This project is a Machine Learning pipeline that cleans student performance data and trains a model to predict a student's grade based on factors such as:
- Weekly self-study hours
- Attendance percentage
- Class participation
- Total score
The system performs the following steps:
- Data Cleaning
- Data Preprocessing
- Model Training
- Model Evaluation
- Model Saving
The final trained model is saved and can later be used in applications such as dashboards, APIs, or web applications.
project-folder
│
├── data/
│ └── student_performance.csv
│
├── clean_data/
│ └── clean.csv
│
├── clean_data/cleaned_data/
│ └── cleaned.csv
│
├── logistic_model.pkl
│
├── clean_data_script.py
├── train_model.py
└── README.md
✔ Cleans raw student performance datasets
✔ Handles missing values safely
✔ Removes duplicate records
✔ Converts numeric columns to proper numeric format
✔ Encodes categorical variables
✔ Trains a Logistic Regression Machine Learning model
✔ Evaluates model accuracy and classification metrics
✔ Saves the trained model for later use
- Python
- Pandas – Data manipulation
- Scikit-learn – Machine Learning
- Joblib – Model saving
- OS module – File handling
The first script cleans the raw dataset before training the machine learning model.
- Reads the raw CSV dataset.
- Ensures the output directory exists.
- Selects important columns:
Student_idWeekly_self_study_hoursattendance_percentageclass_participationtotal_scoregrade
- Removes rows with missing values.
- Removes duplicate records.
- Converts numeric columns into proper numeric data types.
- Saves the cleaned dataset.
clean_data/clean.csv
After cleaning, the training script:
- Loads multiple cleaned CSV files.
- Combines them into one dataset.
- Normalizes column names (lowercase and trimmed).
- Handles missing values:
- Numeric columns → filled with median
- Categorical columns → filled with mode
Machine learning models cannot understand text values.
So categorical columns are converted into numbers using:
LabelEncoder
Example:
| Grade | Encoded |
|---|---|
| A | 0 |
| B | 1 |
| C | 2 |
The model uses the following features:
- Weekly study hours
- Attendance percentage
- Class participation
- Total score
The target variable is:
grade
Student ID is removed because it is not useful for prediction.
The dataset is split into:
- 80% Training Data
- 20% Testing Data
train_test_split(test_size=0.2)
This ensures the model is tested on unseen data.
The project uses a Logistic Regression model.
Logistic Regression is commonly used for classification problems where the output is a category such as grades.
model = LogisticRegression(max_iter=1000)
model.fit(x_train, y_train)
After training, the model is evaluated using:
Shows how often the model predicts correctly.
Includes:
- Precision
- Recall
- F1-score
Example output:
Model Accuracy: 0.87
The trained model is saved using Joblib.
joblib.dump(model, "logistic_model.pkl")
Saved file:
logistic_model.pkl
This model can later be used for:
- Web APIs
- Dashboards
- Student analytics tools
- Prediction systems
pip install pandas scikit-learn joblibpython clean_data_script.pypython train_model.pySchools or educational platforms can use this system to:
- Predict student grades
- Identify struggling students early
- Improve academic performance monitoring
Possible upgrades:
- Add Random Forest or XGBoost models
- Build a Flask API
- Create a student performance dashboard
- Add data visualization
- Deploy as a web application
Maurice Kabubu
Aspiring Software Developer & Data Scientist interested in:
- Machine Learning
- Data Science
- Backend Development
- Building impactful software systems.