#OVERALL PREDICTION OF BUDGET
from tkinter import *
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import csv
from tkinter import filedialog
root=Tk()
root.geometry('1370x700+0+0')
root.title('NMRL FBE')
header=Frame(root,width=1370,bd=4)
header.pack(side=TOP,fill=X)
def submit_path():
#path=e1.get()
path = file_path
year=int(e2.get())
# Load data from CSV
df = pd.read_csv(path)
# Extract years and department names
years = df['Year']
departments = df.columns[1:] # Exclude the 'Year' column
# Convert to numpy array for modeling
X = np.array(years).reshape(-1, 1) # Years as input feature
# Create a dictionary to store department-wise forecasted amounts
dept_forecast = {}
# Loop through departments to train individual models (if needed) and store predictions
for dept in departments:
y = df[dept] # Forecasted amounts for current department
# Train a linear regression model
model = LinearRegression()
model.fit(X, y)
# Store the model for this department
dept_forecast[dept] = model
# Function to predict total forecasted amount for any given year
def predict_total_forecast(year):
total_forecast = 0
for dept, model in dept_forecast.items():
# Predict forecasted amount for the given year using the model for each department
forecast_amount = model.predict(np.array(year).reshape(-1, 1))[0]
total_forecast += forecast_amount
return total_forecast
# Example: Predict total forecast for year 2025
#a=int(input("Enter your required year:"))
year_to_predict = year
total_forecast_2025 = predict_total_forecast(year_to_predict)
result_text=f'Total forecasted amount for the organization in {year_to_predict}: {total_forecast_2025}'
output=Frame(root,width=1370,bd=6,bg='black')
output.pack(side=TOP)
Label(output,text=result_text,font=('Times New Roman',14,'bold'),fg='aqua',bg='black',bd=6,pady=10).pack(side=TOP)
Button(output,text='Clear Result',width=15,bd=3,command=output.destroy).pack(side=TOP)
#root.destroy()
#def submit_year():
#year=e2.get()
#return year
#div=e3.get()
def read_csv_file(file_path):
with open(file_path, 'r') as file:
reader = csv.reader(file)
content = [row for row in reader]
return content
def browse_files():
global file_path
file_path = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")])
if file_path:
content = read_csv_file(file_path)
print(file_path)
#for row in content:
# print(row)
Label(header,text='NMRL FBE',font=('Times New Roman',36,'bold'),fg='black',bg='orange',bd=6,relief='ridge').pack(side=TOP,fill=X)
body=Frame(root,width=1370,bd=6,bg='yellowgreen',relief='ridge')
body.pack(side=TOP,fill=X)
Label(body,text='Select dataset to predict:',font=('Times New Roman',14,'bold'),bg='yellowgreen',fg='black').pack(side=LEFT)
#e1=Entry(body,width=20, font = ('Times New Roman',14,'normal'),bd=4)
#e1.pack(side=LEFT,padx=20)
browse_button = Button(body, text="Browse Documents", command=browse_files)
browse_button.pack(side= LEFT)
Label(body,text='Enter required year:',font=('Times New Roman',14,'bold'),bg='yellowgreen',fg='black').pack(side=LEFT)
e2=Entry(body, font = ('Times New Roman',14,'normal'),bd=4)
e2.pack(side=LEFT,padx=20)
#Label(body,text='Enter required division:',font=('Times New Roman',14,'bold'),bg='yellowgreen',fg='black').pack(side=LEFT)
#e2=Entry(body, font = ('Times New Roman',14,'normal'),bd=4)
#e2.pack(side=LEFT,padx=20)
btn_frame=Frame(root,width=1370,bd=4)
btn_frame.pack(side=TOP)
sbt_btn=Button(btn_frame,text='Submit',width=15,bd=3,command=submit_path)
sbt_btn.pack(side=LEFT)
#sbt_btn=Button(btn_frame,text='Run Model',width=15,bd=3,command=submit_year)
#sbt_btn.pack(side=LEFT)
mainloop()