Repository navigation
Expand file tree
/
Copy pathgenerate_data.py
More file actions
152 lines (133 loc) · 6.15 KB
/
Copy pathgenerate_data.py
File metadata and controls
152 lines (133 loc) · 6.15 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import pandas as pd
import numpy as np
from faker import Faker
import random
import os
# Use Indian locale for realistic Indian student names
fake = Faker('en_IN')
def generate_synthetic_data(num_students=2000):
departments = [
'Computer Science & Engineering',
'Mechanical Engineering',
'Civil Engineering',
'Electrical & Electronics',
'Business Administration',
'Arts & Humanities'
]
semesters = [1, 2, 3, 4, 5, 6, 7, 8]
genders = ['Male', 'Female', 'Other']
# Typical Indian college roll number pattern
current_year = 26 # 2026
data = []
for i in range(num_students):
# Indian-style roll number: e.g. 24CSE001
dept_code = {
'Computer Science & Engineering': 'CSE',
'Mechanical Engineering': 'MECH',
'Civil Engineering': 'CIVIL',
'Electrical & Electronics': 'EEE',
'Business Administration': 'BBA',
'Arts & Humanities': 'ARTS'
}
dept = random.choice(departments)
code = dept_code[dept]
student_id = f"{current_year}{code}{str(i+1).zfill(4)}"
name = fake.name()
sem = random.choice(semesters)
gender = random.choices(genders, weights=[52, 45, 3], k=1)[0]
age = random.randint(18, 24)
# Base academic profile: 0 to 1
profile = np.random.beta(a=2, b=2)
attendance_percentage = int(np.clip(profile * 100 + np.random.normal(0, 10), 30, 100))
internal_marks = int(np.clip(profile * 100 + np.random.normal(0, 10), 20, 100))
assignment_score = int(np.clip(profile * 100 + np.random.normal(0, 10), 10, 100))
midterm_score = int(np.clip(profile * 100 + np.random.normal(0, 15), 10, 100))
previous_semester_percentage = int(np.clip(profile * 100 + np.random.normal(0, 12), 20, 100))
# Specific Subject Scores (typical Indian engineering / arts subjects)
math_score = int(np.clip(internal_marks + np.random.normal(0, 15), 10, 100))
physics_score = int(np.clip(internal_marks + np.random.normal(0, 15), 10, 100))
programming_score = int(np.clip(internal_marks + np.random.normal(0, 15), 10, 100))
# Subject-wise attendance (5 subjects, Indian style)
sub_attn = [int(np.clip(attendance_percentage + np.random.randint(-15, 15), 30, 100)) for _ in range(5)]
subject_wise_attendance = (
f"Maths:{sub_attn[0]}%,"
f" Physics:{sub_attn[1]}%,"
f" Programming:{sub_attn[2]}%,"
f" EVS:{sub_attn[3]}%,"
f" Communication:{sub_attn[4]}%"
)
# Monday/Friday bunk pattern
monday_friday_absences = 1 if attendance_percentage < 80 and np.random.rand() > 0.6 else 0
extracurricular_score = random.randint(0, 100)
consecutive_absences = max(0, int((100 - attendance_percentage) / 10 + np.random.randint(-2, 4)))
library_visits = int(np.clip(profile * 40 + np.random.randint(-5, 15), 0, 50))
lab_completion_score = int(np.clip(profile * 100 + np.random.normal(0, 10), 20, 100))
counseling_sessions = max(0, int((1 - profile) * 5 + np.random.randint(-1, 3)))
# Burnout flag
burnout = 1 if (
(previous_semester_percentage - internal_marks > 20)
and attendance_percentage < 60
and extracurricular_score < 30
) else 0
# Risk score (weighted)
risk_score_raw = (
(100 - attendance_percentage) * 0.35 +
(100 - previous_semester_percentage) * 0.20 +
(100 - midterm_score) * 0.20 +
consecutive_absences * 2.0 +
(100 - lab_completion_score) * 0.10 +
(100 - assignment_score) * 0.10 +
(5 - library_visits) * 0.5 +
(burnout * 10) +
(monday_friday_absences * 5)
)
risk_score = max(0, min(100, int(risk_score_raw)))
if risk_score < 30:
risk_label = "Low Risk"
elif risk_score < 55:
risk_label = "Moderate Risk"
elif risk_score < 75:
risk_label = "High Risk"
else:
risk_label = "Critical Risk"
data.append({
'student_id': student_id,
'name': name,
'department': dept,
'semester': sem,
'attendance_percentage': attendance_percentage,
'monday_friday_absences': monday_friday_absences,
'subject_wise_attendance': subject_wise_attendance,
'internal_marks': internal_marks,
'math_score': math_score,
'physics_score': physics_score,
'programming_score': programming_score,
'assignment_score': assignment_score,
'midterm_score': midterm_score,
'previous_semester_percentage': previous_semester_percentage,
'extracurricular_score': extracurricular_score,
'consecutive_absences': consecutive_absences,
'library_visits': library_visits,
'lab_completion_score': lab_completion_score,
'counseling_sessions': counseling_sessions,
'burnout': burnout,
'age': age,
'gender': gender,
'risk_score': risk_score,
'risk_label': risk_label
})
df = pd.DataFrame(data)
os.makedirs('data', exist_ok=True)
df.to_csv('data/synthetic_students.csv', index=False)
print(f"Generated {num_students} Indian student records -> data/synthetic_students.csv")
# Historical risk (6 months of data per student)
hist_data = []
for _, row in df.iterrows():
base_risk = row['risk_score']
for month in range(1, 7):
hist_risk = max(0, min(100, base_risk + np.random.randint(-15, 15)))
hist_data.append({'student_id': row['student_id'], 'month': f"Month {month}", 'risk_score': hist_risk})
pd.DataFrame(hist_data).to_csv('data/historical_risk.csv', index=False)
print("Historical risk data saved -> data/historical_risk.csv")
if __name__ == "__main__":
generate_synthetic_data(2000)