{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"#### I recently learnt Principal component analysis(PCA) and wanted to apply my learning to MNIST data which is a collection of handwritten digits.Each digit is of 28 x 28 pixels.Each digit has been transformed into 784(28 x 28) columns i.e 784 features.The labels denote the digit which each particular row represents.Please upvote and feel free to comment or ask any questions.\n\n","metadata":{}},{"cell_type":"code","source":"from IPython.display import Image\nimport os\n!ls ../input/images\nImage(\"../input/images/mnist.png\")","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:55:38.045954Z","iopub.execute_input":"2023-02-14T14:55:38.046411Z","iopub.status.idle":"2023-02-14T14:55:39.250129Z","shell.execute_reply.started":"2023-02-14T14:55:38.046374Z","shell.execute_reply":"2023-02-14T14:55:39.248257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot  as plt\n\nfor dirpath, dirname, filename in os.walk('/kaggle/input'):\n   print(dirpath)\n   print(dirname)\n   print(filename)\n   print(\"*********\")","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:55:41.858648Z","iopub.execute_input":"2023-02-14T14:55:41.859121Z","iopub.status.idle":"2023-02-14T14:55:41.869209Z","shell.execute_reply.started":"2023-02-14T14:55:41.859067Z","shell.execute_reply":"2023-02-14T14:55:41.867556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for dirpath,dirname,filename in os.walk(\"/kaggle/input/digit-recognizer\"):\n    for i in filename:\n        print(os.path.join(dirpath,i))","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:55:45.206195Z","iopub.execute_input":"2023-02-14T14:55:45.206735Z","iopub.status.idle":"2023-02-14T14:55:45.215418Z","shell.execute_reply.started":"2023-02-14T14:55:45.206697Z","shell.execute_reply":"2023-02-14T14:55:45.213568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:55:47.757386Z","iopub.execute_input":"2023-02-14T14:55:47.757850Z","iopub.status.idle":"2023-02-14T14:55:50.410922Z","shell.execute_reply.started":"2023-02-14T14:55:47.757815Z","shell.execute_reply":"2023-02-14T14:55:50.409540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:55:51.881727Z","iopub.execute_input":"2023-02-14T14:55:51.882146Z","iopub.status.idle":"2023-02-14T14:55:51.891339Z","shell.execute_reply.started":"2023-02-14T14:55:51.882113Z","shell.execute_reply":"2023-02-14T14:55:51.889558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head() #The labels denote the actual digit","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:55:55.093682Z","iopub.execute_input":"2023-02-14T14:55:55.094099Z","iopub.status.idle":"2023-02-14T14:55:55.119040Z","shell.execute_reply.started":"2023-02-14T14:55:55.094065Z","shell.execute_reply":"2023-02-14T14:55:55.117327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.sample(1,random_state=42) #to replicate same result each time","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:55:57.325736Z","iopub.execute_input":"2023-02-14T14:55:57.326123Z","iopub.status.idle":"2023-02-14T14:55:57.346485Z","shell.execute_reply.started":"2023-02-14T14:55:57.326093Z","shell.execute_reply":"2023-02-14T14:55:57.345235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#visual representation of the above row\nplt.imshow(df.iloc[5457,1:].values.reshape(28,28)) #reshaping the 784 columns into 28 * 28 array","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:56:00.023524Z","iopub.execute_input":"2023-02-14T14:56:00.023903Z","iopub.status.idle":"2023-02-14T14:56:00.234962Z","shell.execute_reply.started":"2023-02-14T14:56:00.023872Z","shell.execute_reply":"2023-02-14T14:56:00.233936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=df.iloc[:,1:] #assigning all pixel columns to X\ny=df.iloc[:,0]  #assigning labels to target variable y","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:56:03.795768Z","iopub.execute_input":"2023-02-14T14:56:03.796276Z","iopub.status.idle":"2023-02-14T14:56:03.804720Z","shell.execute_reply.started":"2023-02-14T14:56:03.796238Z","shell.execute_reply":"2023-02-14T14:56:03.803373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#splitting into train and test values\nfrom sklearn.model_selection import train_test_split\nX_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:56:06.391514Z","iopub.execute_input":"2023-02-14T14:56:06.392742Z","iopub.status.idle":"2023-02-14T14:56:06.689824Z","shell.execute_reply.started":"2023-02-14T14:56:06.392696Z","shell.execute_reply":"2023-02-14T14:56:06.688563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape,X_test.shape ","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:56:08.943580Z","iopub.execute_input":"2023-02-14T14:56:08.943993Z","iopub.status.idle":"2023-02-14T14:56:08.952515Z","shell.execute_reply.started":"2023-02-14T14:56:08.943960Z","shell.execute_reply":"2023-02-14T14:56:08.950607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### First we will apply an algo say KNN (in this case) without the use of PCA and check the accuracy.","metadata":{}},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier\nknn=KNeighborsClassifier() \nknn.fit(X_train,y_train) # fit the training data","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:56:12.299795Z","iopub.execute_input":"2023-02-14T14:56:12.300218Z","iopub.status.idle":"2023-02-14T14:56:12.322987Z","shell.execute_reply.started":"2023-02-14T14:56:12.300174Z","shell.execute_reply":"2023-02-14T14:56:12.321689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#time required to run KNN on 784 features\nimport time\nstart=time.time()  # current time\ny_pred=knn.predict(X_test) #predicted labels by KNN\nprint(time.time()-start) ","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:56:14.795491Z","iopub.execute_input":"2023-02-14T14:56:14.795944Z","iopub.status.idle":"2023-02-14T14:56:28.745065Z","shell.execute_reply.started":"2023-02-14T14:56:14.795898Z","shell.execute_reply":"2023-02-14T14:56:28.743651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#measuring accuracy\nfrom sklearn.metrics import accuracy_score\naccuracy_score(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:00.435723Z","iopub.execute_input":"2023-02-14T14:57:00.436137Z","iopub.status.idle":"2023-02-14T14:57:00.447777Z","shell.execute_reply.started":"2023-02-14T14:57:00.436107Z","shell.execute_reply":"2023-02-14T14:57:00.446340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### The accuracy is quite good with run time ~13.9 seconds.But what if we reach the same or near about accuracy with less no. of features and less run time with PCA?Won't it be great","metadata":{}},{"cell_type":"code","source":"#Mean center the data for PCA\nfrom sklearn.preprocessing import StandardScaler \nscaler=StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:02.651777Z","iopub.execute_input":"2023-02-14T14:57:02.652258Z","iopub.status.idle":"2023-02-14T14:57:02.658184Z","shell.execute_reply.started":"2023-02-14T14:57:02.652220Z","shell.execute_reply":"2023-02-14T14:57:02.656851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=scaler.fit_transform(X_train) #fit and transform the training data\nX_test=scaler.transform(X_test)       #transform the test data","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:07.882814Z","iopub.execute_input":"2023-02-14T14:57:07.883314Z","iopub.status.idle":"2023-02-14T14:57:08.597924Z","shell.execute_reply.started":"2023-02-14T14:57:07.883260Z","shell.execute_reply":"2023-02-14T14:57:08.596658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### PCA","metadata":{}},{"cell_type":"code","source":"#PCA\nfrom sklearn.decomposition import PCA\npca=PCA(n_components=100) #try with None,200,300 etc","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:10.967341Z","iopub.execute_input":"2023-02-14T14:57:10.967833Z","iopub.status.idle":"2023-02-14T14:57:10.974807Z","shell.execute_reply.started":"2023-02-14T14:57:10.967798Z","shell.execute_reply":"2023-02-14T14:57:10.973235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_trf=pca.fit_transform(X_train) #X_train_trf is the transformed training data after PCA\nX_test_trf=pca.transform(X_test)       #X_test_trf is the transformed test data after PCA","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:16.209470Z","iopub.execute_input":"2023-02-14T14:57:16.209965Z","iopub.status.idle":"2023-02-14T14:57:21.143932Z","shell.execute_reply.started":"2023-02-14T14:57:16.209925Z","shell.execute_reply":"2023-02-14T14:57:21.141667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_trf.shape # the 784 features have reduced to 100 principal components with PC1 having the largest variance along its axis.\n#The order of variance from largest to smallest goes on from PC1 to PC100.","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:23.907249Z","iopub.execute_input":"2023-02-14T14:57:23.907801Z","iopub.status.idle":"2023-02-14T14:57:23.916851Z","shell.execute_reply.started":"2023-02-14T14:57:23.907763Z","shell.execute_reply":"2023-02-14T14:57:23.915397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Apply knn again with reduced features\nknn=KNeighborsClassifier()\nknn.fit(X_train_trf,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:25.834827Z","iopub.execute_input":"2023-02-14T14:57:25.835219Z","iopub.status.idle":"2023-02-14T14:57:25.849826Z","shell.execute_reply.started":"2023-02-14T14:57:25.835186Z","shell.execute_reply":"2023-02-14T14:57:25.848563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"start=time.time()\ny_pred=knn.predict(X_test_trf)\nprint(time.time()-start)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:28.403336Z","iopub.execute_input":"2023-02-14T14:57:28.403789Z","iopub.status.idle":"2023-02-14T14:57:35.974749Z","shell.execute_reply.started":"2023-02-14T14:57:28.403755Z","shell.execute_reply":"2023-02-14T14:57:35.972612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\naccuracy_score(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:57:39.119982Z","iopub.execute_input":"2023-02-14T14:57:39.120782Z","iopub.status.idle":"2023-02-14T14:57:39.130956Z","shell.execute_reply.started":"2023-02-14T14:57:39.120735Z","shell.execute_reply":"2023-02-14T14:57:39.129324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### The accuracy is almost the same but with reduced featues and reduced run time.","metadata":{}},{"cell_type":"markdown","source":"#### You can run the following block of code but it would take too much time so we will visually try to find the accuracy greater than 95.4% with different no of PCA components","metadata":{}},{"cell_type":"code","source":"# try to find higher accuracy with different no of PCA components\n\n# a=[]\n# for i in range(1,785):\n#     pca=PCA(n_components=i)\n#     X_train_trf=pca.fit_transform(X_train)\n#     X_test_trf=pca.transform(X_test)\n#     knn=KNeighborsClassifier()\n#     knn.fit(X_train_trf,y_train)\n#     y_pred=knn.predict(X_test_trf)\n#     b=accuracy_score(y_test,y_pred).tolist()\n#     a.append(b)\n    \n# for i in enumerate(a):\n#     print(i)\n","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:54:33.256652Z","iopub.execute_input":"2023-02-14T14:54:33.257066Z","iopub.status.idle":"2023-02-14T14:54:33.264073Z","shell.execute_reply.started":"2023-02-14T14:54:33.257034Z","shell.execute_reply":"2023-02-14T14:54:33.261894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Visualization","metadata":{}},{"cell_type":"markdown","source":"#### 2D","metadata":{}},{"cell_type":"code","source":"# Suppose we want to turn it in into a 2D cordinate system i.e PC1 and PC2\npca=PCA(n_components=2)\nX_train_trf=pca.fit_transform(X_train)\nX_test_trf=pca.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T14:59:58.528780Z","iopub.execute_input":"2023-02-14T14:59:58.529240Z","iopub.status.idle":"2023-02-14T15:00:02.260091Z","shell.execute_reply.started":"2023-02-14T14:59:58.529204Z","shell.execute_reply":"2023-02-14T15:00:02.257916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_trf.shape # X_train_trf.shape[1] = PC1 AND PC2 ","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:04.639328Z","iopub.execute_input":"2023-02-14T15:00:04.639711Z","iopub.status.idle":"2023-02-14T15:00:04.646234Z","shell.execute_reply.started":"2023-02-14T15:00:04.639680Z","shell.execute_reply":"2023-02-14T15:00:04.645395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PC1=X_train_trf[:,0]\nPC2=X_train_trf[:,1]","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:09.635794Z","iopub.execute_input":"2023-02-14T15:00:09.636287Z","iopub.status.idle":"2023-02-14T15:00:09.643342Z","shell.execute_reply.started":"2023-02-14T15:00:09.636249Z","shell.execute_reply":"2023-02-14T15:00:09.641381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#interactive map\nimport plotly.express as px\nfig=px.scatter(x=PC1,y=PC2,color=y_train.astype(str))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:11.748648Z","iopub.execute_input":"2023-02-14T15:00:11.749219Z","iopub.status.idle":"2023-02-14T15:00:11.967131Z","shell.execute_reply.started":"2023-02-14T15:00:11.749172Z","shell.execute_reply":"2023-02-14T15:00:11.965673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 3D","metadata":{}},{"cell_type":"code","source":"# Suppose we want to turn it in into a 3D cordinate system i.e PC1,PC2 and PC3\npca=PCA(n_components=3)\nX_train_trf=pca.fit_transform(X_train)\nX_test_trf=pca.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:16.155060Z","iopub.execute_input":"2023-02-14T15:00:16.155552Z","iopub.status.idle":"2023-02-14T15:00:20.209877Z","shell.execute_reply.started":"2023-02-14T15:00:16.155516Z","shell.execute_reply":"2023-02-14T15:00:20.208424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PC1=X_train_trf[:,0]\nPC2=X_train_trf[:,1]\nPC3=X_train_trf[:,2]","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:21.355168Z","iopub.execute_input":"2023-02-14T15:00:21.355658Z","iopub.status.idle":"2023-02-14T15:00:21.362937Z","shell.execute_reply.started":"2023-02-14T15:00:21.355621Z","shell.execute_reply":"2023-02-14T15:00:21.361517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#interactive map\nimport plotly.express as px\nfig=px.scatter_3d(x=PC1,y=PC2,z=PC3,color=y_train.astype(str))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:23.727255Z","iopub.execute_input":"2023-02-14T15:00:23.728825Z","iopub.status.idle":"2023-02-14T15:00:23.897079Z","shell.execute_reply.started":"2023-02-14T15:00:23.728773Z","shell.execute_reply":"2023-02-14T15:00:23.894950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#eigen values\npca.explained_variance_","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:28.580203Z","iopub.execute_input":"2023-02-14T15:00:28.580644Z","iopub.status.idle":"2023-02-14T15:00:28.588330Z","shell.execute_reply.started":"2023-02-14T15:00:28.580609Z","shell.execute_reply":"2023-02-14T15:00:28.587150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#eigen vector\npca.components_.shape   # 3 eigen vectors with in 784 dimension","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:30.787329Z","iopub.execute_input":"2023-02-14T15:00:30.787732Z","iopub.status.idle":"2023-02-14T15:00:30.796778Z","shell.execute_reply.started":"2023-02-14T15:00:30.787700Z","shell.execute_reply":"2023-02-14T15:00:30.794923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#% contribution of each PCA (PC1,PC2 & PC3 in order) to variance\n(pca.explained_variance_ratio_)*100","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:33.499381Z","iopub.execute_input":"2023-02-14T15:00:33.499841Z","iopub.status.idle":"2023-02-14T15:00:33.509428Z","shell.execute_reply.started":"2023-02-14T15:00:33.499806Z","shell.execute_reply":"2023-02-14T15:00:33.507796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sum((pca.explained_variance_ratio_)*100) ","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:35.911085Z","iopub.execute_input":"2023-02-14T15:00:35.911591Z","iopub.status.idle":"2023-02-14T15:00:35.921711Z","shell.execute_reply.started":"2023-02-14T15:00:35.911551Z","shell.execute_reply":"2023-02-14T15:00:35.920188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### The total contribution  of the three PC's to variance is only 13%.we need to reach atleast 90% or more.This means inclusion of more PC's.","metadata":{}},{"cell_type":"markdown","source":"#### Lets check the no. of PC's required for atleast 90% variation","metadata":{}},{"cell_type":"code","source":"pca=PCA(n_components=None) # trying all features i.e 784 PC's\nX_train_trf=pca.fit_transform(X_train)\nX_test_trf=pca.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:40.546689Z","iopub.execute_input":"2023-02-14T15:00:40.547110Z","iopub.status.idle":"2023-02-14T15:00:45.519178Z","shell.execute_reply.started":"2023-02-14T15:00:40.547077Z","shell.execute_reply":"2023-02-14T15:00:45.517397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca.components_.shape #784 eigen vectors in 784 dimension space.","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:00:48.667247Z","iopub.execute_input":"2023-02-14T15:00:48.667964Z","iopub.status.idle":"2023-02-14T15:00:48.673984Z","shell.execute_reply.started":"2023-02-14T15:00:48.667926Z","shell.execute_reply":"2023-02-14T15:00:48.673082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a=np.arange(1,785)\npc=pd.DataFrame({'features':a,'variance':pca.explained_variance_ratio_})\nprint(pc)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:01:03.120087Z","iopub.execute_input":"2023-02-14T15:01:03.120515Z","iopub.status.idle":"2023-02-14T15:01:03.132904Z","shell.execute_reply.started":"2023-02-14T15:01:03.120480Z","shell.execute_reply":"2023-02-14T15:01:03.131775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(np.cumsum(pc['variance']))","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:01:10.984903Z","iopub.execute_input":"2023-02-14T15:01:10.985493Z","iopub.status.idle":"2023-02-14T15:01:11.207551Z","shell.execute_reply.started":"2023-02-14T15:01:10.985451Z","shell.execute_reply":"2023-02-14T15:01:11.206141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### It seems we need atleast 250 PC's for 90% variation.","metadata":{}},{"cell_type":"code","source":"#Highest accuracy with minimum no. features\npca=PCA(n_components=90) # 85 PC's\nX_train_trf=pca.fit_transform(X_train)\nX_test_trf=pca.transform(X_test)\nknn.fit(X_train_trf,y_train)\ny_pred=knn.predict(X_test_trf)\naccuracy_score(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2023-02-14T15:03:00.815858Z","iopub.execute_input":"2023-02-14T15:03:00.816247Z","iopub.status.idle":"2023-02-14T15:03:12.315982Z","shell.execute_reply.started":"2023-02-14T15:03:00.816217Z","shell.execute_reply":"2023-02-14T15:03:12.314429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Here i demonstrated the use of PCA for dimensionality reduction.We were able to reduce our features from 784 to 90 with 95.5% accuracy.","metadata":{}}]}