chiichann commited on
Commit
3bbe6c1
·
1 Parent(s): 4fb6ea2

first sync with the remote repo

Browse files
Files changed (3) hide show
  1. app.py +80 -0
  2. requirements.txt +5 -0
  3. student_performance_data.csv +101 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ from sklearn.linear_model import LinearRegression
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.metrics import mean_squared_error, r2_score
6
+ import streamlit as st
7
+ import altair as alt
8
+
9
+ # Streamlit app title
10
+ st.title("📊 Student Performance Predictor")
11
+
12
+ # Load dataset
13
+ try:
14
+ df = pd.read_csv("student_performance_data.csv") # Ensure the file is in the same directory
15
+ st.write("### Preview of Dataset")
16
+ st.write(df.head()) # Show first few rows
17
+ except FileNotFoundError:
18
+ st.error("File 'student_performance_data.csv' not found! Please upload the dataset.")
19
+
20
+ # Ensure dataset contains the required columns
21
+ required_columns = ['Study Hours', 'Attendance Rate', 'Assignment Grades', 'Final Exam Score']
22
+ if not all(col in df.columns for col in required_columns):
23
+ st.error("Dataset must contain the following columns: " + ", ".join(required_columns))
24
+ else:
25
+ # Prepare data for training
26
+ X = df[['Study Hours', 'Attendance Rate', 'Assignment Grades']]
27
+ y = df['Final Exam Score']
28
+
29
+ # Split data into training and testing sets
30
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
31
+
32
+ # Train a Linear Regression model
33
+ model = LinearRegression()
34
+ model.fit(X_train, y_train)
35
+
36
+ # Make predictions
37
+ y_pred = model.predict(X_test)
38
+
39
+ # Evaluate the model
40
+ mse = mean_squared_error(y_test, y_pred)
41
+ r2 = r2_score(y_test, y_pred)
42
+
43
+ # Create tabs
44
+ tab1, tab2, tab3 = st.tabs(["📈 Data Visualization", "📊 Model Performance", "🎯 Prediction"])
45
+
46
+ # Tab 1: Data Visualization
47
+ with tab1:
48
+ st.write("### Data Visualization")
49
+
50
+ # Scatter plots
51
+ for col in ['Study Hours', 'Attendance Rate', 'Assignment Grades']:
52
+ st.write(f"**{col} vs Final Exam Score**")
53
+ chart = alt.Chart(df).mark_circle().encode(
54
+ x=col,
55
+ y='Final Exam Score',
56
+ tooltip=[col, 'Final Exam Score']
57
+ ).interactive()
58
+ st.altair_chart(chart, use_container_width=True)
59
+
60
+ # Tab 2: Model Performance
61
+ with tab2:
62
+ st.write("### Model Performance")
63
+ st.write(f"✅ Mean Squared Error (MSE): {mse:.2f}")
64
+ st.write(f"✅ R-squared Score: {r2:.2f}")
65
+
66
+ # Tab 3: Prediction
67
+ with tab3:
68
+ st.write("### Predict Final Exam Score")
69
+ study_hours = st.number_input("📚 Study Hours", min_value=0, value=10, step=1)
70
+ attendance_rate = st.slider("🎟️ Attendance Rate", min_value=0.0, max_value=1.0, step=0.01, value=0.85)
71
+ assignment_grades = st.number_input("📝 Average Assignment Grade", min_value=0, max_value=100, value=80, step=1)
72
+
73
+ if st.button("🔮 Predict"):
74
+ # Prepare input for prediction
75
+ input_data = np.array([[study_hours, attendance_rate, assignment_grades]])
76
+
77
+ # Make prediction
78
+ predicted_score = model.predict(input_data)[0]
79
+
80
+ st.success(f"🎯 Predicted Final Exam Score: {predicted_score:.2f}")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ scikit-learn
4
+ streamlit
5
+ altair
student_performance_data.csv ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Study Hours,Attendance Rate,Assignment Grades,Final Exam Score
2
+ 39,0.86,75,70
3
+ 29,0.82,97,75
4
+ 15,0.94,98,78
5
+ 8,0.74,51,50
6
+ 21,0.56,50,50
7
+ 39,0.86,97,92
8
+ 19,0.88,61,61
9
+ 23,0.78,54,52
10
+ 11,0.89,86,71
11
+ 11,0.75,81,60
12
+ 24,0.76,58,62
13
+ 36,0.71,90,80
14
+ 24,0.51,84,56
15
+ 3,0.55,68,52
16
+ 22,0.52,97,69
17
+ 2,0.82,65,50
18
+ 24,0.66,52,54
19
+ 30,0.75,69,66
20
+ 38,0.95,73,76
21
+ 2,0.62,82,56
22
+ 21,0.71,73,68
23
+ 33,0.88,60,66
24
+ 12,0.61,98,70
25
+ 22,0.54,57,54
26
+ 25,0.64,85,66
27
+ 27,0.58,87,66
28
+ 28,0.96,89,72
29
+ 16,0.9,69,55
30
+ 15,0.82,84,66
31
+ 3,0.94,97,64
32
+ 37,0.9,74,74
33
+ 7,0.59,84,52
34
+ 21,0.95,74,59
35
+ 9,0.77,78,60
36
+ 39,0.9,67,71
37
+ 18,0.95,95,75
38
+ 4,0.66,67,50
39
+ 25,0.56,51,50
40
+ 14,0.61,84,66
41
+ 9,0.71,65,52
42
+ 26,0.91,90,79
43
+ 2,0.93,85,56
44
+ 20,0.5,82,69
45
+ 28,0.76,53,67
46
+ 7,0.71,82,64
47
+ 8,0.61,63,51
48
+ 35,0.56,70,62
49
+ 14,0.67,97,68
50
+ 17,0.97,69,70
51
+ 36,0.66,57,57
52
+ 4,0.76,56,50
53
+ 2,0.85,52,50
54
+ 6,0.68,66,50
55
+ 4,0.99,82,72
56
+ 29,0.98,97,81
57
+ 18,0.63,61,50
58
+ 26,0.75,71,65
59
+ 34,0.65,71,56
60
+ 10,0.64,95,66
61
+ 36,0.52,79,71
62
+ 14,0.8,87,67
63
+ 31,0.75,87,81
64
+ 15,0.53,94,54
65
+ 8,0.64,57,55
66
+ 14,0.95,76,62
67
+ 23,0.62,76,54
68
+ 21,0.57,83,59
69
+ 16,0.74,70,67
70
+ 18,0.99,79,70
71
+ 24,0.62,82,58
72
+ 26,0.84,77,62
73
+ 25,0.88,96,76
74
+ 29,0.62,82,55
75
+ 15,0.86,54,50
76
+ 1,0.68,97,67
77
+ 25,0.82,68,70
78
+ 7,0.82,53,50
79
+ 9,0.77,84,58
80
+ 24,0.55,98,67
81
+ 1,0.92,66,66
82
+ 8,0.66,93,63
83
+ 24,0.59,77,65
84
+ 11,0.52,79,51
85
+ 17,0.8,78,64
86
+ 8,0.84,95,70
87
+ 35,0.51,55,55
88
+ 35,0.76,84,64
89
+ 33,0.61,90,77
90
+ 5,0.82,86,58
91
+ 39,0.59,73,76
92
+ 28,0.85,78,74
93
+ 7,0.69,98,63
94
+ 9,0.97,95,73
95
+ 8,0.57,80,52
96
+ 12,0.67,84,57
97
+ 34,0.56,82,67
98
+ 33,0.96,70,77
99
+ 23,0.94,81,69
100
+ 24,0.63,72,56
101
+ 37,0.83,82,74