-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript 3.py
More file actions
85 lines (72 loc) · 2.54 KB
/
Copy pathscript 3.py
File metadata and controls
85 lines (72 loc) · 2.54 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
# Save the training data to CSV for the web app
training_data_csv = df.to_csv(index=False)
# Create a sample prediction function
def predict_dropout_risk(student_data):
"""
Predict dropout risk for a student
Returns: risk_level, probability, key_factors
"""
# This would use the trained model in the actual web app
# For now, we'll create a simplified version
risk_score = 0
key_factors = []
# Attendance factor
if student_data.get('attendance_rate', 100) < 70:
risk_score += 3
key_factors.append("Poor attendance (< 70%)")
elif student_data.get('attendance_rate', 100) < 85:
risk_score += 1
key_factors.append("Below average attendance")
# Academic performance
avg_grade = (
student_data.get('math_grade', 75) +
student_data.get('english_grade', 75) +
student_data.get('science_grade', 75)
) / 3
if avg_grade < 60:
risk_score += 3
key_factors.append("Poor academic performance (< 60%)")
elif avg_grade < 70:
risk_score += 2
key_factors.append("Below average grades")
# Behavioral factors
if student_data.get('disciplinary_actions', 0) > 3:
risk_score += 2
key_factors.append("Multiple disciplinary issues")
# Family support
if student_data.get('family_support', 5) < 4:
risk_score += 2
key_factors.append("Limited family support")
# Homework completion
if student_data.get('homework_completion', 80) < 60:
risk_score += 2
key_factors.append("Poor homework completion")
# Determine risk level
if risk_score >= 6:
risk_level = "High Risk"
probability = 0.8 + (risk_score - 6) * 0.02
elif risk_score >= 3:
risk_level = "Medium Risk"
probability = 0.4 + (risk_score - 3) * 0.1
else:
risk_level = "Low Risk"
probability = 0.05 + risk_score * 0.05
return risk_level, min(probability, 0.95), key_factors
# Test the function
test_student = {
'attendance_rate': 65,
'math_grade': 55,
'english_grade': 58,
'science_grade': 52,
'disciplinary_actions': 4,
'family_support': 3,
'homework_completion': 45
}
risk, prob, factors = predict_dropout_risk(test_student)
print(f"Test Student Prediction:")
print(f"Risk Level: {risk}")
print(f"Probability: {prob:.2f}")
print(f"Key Factors: {factors}")
print(f"\nDataset ready for web application!")
print(f"Total students in training data: {len(df)}")
print(f"Features used: {len(feature_names)}")