An AI/ML project that analyzes software metrics to predict code quality.
This project explores how static code features and software metrics can be used to build a machine learning model that estimates the quality of source code.
Software quality is an important part of software engineering, especially when trying to detect maintainability issues, code smells, and poor design patterns.
This project aims to use machine learning to classify or estimate code quality based on measurable code metrics.
The workflow includes:
- Loading and exploring the dataset.
- Cleaning and preprocessing the data.
- Engineering relevant features.
- Training machine learning models.
- Evaluating performance with standard metrics.
- Saving the final model for reuse.
- Build an AI model for code quality assessment.
- Analyze the relationship between software metrics and code quality.
- Compare different machine learning algorithms.
- Create a reproducible pipeline for experimentation and evaluation.
- Produce a GitHub-ready project that demonstrates AI/ML and software engineering skills.
This project uses the Software Code Quality and Source Code Metrics Dataset from Mendeley available in this link : https://data.mendeley.com/datasets/77p6rzb73n/5 The dataset contains synthesized code smells, issues, quality, and source code metrics information of 60 versions under 10 different repositories.
The version 5 is used. The dataset includes these following information:
- Source code metrics
- Code smells
- Static analysis issues
- Quality attributes
The data is available at three levels:
- Package level
- Class level
- Method level
repositories.csv– Repository information (name, URL, commits, stars, forks)versions.csv– Version information and repository growth metricsattribute-details.csv– Description of quality attributes and metricscodesmells.csv– Code smell rules and descriptions
- 9.4 million+ lines of code analyzed
- 173,000+ classes analyzed
- 10 repositories
- 60 software versions
The full dataset is saved in the data/raw/ folder.
This project can be formulated as:
- Classification, if the target is a quality class.
- Regression, if the target is a numeric quality score.
In the first version of the project, a classification approach has been chosen for simplicity and clearer interpretation.
code-quality-assessment-model/
├── README.md
├── requirements.txt
├── .gitignore
├── LICENSE
├── data/
│ ├── raw/
│ ├── processed/
│ └── sample/
├── notebooks/
│ ├── 01_data_exploration.ipynb
│ ├── 02_preprocessing.ipynb
│ ├── 03_model_training.ipynb
│ └── 04_model_evaluation.ipynb
├── src/
│ ├── __init__.py
│ ├── config.py
│ ├── data_loader.py
│ ├── preprocessing.py
│ ├── feature_engineering.py
│ ├── train.py
│ ├── evaluate.py
│ └── predict.py
├── models/
│ ├── trained_model.pkl
│ └── label_encoder.pkl
├── reports/
│ ├── figures/
│ └── metrics/
├── tests/
│ ├── test_preprocessing.py
│ ├── test_model.py
│ └── test_prediction.py
└── docs/
├── project_overview.md
└── dataset_description.md
The dataset is loaded and inspected to understand:
- Column names.
- Missing values.
- Data types.
- Distributions of features.
- Target label availability.
The preprocessing step includes:
- Removing duplicates.
- Handling missing values.
- Converting data types.
- Encoding categorical variables.
- Normalizing or scaling features if needed.
Relevant software metrics are selected or derived to improve model learning.
Examples may include:
- Complexity metrics.
- Object-oriented metrics.
- Size metrics.
- Coupling metrics.
Several machine learning models can be trained and compared, such as:
- Logistic Regression.
- Random Forest.
- Decision Tree.
- XGBoost or Gradient Boosting.
The model is evaluated using metrics such as:
- Accuracy.
- Precision.
- Recall.
- F1-score.
- Confusion Matrix.
The best-performing model is saved for future prediction and reuse.
- Python
- Jupyter Notebook
- Pandas
- NumPy
- Scikit-learn
- Matplotlib
- Seaborn
- Joblib
Clone the repository:
git clone https://github.com/your-username/code-quality-assessment-model.git
cd code-quality-assessment-modelCreate and activate a virtual environment:
python -m venv venvOn Windows:
venv\Scripts\activateOn macOS/Linux:
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtPut the original dataset in:
data/raw/
Open and run:
notebooks/01_data_exploration.ipynb
Run:
notebooks/02_preprocessing.ipynb
Run:
notebooks/03_model_training.ipynb
Run:
notebooks/04_model_evaluation.ipynb
If a prediction script is included, run:
python src/predict.pyThe project will generate:
- Cleaned and processed data.
- Trained machine learning model.
- Evaluation metrics.
- Visualizations of performance.
- Feature importance analysis.
Results will be stored in the reports/ and models/ folders.
- Add more datasets for better generalization.
- Extend the model to support multiple programming languages.
- Improve feature engineering with static analysis tools.
- Build a web interface for real-time code quality prediction.
- Deploy the model as an API.
This repository is part of my AI/ML portfolio and demonstrates practical skills in:
- Machine learning.
- Data preprocessing.
- Model evaluation.
- Software quality analysis.
- Reproducible project organization.
Henikaja Andriamahay IRIMANANA