Repository navigation
Expand file tree
/
Copy pathmodel.py
More file actions
68 lines (51 loc) · 1.55 KB
/
Copy pathmodel.py
File metadata and controls
68 lines (51 loc) · 1.55 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
# ============================================
# Student Performance Prediction Model
# ============================================
import pandas as pd
import joblib
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
# ============================================
# Load Dataset
# ============================================
df = pd.read_csv("Student_Performance.csv")
# ============================================
# Data Preprocessing
# ============================================
df["Extracurricular Activities"] = df["Extracurricular Activities"].map({
"Yes": 1,
"No": 0
})
# ============================================
# Features and Target
# ============================================
X = df[
[
"Hours Studied",
"Previous Scores",
"Extracurricular Activities",
"Sleep Hours",
"Sample Question Papers Practiced"
]
]
y = df["Performance Index"]
# ============================================
# Split Dataset
# ============================================
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
test_size=0.2,
random_state=42
)
# ============================================
# Train Model
# ============================================
model = LinearRegression()
model.fit(X_train, y_train)
# ============================================
# Save Model
# ============================================
joblib.dump(model, "model.pkl")
print("✅ Model trained successfully!")
print("✅ model.pkl created successfully!")