-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e768d2b
commit d87c3e0
Showing
16 changed files
with
9,670 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
910 changes: 910 additions & 0 deletions
910
NoteBooks/.ipynb_checkpoints/Data_Analysis-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
537 changes: 537 additions & 0 deletions
537
NoteBooks/.ipynb_checkpoints/KNN Classifier on Dataset-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
618 changes: 618 additions & 0 deletions
618
NoteBooks/.ipynb_checkpoints/Neural Network on Handwritten Digits-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
539 changes: 539 additions & 0 deletions
539
NoteBooks/.ipynb_checkpoints/PCA on Dataset-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
226 changes: 226 additions & 0 deletions
226
NoteBooks/.ipynb_checkpoints/Primary Data Analysis-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
364 changes: 364 additions & 0 deletions
364
NoteBooks/.ipynb_checkpoints/SVM on HandWritten Dataset-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,364 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# SVM on Handwritten Digits" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Loading libraries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n", | ||
"from sklearn.svm import SVC\n", | ||
"import numpy as np\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import pandas as pd\n", | ||
"from sklearn import decomposition\n", | ||
"from sklearn.preprocessing import StandardScaler\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"from sklearn import metrics" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Loading data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
"<style scoped>\n", | ||
" .dataframe tbody tr th:only-of-type {\n", | ||
" vertical-align: middle;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe tbody tr th {\n", | ||
" vertical-align: top;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe thead th {\n", | ||
" text-align: right;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<table border=\"1\" class=\"dataframe\">\n", | ||
" <thead>\n", | ||
" <tr style=\"text-align: right;\">\n", | ||
" <th></th>\n", | ||
" <th>pixel0</th>\n", | ||
" <th>pixel1</th>\n", | ||
" <th>pixel2</th>\n", | ||
" <th>pixel3</th>\n", | ||
" <th>pixel4</th>\n", | ||
" <th>pixel5</th>\n", | ||
" <th>pixel6</th>\n", | ||
" <th>pixel7</th>\n", | ||
" <th>pixel8</th>\n", | ||
" <th>pixel9</th>\n", | ||
" <th>...</th>\n", | ||
" <th>pixel775</th>\n", | ||
" <th>pixel776</th>\n", | ||
" <th>pixel777</th>\n", | ||
" <th>pixel778</th>\n", | ||
" <th>pixel779</th>\n", | ||
" <th>pixel780</th>\n", | ||
" <th>pixel781</th>\n", | ||
" <th>pixel782</th>\n", | ||
" <th>pixel783</th>\n", | ||
" <th>class</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>252</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>...</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>1</th>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>...</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2</th>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>...</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3</th>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>...</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>4</th>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>253</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>254</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>...</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>255</td>\n", | ||
" <td>1</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"<p>5 rows × 785 columns</p>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" pixel0 pixel1 pixel2 pixel3 pixel4 pixel5 pixel6 pixel7 pixel8 \\\n", | ||
"0 255 255 254 255 255 255 252 255 255 \n", | ||
"1 255 255 254 255 255 254 255 255 255 \n", | ||
"2 255 254 255 255 255 255 254 255 254 \n", | ||
"3 254 255 255 255 254 255 255 255 254 \n", | ||
"4 254 255 255 253 255 255 255 254 255 \n", | ||
"\n", | ||
" pixel9 ... pixel775 pixel776 pixel777 pixel778 pixel779 pixel780 \\\n", | ||
"0 255 ... 255 255 255 255 255 255 \n", | ||
"1 255 ... 255 255 255 255 255 255 \n", | ||
"2 255 ... 255 255 255 255 255 255 \n", | ||
"3 255 ... 255 255 255 255 255 255 \n", | ||
"4 255 ... 255 255 255 255 255 255 \n", | ||
"\n", | ||
" pixel781 pixel782 pixel783 class \n", | ||
"0 255 255 255 1 \n", | ||
"1 255 255 255 1 \n", | ||
"2 255 255 255 1 \n", | ||
"3 255 255 255 1 \n", | ||
"4 255 255 255 1 \n", | ||
"\n", | ||
"[5 rows x 785 columns]" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"df = pd.read_csv(\"E://Telugu Character Recogniton//CSV_dataset//CSV_datasetsix_vowel_dataset_with_class.csv\")\n", | ||
"df.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Splitting data into 'train' and 'test'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pix=[]\n", | ||
"for i in range(784):\n", | ||
" pix.append('pixel'+str(i))\n", | ||
"features=pix\n", | ||
"X = df.loc[:, features].values\n", | ||
"y = df.loc[:,'class'].values\n", | ||
"\n", | ||
"X_train, X_test, y_train, y_test = train_test_split(\n", | ||
" X, y, test_size = 0.25, random_state = 100)\n", | ||
"y_train=y_train.ravel()\n", | ||
"y_test=y_test.ravel()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Building classifier" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"svm_model = SVC(kernel = 'poly', C = 1, gamma=2).fit(X_train, y_train)\n", | ||
"svm_predictions = svm_model.predict(X_test)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Finding accuracy of the model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Accuracy: 89.33333333333333\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"accuracy = svm_model.score(X_test, y_test)\n", | ||
"print('Accuracy: ',accuracy*100)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## <font color='tomato'>Accuracy of the model is: </font><font color='MediumSpringGreen'>89.333333333</font>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Conclusion:\n", | ||
"* <font color='navy' face='lucida console'><strong>Support Vector Machine(SVM) performs well on the small dataset when compared to other models like K-NNC and Neural Neetworks.</strong></font>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.