0% found this document useful (0 votes)
20 views7 pages

Digit Recognition with Machine Learning

This project report focuses on handwritten digit recognition using classical machine learning models, specifically evaluating the UCI Digits dataset. Various models including Logistic Regression, K-Nearest Neighbors, Support Vector Machine, Decision Tree, and Random Forest were implemented, with the Support Vector Machine achieving the highest accuracy of over 99.1%. The report discusses data preprocessing techniques, model evaluation metrics, and concludes with the performance comparison of the models.

Uploaded by

prarit.work
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

Digit Recognition with Machine Learning

This project report focuses on handwritten digit recognition using classical machine learning models, specifically evaluating the UCI Digits dataset. Various models including Logistic Regression, K-Nearest Neighbors, Support Vector Machine, Decision Tree, and Random Forest were implemented, with the Support Vector Machine achieving the highest accuracy of over 99.1%. The report discusses data preprocessing techniques, model evaluation metrics, and concludes with the performance comparison of the models.

Uploaded by

prarit.work
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ARM 210

Introduction to
machine learning
Project report

Submitted To: Submitted By:


[Link] Choudhary Prarit Arora
AIML B1
04919051623
Email- [Link]@[Link]
Contact - 9999538421
Digit Recognition Using Classical Machine
Learning Models

Link to Notebook

Abstract

Handwritten digit recognition is a classical problem in machine learning and computer


vision, often used to benchmark model performance. This project utilizes the UCI Digits
dataset to evaluate various traditional machine learning classifiers on their ability to
identify handwritten digits (0–9). A range of models including Logistic Regression, K-
Nearest Neighbors, Support Vector Machine, Decision Tree, and Random Forest were
implemented. Their performance was compared using metrics such as accuracy,
precision, recall, F1-score, confusion matrices, and cross-validation scores. Preprocessing
techniques, including normalization and an attempted dimensionality reduction using
PCA, are discussed. Support Vector Machine achieved the highest performance among
all models.

Keywords

Handwritten Digit Recognition, Supervised Learning, Classification Algorithm, Model


Evaluation, Confusion Matrix

1. Introduction

Handwritten digit classification is a well-known pattern recognition problem and serves


as an ideal case study for evaluating various supervised learning algorithms. The task is
to automatically recognize digits written by hand, which is foundational to applications
like postal code recognition, bank check processing, and digit-based entry systems.

This study uses the UCI Digits dataset, which is smaller and more lightweight compared
to MNIST, making it ideal for quick prototyping and comparisons.
2. Dataset Overview

 Dataset Source: UCI Machine Learning Repository (via


[Link].load_digits)
 Shape: 1797 images of 8x8 pixels (64 features per image)
 Classes: 10 (Digits 0 through 9)
 Format: Each image is flattened into a 1D array of 64 pixel intensity values

Each sample in the dataset represents a grayscale digit image. Pixel values range from 0
to 16.

3. Data Preprocessing

 Normalization: Since pixel values range from 0–16, all values were normalized
by dividing by 16 to bring them into the [0, 1] range, which often improves model
convergence and accuracy.
 Train-Test Split:
o 80% for training (1437 samples)
o 20% for testing (360 samples)
o Stratified split was used to ensure class distribution remains consistent
across sets.
 Principal Component Analysis (PCA):
o PCA was attempted to reduce dimensionality and possibly enhance
performance.
o However, applying PCA led to a slight drop in accuracy, possibly due to
loss of information critical for classification. Hence, the raw normalized
features were retained.

4. Models Used

1. Logistic Regression

 A baseline linear classifier that works well with normalized numeric data.
 Surprisingly effective for this task, achieving over 93% accuracy.

2. K-Nearest Neighbors (KNN)

 A non-parametric model that classifies based on the majority class of its k closest
neighbors.
 It performed extremely well, achieving nearly 98.6% accuracy, as digit images
tend to cluster well in pixel-space.

3. Support Vector Machine (SVM)

 A powerful classifier that finds the optimal hyperplane to separate classes using
kernel tricks (RBF used here).
 This model achieved the highest accuracy of all: over 99.1%.

4. Decision Tree

 A simple and interpretable model that recursively splits data based on feature
values.
 Its performance was the weakest among all, with an accuracy of 83.3%.

5. Random Forest

 An ensemble model of multiple decision trees, helping reduce overfitting and


improve generalization.
 Achieved 96.1% accuracy — much better than a single tree.
5. Evaluation Metrics

The following metrics were used for evaluation:

 Accuracy: Ratio of correctly predicted instances over total instances.


 Precision (weighted): True positives / (True positives + False positives),
weighted by class.
 Recall (weighted): True positives / (True positives + False negatives), weighted
by class.
 F1-Score (weighted): Harmonic mean of precision and recall.
 Confusion Matrix: Shows detailed breakdown of actual vs predicted classes.
 Cross-Validation (5-fold): Measures model stability across multiple subsets.

6. Results

Metric Comparison Table:


Model Accuracy Precision Recall F1-Score

Logistic Regression 0.9361 0.9366 0.9361 0.9353

K-Nearest Neighbors 0.9861 0.9867 0.9861 0.9861

Support Vector Machine 0.9917 0.9920 0.9917 0.9917

Decision Tree 0.8333 0.8372 0.8333 0.8335

Random Forest 0.9611 0.9620 0.9611 0.9609

Cross-Validation Scores (5-fold):

 SVM: 0.9882 ± 0.0052


 KNN: 0.9882 ± 0.0087
 Random Forest: 0.9756 ± 0.0062
 Logistic Regression: 0.9429 ± 0.0061
 Decision Tree: 0.8427 ± 0.0233
