File size: 821 Bytes
d40e39e | 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 | import xgboost as xgb
import pandas as pd
import pickle
from sklearn.model_selection import train_test_split
data = {
"study_hours": [1,2,3,4,5,6,7,8,2,3,5,6,7,1,4],
"attendance": [50,55,60,65,70,75,80,85,60,65,75,80,85,45,68],
"assignments_completed": [1,1,2,2,3,3,4,4,2,2,3,3,4,1,2],
"previous_marks": [30,35,40,45,50,55,60,65,42,48,53,58,62,28,47],
"pass": [0,0,0,0,1,1,1,1,0,0,1,1,1,0,0]
}
df = pd.DataFrame(data)
X = df.drop("pass", axis=1)
y = df["pass"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
model = xgb.XGBClassifier(
objective="binary:logistic",
eval_metric="logloss",
use_label_encoder=False
)
model.fit(X_train, y_train)
with open("model.pkl", "wb") as f:
pickle.dump(model, f)
print("Model saved as model.pkl")
|