|
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, r2_score |
|
import streamlit as st |
|
import altair as alt |
|
|
|
|
|
st.title("๐ Student Performance Predictor") |
|
|
|
|
|
try: |
|
df = pd.read_csv("student_performance_data.csv") |
|
st.write("### Preview of Dataset") |
|
st.write(df.head()) |
|
except FileNotFoundError: |
|
st.error("File 'student_performance_data.csv' not found! Please upload the dataset.") |
|
|
|
|
|
required_columns = ['Study Hours', 'Attendance Rate', 'Assignment Grades', 'Final Exam Score'] |
|
if not all(col in df.columns for col in required_columns): |
|
st.error("Dataset must contain the following columns: " + ", ".join(required_columns)) |
|
else: |
|
|
|
X = df[['Study Hours', 'Attendance Rate', 'Assignment Grades']] |
|
y = df['Final Exam Score'] |
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
|
|
|
|
|
model = LinearRegression() |
|
model.fit(X_train, y_train) |
|
|
|
|
|
y_pred = model.predict(X_test) |
|
|
|
|
|
mse = mean_squared_error(y_test, y_pred) |
|
r2 = r2_score(y_test, y_pred) |
|
|
|
|
|
tab1, tab2, tab3 = st.tabs(["๐ Data Visualization", "๐ Model Performance", "๐ฏ Prediction"]) |
|
|
|
|
|
with tab1: |
|
st.write("### Data Visualization") |
|
|
|
|
|
for col in ['Study Hours', 'Attendance Rate', 'Assignment Grades']: |
|
st.write(f"**{col} vs Final Exam Score**") |
|
chart = alt.Chart(df).mark_circle().encode( |
|
x=col, |
|
y='Final Exam Score', |
|
tooltip=[col, 'Final Exam Score'] |
|
).interactive() |
|
st.altair_chart(chart, use_container_width=True) |
|
|
|
|
|
with tab2: |
|
st.write("### Model Performance") |
|
st.write(f"โ
Mean Squared Error (MSE): {mse:.2f}") |
|
st.write(f"โ
R-squared Score: {r2:.2f}") |
|
|
|
|
|
with tab3: |
|
st.write("### Predict Final Exam Score") |
|
study_hours = st.number_input("๐ Study Hours", min_value=0, value=10, step=1) |
|
attendance_rate = st.slider("๐๏ธ Attendance Rate", min_value=0.0, max_value=1.0, step=0.01, value=0.85) |
|
assignment_grades = st.number_input("๐ Average Assignment Grade", min_value=0, max_value=100, value=80, step=1) |
|
|
|
if st.button("๐ฎ Predict"): |
|
|
|
input_data = np.array([[study_hours, attendance_rate, assignment_grades]]) |
|
|
|
|
|
predicted_score = model.predict(input_data)[0] |
|
|
|
st.success(f"๐ฏ Predicted Final Exam Score: {predicted_score:.2f}") |
|
|