Open Elective: handwritten digit classification
Project
An educational scikit-learn random forest that classifies 8×8 handwritten digit images (0–9) using 64 pixel values. The model was trained on the public scikit-learn digits dataset, not personally collected data and not a pretrained neural network. The project uses hyperparameter tuning through 3-fold stratified cross-validation; calling it fine-tuning of a pretrained model would be inaccurate.
Dataset and evaluation
- Source:
sklearn.datasets.load_digits, 1,797 labeled images. - Stratified training/test split: 1,437 / 360,
random_state=42. - Baseline:
RandomForestClassifier(n_estimators=100, max_depth=2, random_state=42). - Tuning:
GridSearchCVovern_estimators[100, 200],max_depth[5, 10, None], andmin_samples_leaf[1, 2], with 3-fold stratified training cross-validation. The test set was not used to select parameters. - Best settings:
max_depth=10,min_samples_leaf=1,n_estimators=200. - Baseline test accuracy: 80.56% (290/360).
- Tuned test accuracy: 96.39% (347/360); gain 15.83 percentage points.
The starting forest was deliberately shallow. This large gain is a result on this educational dataset and a single test split, not a guarantee on new data. The notebook shows the full code and classification report.
Files
Open_Elective_Train_and_Tune.ipynb: training, validation, comparison, and model export.tuned_digits_model.joblib: fitted tuned random forest.requirements.txt: scikit-learn version used to serialize the model.
Reuse
Run the notebook in Colab to retrain. For predictions with the saved artifact in a compatible trusted Python environment:
import joblib
from sklearn.datasets import load_digits
model = joblib.load("tuned_digits_model.joblib")
sample = load_digits().data[:1] # one 8x8 image flattened to 64 pixel values
print(model.predict(sample))
Only load joblib files from sources you trust. The repository does not host an interactive prediction app; the notebook and serialized model are available for review.