ML Project – Predict Annual Tuition Fee using Multiple Linear Regression Model GUI Based

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

College Dataset

# To build a machine learning model that can predict the annual tuition fee of a
# private college based on:
# Its ranking , The student satisfaction score , The placement rate

import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
import tkinter as tk
from tkinter import messagebox
import seaborn as sns
import matplotlib.pyplot as plt
# Load and train the model
df = pd.read_excel("D://MLFile/college_data.xlsx")
def train_model():

    X = df[['Ranking', 'Student_Satisfaction', 'Placement_Rate (%)']] # Independent variable
    y = df['Tuition_Fee ($)'] # depended variable
    model = LinearRegression()
    model.fit(X, y)  # Train
    return model

model = train_model()

# GUI Function to predict tuition fee

def predict_fee():
    try:
        rank = float(entry_rank.get())
        satisfaction = float(entry_satisfaction.get())
        placement = float(entry_placement.get())

        input_data = np.array([[rank, satisfaction, placement]])
        predicted = model.predict(input_data)[0]

        result_label.config(text=f"Predicted Tuition Fee: ${predicted:,.2f}")

        # Plot: Compare predicted fee with average
        avg_fee = df['Tuition_Fee ($)'].mean()
        data = {
            'Type': ['Predicted College', 'Average Fee'],
            'Tuition Fee ($)': [predicted, avg_fee]
        }
        plot_df = pd.DataFrame(data)
       # print(plot_df)
        sns.barplot(x='Type', y='Tuition Fee ($)', data=plot_df, palette="Blues_d")
        plt.title("Predicted vs Average Tuition Fee")
        plt.ylabel("Fee in $")
        plt.tight_layout()
        plt.show()

    except ValueError:
        messagebox.showerror("Invalid Input", "Please enter numeric values.")



# def predict_fee():
#     try:
#         rank = float(entry_rank.get())
#         satisfaction = float(entry_satisfaction.get())
#         placement = float(entry_placement.get())
#
#         # Predict using the model
#         input_data = np.array([[rank, satisfaction, placement]])
#         fee = model.predict(input_data)  # Predication
#
#         result_label.config(text=f"Predicted Tuition Fee: ${fee[0]:,.2f}")
#     except ValueError:
#         messagebox.showerror("Invalid Input", "Please enter numeric values.")

# Create GUI window
root = tk.Tk()
root.title("Tuition Fee Predictor for Colleges")
root.geometry("500x400")
root.resizable(False, False)

# Title label
tk.Label(root, text="Tuition Fee Predictor", font=("Helvetica", 25, "bold")).pack(pady=10)
# Ranking
tk.Label(root, text="College Ranking (1 = Best):",font=("Arial", 12, "bold")).pack()
entry_rank = tk.Entry(root,font=("Arial", 12,"bold"))  # TextBox
entry_rank.pack()
# Student Satisfaction
tk.Label(root, text="Student Satisfaction Score (0 - 10):",font=("Arial", 12, "bold")).pack()
entry_satisfaction = tk.Entry(root,font=("Arial", 12,"bold")) # TextBox
entry_satisfaction.pack()
# Placement Rate
tk.Label(root, text="Placement Rate (%):",font=("Arial", 12, "bold")).pack()
entry_placement = tk.Entry(root,font=("Arial", 12,"bold"))  # TextBox
entry_placement.pack()

# Predict Button
tk.Button(root, text="Predict Tuition Fee", command=predict_fee, bg="blue", fg="white").pack(pady=10)

# Result Label
result_label = tk.Label(root, text="", font=("Arial", 12, "bold"), fg="green")
result_label.pack(pady=10)

# Run the GUI loop
root.mainloop()

 

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *