본문 바로가기

데이터 분석

Forecastiong GUI with Tkinter

반응형
 

This program is a tkinter-based application that allows the user to input two values and performs forecasting based on an ARIMA model.

 

It uses the statsmodels library to create and train an ARIMA model using example data.

The program predicts the next value based on the provided data points and displays the result in a GUI window.

The user can input their own values, and the program will update the forecast accordingly.

 

import tkinter as tk
from statsmodels.tsa.arima.model import ARIMA
import numpy as np

def forecast():
    try:
        value1 = float(entry1.get())
        value2 = float(entry2.get())

        # Example data
        data = np.array([1, 2, 3, 4, 5])  # Use only 5 data points as an example
        model = ARIMA(data, order=(1, 1, 1))  # Create an ARIMA model

        # Model training
        model_fit = model.fit()

        # Predict the next value based on the last data point
        next_value = model_fit.forecast(steps=1)[0]

        result_label.config(text="Forecasting Result: {}".format(next_value))

    except ValueError:
        result_label.config(text="Please enter numeric values only.")


# Create a tkinter window
window = tk.Tk()
window.title("Forecasting Program")

# Create input fields and button
label1 = tk.Label(window, text="Value 1:")
label1.pack()
entry1 = tk.Entry(window)
entry1.pack()

label2 = tk.Label(window, text="Value 2:")
label2.pack()
entry2 = tk.Entry(window)
entry2.pack()

forecast_button = tk.Button(window, text="Forecasting", command=forecast)
forecast_button.pack()

# Create a label to display the prediction result
result_label = tk.Label(window, text="Forecasting Result:")
result_label.pack()

window.mainloop()
반응형