A simple AI/ML-based real-world application that predicts a student's final academic performance in Mathematics and Portuguese using demographic, family, social, study, and academic-related information.
Selected Application: Student Performance Prediction
This project follows the required PR12 stages:
- Problem Definition
- Dataset Collection
- Data Preprocessing
- Exploratory Data Analysis
- Model Development
- Performance Evaluation
- Model Optimization
- Result Analysis and Documentation
To develop a machine learning system that predicts a student's final Mathematics and Portuguese grades and displays the results through a simple Flask web application.
- Collect and use student performance data.
- Combine Mathematics and Portuguese student datasets.
- Perform basic data preprocessing.
- Perform simple Exploratory Data Analysis (EDA).
- Train a machine learning regression model.
- Predict Mathematics and Portuguese final grades.
- Evaluate the model using MAE, MSE, RMSE, and R².
- Use 10-fold cross-validation to check model performance.
- Save the trained model for use in the Flask application.
- Display predicted grades and performance categories.
- Provide a basic academic recommendation.
The project uses the Student Performance dataset.
The dataset contains information about students including:
- Demographic information
- Family information
- School information
- Study habits
- Social activities
- Previous failures
- Absences
- Previous grades
- Other student-related attributes
The project uses Mathematics and Portuguese subject data.
data/
├── student-mat.csv
├── student-por.csv
└── student-merge.csv
The two subject datasets are combined into:
student-merge.csv
The model predicts two final grades:
G3_x → Mathematics Final Grade
G3_y → Portuguese Final Grade
Therefore, the project uses a multi-output regression approach.
A simple Exploratory Data Analysis (EDA) was performed before model training.
The EDA includes:
- Dataset shape
- Dataset columns
- First five rows
- Dataset information
- Missing value checking
- Duplicate row checking
- Statistical summary
- Final grade analysis
- Grade distribution
- Study time vs final grade
- Previous failures vs final grade
- Absences vs final grade
- Correlation analysis
EDA was performed for both Mathematics and Portuguese.
The following features were analyzed:
G3_x
studytime_x
failures_x
absences_x
Graphs include:
- Mathematics final grade distribution
- Study time vs Mathematics final grade
- Previous failures vs Mathematics final grade
- Absences vs Mathematics final grade
The following features were analyzed:
G3_y
studytime_y
failures_y
absences_y
Graphs include:
- Portuguese final grade distribution
- Study time vs Portuguese final grade
- Previous failures vs Portuguese final grade
- Absences vs Portuguese final grade
A correlation heatmap is also generated using the numerical features.
The correlation of the features with:
G3_x
and
G3_y
is displayed to understand the relationship between numerical features and final grades.
The project uses a:
Random Forest Regressor
Random Forest is a machine learning algorithm that combines multiple decision trees to make predictions.
The preprocessing and model are combined using a Scikit-learn Pipeline.
The model performs multi-output regression, allowing it to predict:
Mathematics Final Grade
+
Portuguese Final Grade
The dataset contains both numerical and categorical features.
Missing numerical values are handled using:
Median Imputation
The median value is used because it is less affected by extreme values.
Missing categorical values are handled using:
Most Frequent Imputation
Categorical values are converted into numerical features using:
OneHotEncoder
The encoder uses:
handle_unknown="ignore"This allows the model to handle unknown categorical values during prediction.
The Random Forest Regressor is configured as follows:
RandomForestRegressor(
n_estimators=200,
max_depth=15,
min_samples_split=5,
min_samples_leaf=2,
random_state=42
)| Parameter | Value |
|---|---|
| Number of Trees | 200 |
| Maximum Depth | 15 |
| Minimum Samples Split | 5 |
| Minimum Samples Leaf | 2 |
| Random State | 42 |
The dataset is divided into training and testing data.
80% → Training Data
20% → Testing Data
The training process includes:
Dataset
↓
Data Preprocessing
↓
Train-Test Split
↓
10-Fold Cross-Validation
↓
Random Forest Training
↓
Model Evaluation
↓
Save Model
The project uses 10-fold cross-validation.
The training data is divided into 10 parts.
The model is trained and evaluated multiple times using different parts of the training dataset.
The R² score is used for cross-validation.
This provides a better understanding of how the model performs on different subsets of the data.
The model is evaluated using four metrics.
MAE measures the average absolute difference between the actual and predicted grades.
A lower MAE indicates better prediction performance.
MSE measures the average squared difference between actual and predicted grades.
A lower MSE indicates better performance.
RMSE is the square root of MSE.
It represents the prediction error in the same scale as the student's grade.
R² measures how well the model explains the variation in the target values.
A value closer to 1 indicates better performance.
The Random Forest Regressor produced the following results on the test dataset:
| Metric | Result |
|---|---|
| Mean Absolute Error (MAE) | 0.984 |
| Mean Squared Error (MSE) | 3.060 |
| Root Mean Squared Error (RMSE) | 1.749 |
| R² Score | 0.768 |
Model Performance
-----------------
MAE: 0.984
MSE: 3.060
RMSE: 1.749
R²: 0.768
The R² score of 0.768 indicates that the model explains approximately 76.8% of the variation in the test data.
The RMSE of 1.749 means that the prediction error is approximately 1.75 grade points on the 0–20 grading scale.
Student Details
↓
HTML Form
↓
Flask Application
↓
Request Data
↓
Pandas DataFrame
↓
Saved ML Pipeline
↓
Data Preprocessing
↓
Random Forest Regressor
↓
Predicted Grades
↓
Performance Categories
↓
Academic Recommendation
The project includes a simple Flask web application.
The user enters student information through an HTML form.
The form sends the information to the Flask server.
The trained machine learning model processes the input and predicts the student's final grades.
The results are then displayed on the webpage.
- Mathematics predicted grade
- Portuguese predicted grade
- Mathematics performance category
- Portuguese performance category
- Basic academic recommendation
The predicted grades are classified into four categories.
| Predicted Grade | Category |
|---|---|
< 10 |
At Risk of Failing |
10 - < 12 |
Pass - Needs Improvement |
12 - 16 |
Good Performance |
> 16 |
Excellent Performance |
student_performance_predict_model/
│
├── data/
│ ├── student-mat.csv
│ ├── student-por.csv
│ ├── student-merge.csv
│ ├── student-merge.R
│ ├── student.txt
│ └── student.zip
│
├── models/
│ └── student_performance_model.pkl
│
├── src/
│ ├── train_model.py
│ └── eda.ipynb
│
├── static/
│ └── style.css
│
├── templates/
│ └── index.html
│
├── server.py
│
├── requirementes.txt
│
└── README.md
- Python
- Pandas
- NumPy
- Scikit-learn
- Joblib
- Flask
- HTML
- CSS
- Matplotlib
- Seaborn
The required Python packages are listed in:
requirementes.txt
git clone https://github.com/ZarhanMemon/student_performance_predict_model.gitMove into the project directory:
cd student_performance_predict_modelInstall the required Python packages:
pip install -r requirementes.txtRun the EDA script:
src/eda.ipynbThe script displays:
- Dataset information
- Missing values
- Duplicate values
- Statistical summary
- Mathematics graphs
- Portuguese graphs
- Correlation heatmap
Run:
python src/train_model.pyThe training script:
- Loads the dataset
- Performs preprocessing
- Splits the dataset
- Performs 10-fold cross-validation
- Trains the Random Forest model
- Evaluates the model
- Saves the trained model
The trained model is saved as:
models/student_performance_model.pkl
Start the Flask server:
python server.pyOpen the local Flask address shown in the terminal in your browser.
| PR12 Requirement | Project Implementation |
|---|---|
| Problem Definition | Student final grade prediction |
| Dataset Collection | Mathematics and Portuguese student datasets |
| Data Preprocessing | Imputation and one-hot encoding |
| Exploratory Data Analysis | Basic statistical and graphical analysis |
| Model Development | Random Forest Regressor |
| Performance Evaluation | MAE, MSE, RMSE and R² |
| Model Optimization | Random Forest parameter configuration and 10-fold CV |
| Result Analysis | Predicted grades and performance categories |
| Documentation | README and practical project report |
The Student Performance Prediction system was successfully developed using Python, Machine Learning, and Flask.
The Random Forest Regressor achieved the following results on the test dataset:
| Metric | Result |
|---|---|
| MAE | 0.984 |
| MSE | 3.060 |
| RMSE | 1.749 |
| R² | 0.768 |
The system can predict both:
Mathematics Final Grade
Portuguese Final Grade
The Flask application provides a simple interface for entering student information and viewing the predicted results.
- The model depends on the quality and size of the available dataset.
- The dataset may not represent every student or educational environment.
- Predictions should not be treated as a final judgement of a student's ability.
- The recommendation system is intentionally simple.
- Model performance can vary with different datasets and train-test splits.
- The application is developed mainly for academic and demonstration purposes.
The project can be improved by:
- Adding more recent student datasets.
- Comparing different machine learning algorithms.
- Adding feature importance visualization.
- Adding graphical student performance analysis.
- Improving the recommendation system.
- Adding more student-related features.
- Improving the web interface.
- Deploying the application online.
Zarhan Memon
GitHub:
https://github.com/ZarhanMemon/student_performance_predict_model
This project is developed for academic practical work under: