Download example.py from alanoee/energy_prediction_model: direct link, hf CLI and curl.
- Browser
- Download file 3.15 kB
-
https://huggingface.co/alanoee/energy_prediction_model/resolve/main/example.py
- Command line
-
hf download hf://alanoee/energy_prediction_model/example.py
-
curl -L -o example.py https://huggingface.co/alanoee/energy_prediction_model/resolve/main/example.py
3.15 kB
| """ | |
| Example usage of Energy Consumption Prediction Model | |
| Download this file along with model.py and energy_model_latest.joblib | |
| """ | |
| import pandas as pd | |
| import numpy as np | |
| from datetime import datetime | |
| import os | |
| def main(): | |
| # Check if model file exists | |
| model_path = 'energy_model_latest.joblib' | |
| if not os.path.exists(model_path): | |
| print(f"Error: {model_path} not found!") | |
| print("Please download energy_model_latest.joblib from this repository") | |
| return | |
| # Import and load model | |
| from model import EnergyConsumptionPredictor | |
| print("Loading energy consumption prediction model...") | |
| model = EnergyConsumptionPredictor.from_file(model_path) | |
| print(f"Model loaded successfully: {model.best_model_name}") | |
| print(f"Features used: {len(model.feature_columns)}") | |
| # Make predictions | |
| months_to_predict = 6 | |
| print(f"\nPredicting energy consumption for next {months_to_predict} months...") | |
| predictions = model.predict_future(months=months_to_predict) | |
| # Display results | |
| print("\n" + "="*60) | |
| print("ENERGY CONSUMPTION PREDICTIONS") | |
| print("="*60) | |
| total_consumption = predictions['Predicted_Consumption'].sum() | |
| total_cost = predictions['Predicted_Cost'].sum() | |
| avg_consumption = total_consumption / months_to_predict | |
| avg_cost = total_cost / months_to_predict | |
| print(f"Total predicted consumption: {total_consumption:.0f} kWh") | |
| print(f"Total predicted cost: {total_cost:.0f} PLN") | |
| print(f"Average monthly consumption: {avg_consumption:.0f} kWh") | |
| print(f"Average monthly cost: {avg_cost:.0f} PLN") | |
| print(f"\nMonthly breakdown:") | |
| print("-" * 55) | |
| print(f"{'Month':<15} {'Consumption':<15} {'Cost (PLN)'}") | |
| print("-" * 55) | |
| for _, row in predictions.iterrows(): | |
| month_name = row['Date'].strftime('%B %Y') | |
| consumption = row['Predicted_Consumption'] | |
| cost = row['Predicted_Cost'] | |
| print(f"{month_name:<15} {consumption:>8.0f} kWh {cost:>12.0f}") | |
| print("-" * 55) | |
| # Show feature importance | |
| importance = model.get_feature_importance() | |
| if importance: | |
| print(f"\nTop 5 most important prediction features:") | |
| for i, (feature, score) in enumerate(list(importance.items())[:5], 1): | |
| print(f" {i}. {feature}: {score:.3f}") | |
| # Save predictions to CSV | |
| output_file = 'energy_predictions.csv' | |
| predictions.to_csv(output_file, index=False) | |
| print(f"\nPredictions saved to: {output_file}") | |
| return predictions | |
| if __name__ == "__main__": | |
| print("Energy Consumption Prediction Model - Example Usage") | |
| print("=" * 55) | |
| print("Required files: model.py, energy_model_latest.joblib") | |
| print("=" * 55) | |
| try: | |
| predictions = main() | |
| print(f"\n✓ Success! Generated {len(predictions)} monthly predictions") | |
| except Exception as e: | |
| print(f"\n✗ Error: {str(e)}") | |
| print("\nMake sure you have:") | |
| print("1. model.py") | |
| print("2. energy_model_latest.joblib") | |
| print("3. Required packages: pandas, numpy, scikit-learn, joblib") | |