7. Conclusion

Among the evaluated models, Support Vector Machine (SVM) performed the best with
an accuracy of 99.17% on the test set and strong cross-validation performance. KNN was
a close second, showing the strength of instance-based learning for small image datasets.
Decision Tree, while simple and fast, underperformed likely due to its tendency to
overfit small datasets. Random Forest demonstrated a strong balance between
interpretability and performance.

8. Refrences

1. Scikit-learn Developers. (2024). Scikit-learn User Guide. [Link]


[Link]/stable/user_guide.html
2. Pedregosa, F. et al. (2011). Scikit-learn: Machine Learning in Python. Journal of
Machine Learning Research, 12, 2825–2830.
3. Géron, A. (2019). Hands-On Machine Learning with Scikit-Learn, Keras, and
TensorFlow (2nd ed.). O'Reilly Media.
4. James, G., Witten, D., Hastie, T., & Tibshirani, R. (2021). An Introduction to
Statistical Learning (2nd ed.). Springer. [Link]
5. Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical
Learning (2nd ed.). Springer.
6. Dua, D., & Graff, C. (2019). UCI Machine Learning Repository: Optical
Recognition of Handwritten Digits Dataset. University of California, Irvine.
[Link]
ts
7. LeCun, Y., Bottou, L., Bengio, Y., & Haffner, P. (1998). Gradient-based
learning applied to document recognition. Proceedings of the IEEE, 86(11),
2278–2324. [Link]

8. Kotsiantis, S. B., Zaharakis, I., & Pintelas, P. (2007). Supervised machine


learning: A review of classification techniques. Emerging Artificial Intelligence
Applications in Computer Engineering, 160, 3–24.

9. Jolliffe, I. T., & Cadima, J. (2016). Principal component analysis: A review and
recent developments. Philosophical Transactions of the Royal Society A:
Mathematical, Physical and Engineering Sciences, 374(2065).
[Link]

10. Bhatele, M., Jadon, S., & Chaurasia, P. (2021). A Comparative Study of
Machine Learning Techniques for Digit Recognition. International Journal of
Computer Applications, 183(2), 6–11.

Common questions

Powered by AI

Support Vector Machine (SVM) outperformed other models in the digit recognition task because it effectively utilized kernel tricks, specifically the Radial Basis Function (RBF), to find optimal hyperplanes for class separation. This capability allows SVM to handle non-linear relationships and complex patterns in the dataset, leading to an accuracy of over 99.1% . Additionally, the SVM maintained strong performance during cross-validation, indicating stability and robustness across different data subsets .

Logistic Regression achieved a respectable performance with accuracy over 93%, demonstrating that even simple linear models can be effective with well-preprocessed data. However, more complex models like SVM and Random Forest outperformed it significantly (99.1% and 96.1%, respectively) due to their ability to handle non-linear data relationships and complex feature interactions. SVM's kernel application and Random Forest's ensemble approach enhance predictive accuracy and generalization, which Logistic Regression's linear boundaries could not match .

The Support Vector Machine (SVM) and K-Nearest Neighbors (KNN) models both exhibited great stability with the highest cross-validation scores, recorded as 0.9882 for SVM (± 0.0052) and KNN (± 0.0087). This indicates that these models consistently performed well across different subsets of the dataset, showing that they have strong generalization capabilities and are unlikely to be overfitting to noise or specific data structures present in the original training set .

Normalization in the preprocessing phase involves scaling pixel values from 0 to the range of 0 to 1 by dividing by 16. This step is crucial as it ensures that the feature range is consistent across all inputs, helping improve model convergence rates and overall accuracy. In machine learning, normalized data allows algorithms like logistic regression or SVM to function optimally without being skewed by varying scales in feature sets .

The attempt to use Principal Component Analysis (PCA) for dimensionality reduction resulted in a slight drop in model accuracy. The reduction in performance was attributed to the possibility that critical information necessary for accurate classification was lost during PCA transformation, leading the researchers to retain the original normalized features instead .

The train-test split in this study, dividing 80% for training and 20% for testing while ensuring a stratified split, ensures that the model has a representative sample of the data during both phases. Stratification maintains class distributions, making the evaluation reliable and true to real-world scenarios, preventing imbalanced learning or biased performance outcomes that could occur with unequal class representation .

The confusion matrix provides a detailed breakdown of actual versus predicted classes, allowing for the evaluation of model performance beyond simple accuracy metrics. It helps identify specific types of errors, such as false positives or false negatives, and assesses how well a model distinguishes between different classes. This detailed analysis aids in understanding not only where a model excels but also where it consistently misclassifies, offering insights for targeted improvements .

The Decision Tree model exhibited the weakest performance among the models used, with an accuracy of 83.3%, largely due to its simple structure and tendency to overfit small datasets. In contrast, Random Forest, an ensemble of multiple decision trees, achieved a much better accuracy of 96.1%. This improved performance is because Random Forest mitigates overfitting through bootstrapping and averaging multiple trees’ predictions, enhancing generalizability .

K-Nearest Neighbors (KNN) is particularly effective for the UCI Digits dataset because the digit images tend to cluster well in pixel-space, allowing the non-parametric model to classify based on proximity effectively. This clustering makes it easy for KNN to determine the majority class among its k neighbors, leading to high accuracy rates, around 98.6% in this case .

Decision Trees showed a relatively low performance with an accuracy of 83.3% due to their inherent tendency to overfit small dataset samples. Their simple structure, relying on single feature splits, fails to capture complex patterns present in the dataset effectively. Furthermore, without additional predictive trees or ensemble techniques like Random Forests, single Decision Trees lack robustness and are more susceptible to variations in the input data .

You might also like