-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
105 lines (95 loc) · 3.51 KB
/
test_app.py
File metadata and controls
105 lines (95 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
Test script to verify app.py works correctly with 35 features
"""
import pandas as pd
import joblib
import numpy as np
print("=" * 60)
print("TESTING APP.PY FEATURE COMPATIBILITY")
print("=" * 60)
# Load model
try:
model = joblib.load('student_performance_model.pkl')
print("✅ Model loaded successfully")
except Exception as e:
print(f"❌ Failed to load model: {e}")
exit(1)
# Test input - simulate what app.py will send
mappings_map = {
'Low': 0, 'Medium': 1, 'High': 2,
'No': 0, 'Yes': 1,
'Male': 0, 'Female': 1,
'Public': 0, 'Private': 1,
'Negative': 0, 'Neutral': 1, 'Positive': 2,
'High School': 0, 'College': 1, 'Postgraduate': 2,
'Near': 0, 'Moderate': 1, 'Far': 2
}
# Create test input with all 35 features
hours_studied = 20
attendance = 85
grade_level = 2
current_semester = 4
class_participation = 70
previous_scores = 75
sleep_hours = 7
input_data = pd.DataFrame({
'Hours_Studied': [hours_studied],
'Attendance': [attendance],
'Parental_Involvement': [mappings_map['Medium']],
'Access_to_Resources': [mappings_map['High']],
'Extracurricular_Activities': [mappings_map['No']],
'Sleep_Hours': [sleep_hours],
'Previous_Scores': [previous_scores],
'Motivation_Level': [mappings_map['Medium']],
'Internet_Access': [mappings_map['Yes']],
'Tutoring_Sessions': [1],
'Family_Income': [mappings_map['Medium']],
'Teacher_Quality': [mappings_map['Medium']],
'School_Type': [mappings_map['Public']],
'Peer_Influence': [mappings_map['Positive']],
'Physical_Activity': [3],
'Learning_Disabilities': [mappings_map['No']],
'Parental_Education_Level': [mappings_map['College']],
'Distance_from_Home': [mappings_map['Near']],
'Gender': [mappings_map['Male']],
'Grade_Level': [grade_level],
'Current_Semester': [current_semester],
'Age': [18 + grade_level],
'Class_Participation_Score': [class_participation],
'Cumulative_GPA': [2.0 + (previous_scores - 60) * 0.04],
'Study_Motivation_Interaction': [(hours_studied * mappings_map['Medium']) / 3],
'Attendance_Parental_Interaction': [(attendance * mappings_map['Medium']) / 200],
'Resources_Quality_Interaction': [mappings_map['High'] * mappings_map['Medium']],
'Hours_Studied_Squared': [hours_studied ** 2],
'Sleep_Hours_Squared': [(sleep_hours - 7) ** 2],
'Engagement_Score': [(attendance / 100) * 25 + mappings_map['No'] * 25 + class_participation / 4],
'Support_Index': [mappings_map['Medium'] + mappings_map['Yes'] + mappings_map['Medium'] / 2],
'Health_Wellness_Score': [(10 - abs(sleep_hours - 7)) + 3 * 1.5],
'Sleep_Distance_from_Optimal': [abs(sleep_hours - 7)],
'Is_Senior': [0],
'Is_Sophomore': [1]
})
print(f"\n✅ Input DataFrame created with {len(input_data.columns)} features")
print(f" Features: {list(input_data.columns)}")
# Test prediction
try:
prediction = model.predict(input_data)[0]
print(f"\n✅ Prediction successful!")
print(f" Predicted Score: {prediction:.2f}/100")
if prediction >= 90:
print(f" Category: 🌟 Excellent Performance")
elif prediction >= 75:
print(f" Category: ✅ Good Job")
elif prediction >= 60:
print(f" Category: ⚠️ Needs Improvement")
else:
print(f" Category: 🚨 At Risk")
except Exception as e:
print(f"❌ Prediction failed: {e}")
exit(1)
print("\n" + "=" * 60)
print("✅ ALL TESTS PASSED - APP.PY IS READY!")
print("=" * 60)
print("\nRun the app with:")
print(" streamlit run app.py")
print("=" * 60)