File size: 3,145 Bytes
470deb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
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")