-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForecast Accuracy Analyzer.py
More file actions
100 lines (86 loc) · 2.47 KB
/
Copy pathForecast Accuracy Analyzer.py
File metadata and controls
100 lines (86 loc) · 2.47 KB
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
92
93
94
95
96
97
98
99
100
import tkinter as tk
from tkinter import messagebox
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from sklearn.metrics import mean_absolute_error, mean_squared_error
# -------------------------
# Sample Actual & Forecast Data
# -------------------------
actual = np.array([100, 120, 130, 150, 170, 160, 180])
forecast = np.array([110, 115, 140, 145, 165, 170, 175])
# -------------------------
# Accuracy Calculation
# -------------------------
def analyze_accuracy():
try:
mae = mean_absolute_error(actual, forecast)
rmse = np.sqrt(mean_squared_error(actual, forecast))
mape = np.mean(np.abs((actual - forecast) / actual)) * 100
result_label.config(
text=f"MAE: {mae:.2f} RMSE: {rmse:.2f} MAPE: {mape:.2f}%"
)
plot_results()
except Exception as e:
messagebox.showerror("Error", str(e))
# -------------------------
# Plot Function
# -------------------------
def plot_results():
fig.clear()
ax = fig.add_subplot(111)
ax.plot(actual, marker="o", label="Actual")
ax.plot(forecast, marker="x", label="Forecast")
ax.set_title("Actual vs Forecast Comparison")
ax.set_xlabel("Time")
ax.set_ylabel("Value")
ax.legend()
canvas.draw()
# -------------------------
# GUI Setup
# -------------------------
root = tk.Tk()
root.title("Forecast Accuracy Analyzer")
root.geometry("850x600")
root.resizable(False, False)
title = tk.Label(
root,
text="Forecast Accuracy Analyzer",
font=("Arial", 16, "bold")
)
title.pack(pady=10)
desc = tk.Label(
root,
text="Analyze prediction accuracy using MAE, RMSE, and MAPE",
font=("Arial", 11),
fg="gray"
)
desc.pack()
btn = tk.Button(
root,
text="Analyze Forecast Accuracy",
font=("Arial", 12),
bg="#2ecc71",
fg="white",
command=analyze_accuracy
)
btn.pack(pady=15)
result_label = tk.Label(
root,
text="MAE: -- RMSE: -- MAPE: --",
font=("Arial", 12, "bold"),
fg="blue"
)
result_label.pack(pady=10)
fig = plt.Figure(figsize=(8, 4), dpi=100)
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.get_tk_widget().pack(pady=15)
footer = tk.Label(
root,
text="Model Evaluation | Forecast Accuracy | Python Desktop App",
font=("Arial", 9),
fg="gray"
)
footer.pack(side="bottom", pady=5)
root.mainloop()