Code quality assessor: 77% accuracy, and what it is worth
For a machine learning course (CSCI417, Nile University, spring 2025) our team of five scraped Python functions from public GitHub repositories, labelled each with pylint, and trained classifiers to predict the label from 18 structural features. The best model reaches 77.2% accuracy. Always predicting the most common class reaches 62.0%, so the real gain is 15 points.
Results, with the baseline
Data and label
The GitHub API gave function source from five public repositories of exercises and algorithms. Each function got 18 features with the ast module and radon: size, arguments, returns, calls, cyclomatic complexity, Halstead difficulty and bugs, docstring and comment counts, naming checks and return length. Stubs were dropped (under 3 lines, or complexity 1).
The label comes from pylint, run on each function alone with the convention, refactor and warning checks switched off, so only errors count against the 0 to 10 score. Up to 5 is low, up to 7 mid, above 7 high. After removing 837 duplicates the table had 15,929 functions: 4,163 low, 1,894 mid and 9,872 high, of which 8,312 scored exactly 10.
Split: 80/20, stratified, random_state 42.
Models
Logistic regression on scaled features; XGBoost with defaults; a five-hidden-layer network (13,459 parameters, dropout, early stopping); and a random forest tuned over 36 settings with 3-fold cross-validation (best: 200 trees, depth 30, 75.7% in validation, 77.2% on test).
What this does not show
The label measures pylint errors, not quality. With style checks off, a function scores 10 unless pylint finds an error. Running it on one function alone also flags names defined elsewhere in the file.
The split is random across functions. Functions from the same repository land in both train and test, and five educational repositories say little about code in general.
So the model predicts what pylint would say about a function of this kind, not how maintainable the code is. A fair next test is to hold out whole repositories and report macro-F1.