A machine learning project that predicts whether a student is likely to pass or fail based on academic and lifestyle factors such as attendance, study hours, previous exam scores, sleep, parental support, and extracurricular activities.
The project includes a complete machine learning pipeline covering data preprocessing, exploratory data analysis (EDA), model training, evaluation, and visualization.
- Load data — uses a realistic synthetic dataset (1,000 students) so
the whole pipeline runs end-to-end with no external file needed. Swap in
a real CSV (e.g. the UCI Student Performance dataset)
by passing
csv_pathtoload_data(). - Preprocess — fills missing values, label-encodes categorical features (parental support, internet access, extracurriculars).
- EDA — saves a feature correlation heatmap and a score distribution plot.
- Train models — Logistic Regression and Random Forest classifiers, compared on accuracy, ROC-AUC, and 5-fold cross-validation.
- Evaluate — confusion matrix and feature importance plots for the winning model.
- Save — best model and scaler are pickled with
joblibfor reuse. - Predict — example inference on a new, unseen student profile.
| Model | Accuracy | ROC-AUC | CV Mean |
|---|---|---|---|
| Logistic Regression | 0.840 | 0.873 | 0.819 |
| Random Forest | 0.830 | 0.850 | 0.818 |
Best model: Logistic Regression. previous_score and study_hours
are the strongest predictors of final_score and passed (see
correlation_heatmap.png and feature_importance.png).
(Since the dataset is randomly generated each run, exact numbers will
vary slightly run to run — set a real CSV via csv_path for reproducible,
meaningful results.)
pip install pandas numpy scikit-learn matplotlib seaborn joblib
python student_prediction.pyRunning the script produces:
correlation_heatmap.png— feature correlationsscore_distribution.png— distribution of final scoresconfusion_matrix.png— confusion matrix for the best modelfeature_importance.png— Random Forest feature importancesbest_model.pkl— trained model, saved with joblibscaler.pkl— fitted StandardScaler, saved with joblib
Replace the synthetic generator with your own CSV:
df_raw = load_data(csv_path="your_dataset.csv")Your CSV should include a final_score (numeric) and/or passed
(0/1) target column, plus whatever feature columns you have — the
pipeline auto-detects numeric vs. categorical columns during
preprocessing.
import joblib
model = joblib.load("best_model.pkl")
scaler = joblib.load("scaler.pkl") # only needed if the best model was Logistic RegressionPython · pandas · NumPy · scikit-learn (Logistic Regression, Random Forest) · matplotlib · seaborn · joblib