{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:10.018420Z","iopub.execute_input":"2025-07-12T07:30:10.018721Z","iopub.status.idle":"2025-07-12T07:30:10.026754Z","shell.execute_reply.started":"2025-07-12T07:30:10.018681Z","shell.execute_reply":"2025-07-12T07:30:10.025943Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# this is  using without PCA \n# and after PCA is on down side ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:10.027977Z","iopub.execute_input":"2025-07-12T07:30:10.028296Z","iopub.status.idle":"2025-07-12T07:30:10.045111Z","shell.execute_reply.started":"2025-07-12T07:30:10.028276Z","shell.execute_reply":"2025-07-12T07:30:10.044274Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:10.049207Z","iopub.execute_input":"2025-07-12T07:30:10.049534Z","iopub.status.idle":"2025-07-12T07:30:10.062819Z","shell.execute_reply.started":"2025-07-12T07:30:10.049509Z","shell.execute_reply":"2025-07-12T07:30:10.061926Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df =pd.read_csv('/kaggle/input/digit-recognizer/train.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:10.064130Z","iopub.execute_input":"2025-07-12T07:30:10.064399Z","iopub.status.idle":"2025-07-12T07:30:12.467457Z","shell.execute_reply.started":"2025-07-12T07:30:10.064377Z","shell.execute_reply":"2025-07-12T07:30:12.466412Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:12.468901Z","iopub.execute_input":"2025-07-12T07:30:12.469179Z","iopub.status.idle":"2025-07-12T07:30:12.482945Z","shell.execute_reply.started":"2025-07-12T07:30:12.469158Z","shell.execute_reply":"2025-07-12T07:30:12.482179Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.sample()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:12.483805Z","iopub.execute_input":"2025-07-12T07:30:12.484133Z","iopub.status.idle":"2025-07-12T07:30:12.509139Z","shell.execute_reply.started":"2025-07-12T07:30:12.484107Z","shell.execute_reply":"2025-07-12T07:30:12.508249Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:12.511277Z","iopub.execute_input":"2025-07-12T07:30:12.511583Z","iopub.status.idle":"2025-07-12T07:30:12.515544Z","shell.execute_reply.started":"2025-07-12T07:30:12.511562Z","shell.execute_reply":"2025-07-12T07:30:12.514904Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(df.iloc[10132,1:].values.reshape(28,28))  # this code is used to watch a picture ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:12.516421Z","iopub.execute_input":"2025-07-12T07:30:12.516689Z","iopub.status.idle":"2025-07-12T07:30:12.691404Z","shell.execute_reply.started":"2025-07-12T07:30:12.516669Z","shell.execute_reply":"2025-07-12T07:30:12.690526Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(df.iloc[36274,1:].values.reshape(28,28)) ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:12.692212Z","iopub.execute_input":"2025-07-12T07:30:12.692464Z","iopub.status.idle":"2025-07-12T07:30:12.858874Z","shell.execute_reply.started":"2025-07-12T07:30:12.692444Z","shell.execute_reply":"2025-07-12T07:30:12.857972Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = df.iloc[:,1:]\ny =df.iloc[:,0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:12.860014Z","iopub.execute_input":"2025-07-12T07:30:12.860333Z","iopub.status.idle":"2025-07-12T07:30:12.865231Z","shell.execute_reply.started":"2025-07-12T07:30:12.860304Z","shell.execute_reply":"2025-07-12T07:30:12.864379Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from 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":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:12.865969Z","iopub.execute_input":"2025-07-12T07:30:12.866193Z","iopub.status.idle":"2025-07-12T07:30:13.369911Z","shell.execute_reply.started":"2025-07-12T07:30:12.866175Z","shell.execute_reply":"2025-07-12T07:30:13.369151Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:13.370770Z","iopub.execute_input":"2025-07-12T07:30:13.371040Z","iopub.status.idle":"2025-07-12T07:30:13.376667Z","shell.execute_reply.started":"2025-07-12T07:30:13.371020Z","shell.execute_reply":"2025-07-12T07:30:13.375837Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:13.379462Z","iopub.execute_input":"2025-07-12T07:30:13.379763Z","iopub.status.idle":"2025-07-12T07:30:13.393790Z","shell.execute_reply.started":"2025-07-12T07:30:13.379688Z","shell.execute_reply":"2025-07-12T07:30:13.392870Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":" knn =KNeighborsClassifier()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:13.394797Z","iopub.execute_input":"2025-07-12T07:30:13.395482Z","iopub.status.idle":"2025-07-12T07:30:13.409642Z","shell.execute_reply.started":"2025-07-12T07:30:13.395436Z","shell.execute_reply":"2025-07-12T07:30:13.408668Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"knn.fit(X_train,y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:13.410542Z","iopub.execute_input":"2025-07-12T07:30:13.410832Z","iopub.status.idle":"2025-07-12T07:30:13.539965Z","shell.execute_reply.started":"2025-07-12T07:30:13.410792Z","shell.execute_reply":"2025-07-12T07:30:13.539139Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import time \nstart =time.time()\ny_pred = knn.predict(X_test)\nprint(time.time() - start)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:13.540801Z","iopub.execute_input":"2025-07-12T07:30:13.541108Z","iopub.status.idle":"2025-07-12T07:30:26.673582Z","shell.execute_reply.started":"2025-07-12T07:30:13.541086Z","shell.execute_reply":"2025-07-12T07:30:26.672898Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\naccuracy_score(y_test,y_pred)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:26.674471Z","iopub.execute_input":"2025-07-12T07:30:26.674795Z","iopub.status.idle":"2025-07-12T07:30:26.682441Z","shell.execute_reply.started":"2025-07-12T07:30:26.674773Z","shell.execute_reply":"2025-07-12T07:30:26.681497Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# pridict with the help of PCA ","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nscaler =StandardScaler()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:26.683453Z","iopub.execute_input":"2025-07-12T07:30:26.683789Z","iopub.status.idle":"2025-07-12T07:30:26.699948Z","shell.execute_reply.started":"2025-07-12T07:30:26.683762Z","shell.execute_reply":"2025-07-12T07:30:26.699062Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train =scaler.fit_transform(X_train)\nX_test =scaler.transform(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:26.700784Z","iopub.execute_input":"2025-07-12T07:30:26.701072Z","iopub.status.idle":"2025-07-12T07:30:27.241785Z","shell.execute_reply.started":"2025-07-12T07:30:26.701044Z","shell.execute_reply":"2025-07-12T07:30:27.240879Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# pca \nfrom sklearn.decomposition import PCA\npca =PCA(n_components =100)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:27.242799Z","iopub.execute_input":"2025-07-12T07:30:27.243100Z","iopub.status.idle":"2025-07-12T07:30:27.247283Z","shell.execute_reply.started":"2025-07-12T07:30:27.243069Z","shell.execute_reply":"2025-07-12T07:30:27.246604Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_trf =pca.fit_transform(X_train)\nX_test_trf = pca.transform(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:27.247830Z","iopub.execute_input":"2025-07-12T07:30:27.248051Z","iopub.status.idle":"2025-07-12T07:30:30.076078Z","shell.execute_reply.started":"2025-07-12T07:30:27.248030Z","shell.execute_reply":"2025-07-12T07:30:30.075268Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:30.077127Z","iopub.execute_input":"2025-07-12T07:30:30.077383Z","iopub.status.idle":"2025-07-12T07:30:30.082139Z","shell.execute_reply.started":"2025-07-12T07:30:30.077363Z","shell.execute_reply":"2025-07-12T07:30:30.081527Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_trf.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:30.082922Z","iopub.execute_input":"2025-07-12T07:30:30.083384Z","iopub.status.idle":"2025-07-12T07:30:30.101148Z","shell.execute_reply.started":"2025-07-12T07:30:30.083360Z","shell.execute_reply":"2025-07-12T07:30:30.100377Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"knn = KNeighborsClassifier()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:30.101817Z","iopub.execute_input":"2025-07-12T07:30:30.102070Z","iopub.status.idle":"2025-07-12T07:30:30.116011Z","shell.execute_reply.started":"2025-07-12T07:30:30.102051Z","shell.execute_reply":"2025-07-12T07:30:30.115181Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"knn.fit(X_train_trf,y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:30.117279Z","iopub.execute_input":"2025-07-12T07:30:30.117604Z","iopub.status.idle":"2025-07-12T07:30:30.150318Z","shell.execute_reply.started":"2025-07-12T07:30:30.117568Z","shell.execute_reply":"2025-07-12T07:30:30.149419Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import time \nstart = time.time()\n\ny_pred =knn.predict(X_test_trf)\nprint(time.time()-start)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:30.151346Z","iopub.execute_input":"2025-07-12T07:30:30.151576Z","iopub.status.idle":"2025-07-12T07:30:31.836660Z","shell.execute_reply.started":"2025-07-12T07:30:30.151557Z","shell.execute_reply":"2025-07-12T07:30:31.835754Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"accuracy_score(y_test,y_pred)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:31.837626Z","iopub.execute_input":"2025-07-12T07:30:31.837878Z","iopub.status.idle":"2025-07-12T07:30:31.844568Z","shell.execute_reply.started":"2025-07-12T07:30:31.837859Z","shell.execute_reply":"2025-07-12T07:30:31.843891Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# for i in range (1,5):\n#     pca =PCA(n_components =i)\n\n    \n#     X_train_trf =pca.fit_transform(X_train)\n#     X_test_trf = pca.transform(X_test)\n\n    \n#     knn = KNeighborsClassifier()\n\n    \n#     knn.fit(X_train_trf,y_train)\n\n    \n#     y_pred =knn.predict(X_test_trf)\n\n    \n#     print(accuracy_score(y_test,y_pred))\n    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:31.845430Z","iopub.execute_input":"2025-07-12T07:30:31.845687Z","iopub.status.idle":"2025-07-12T07:30:31.861286Z","shell.execute_reply.started":"2025-07-12T07:30:31.845668Z","shell.execute_reply":"2025-07-12T07:30:31.860295Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# now visualize the data in 2D or 3D cordinate ","metadata":{}},{"cell_type":"code","source":"# our data ia in 784 dimenction and now we will convert into 2 or 3 dimenction to visualize the data ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:31.862341Z","iopub.execute_input":"2025-07-12T07:30:31.862613Z","iopub.status.idle":"2025-07-12T07:30:31.876648Z","shell.execute_reply.started":"2025-07-12T07:30:31.862593Z","shell.execute_reply":"2025-07-12T07:30:31.875822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# transforming to a 2D cordinate \npca = PCA(n_components = 2 )\nX_train_trf =pca.fit_transform(X_train)\nX_test_trf = pca.transform(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:31.877537Z","iopub.execute_input":"2025-07-12T07:30:31.877885Z","iopub.status.idle":"2025-07-12T07:30:32.647541Z","shell.execute_reply.started":"2025-07-12T07:30:31.877858Z","shell.execute_reply":"2025-07-12T07:30:32.645493Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_trf","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:32.651732Z","iopub.execute_input":"2025-07-12T07:30:32.652038Z","iopub.status.idle":"2025-07-12T07:30:32.657320Z","shell.execute_reply.started":"2025-07-12T07:30:32.652016Z","shell.execute_reply":"2025-07-12T07:30:32.656640Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import plotly.express as px\ny_train_trf = y_train.astype(str)\nfig = px.scatter(x=X_train_trf[:,0],\n                y=X_train_trf[:,1],\n                color = y_train_trf,\n                color_discrete_sequence = px.colors.qualitative.G10)\nfig.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:32.657844Z","iopub.execute_input":"2025-07-12T07:30:32.658140Z","iopub.status.idle":"2025-07-12T07:30:32.765626Z","shell.execute_reply.started":"2025-07-12T07:30:32.658119Z","shell.execute_reply":"2025-07-12T07:30:32.764465Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# transforming into 3D \npca = PCA(n_components=3)\nX_train_trf = pca.fit_transform(X_train)\nX_test_trf =pca.transform(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:32.766962Z","iopub.execute_input":"2025-07-12T07:30:32.767353Z","iopub.status.idle":"2025-07-12T07:30:33.580141Z","shell.execute_reply.started":"2025-07-12T07:30:32.767323Z","shell.execute_reply":"2025-07-12T07:30:33.577077Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_trf","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:33.580925Z","iopub.execute_input":"2025-07-12T07:30:33.583913Z","iopub.status.idle":"2025-07-12T07:30:33.590445Z","shell.execute_reply.started":"2025-07-12T07:30:33.583880Z","shell.execute_reply":"2025-07-12T07:30:33.589762Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train_trf = y_train.astype(str)\nfig = px.scatter_3d(df,x=X_train_trf[:,0],y=X_train_trf[:,1],z=X_train_trf[:,2],\n                   color=y_train_trf)\nfig.update_layout(\n    margin =dict( l=20 , r=20, t=20, b=20)\n)\nfig.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:33.591265Z","iopub.execute_input":"2025-07-12T07:30:33.592006Z","iopub.status.idle":"2025-07-12T07:30:33.712212Z","shell.execute_reply.started":"2025-07-12T07:30:33.591978Z","shell.execute_reply":"2025-07-12T07:30:33.711284Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pca.explained_variance_\n# Eigen values ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:33.713253Z","iopub.execute_input":"2025-07-12T07:30:33.713511Z","iopub.status.idle":"2025-07-12T07:30:33.719084Z","shell.execute_reply.started":"2025-07-12T07:30:33.713491Z","shell.execute_reply":"2025-07-12T07:30:33.718346Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pca.components_\n# Eigen vectors","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:33.720091Z","iopub.execute_input":"2025-07-12T07:30:33.720331Z","iopub.status.idle":"2025-07-12T07:30:33.742391Z","shell.execute_reply.started":"2025-07-12T07:30:33.720313Z","shell.execute_reply":"2025-07-12T07:30:33.741479Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# the shape of eigem vaetors \npca.components_.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:33.743434Z","iopub.execute_input":"2025-07-12T07:30:33.743769Z","iopub.status.idle":"2025-07-12T07:30:33.756099Z","shell.execute_reply.started":"2025-07-12T07:30:33.743672Z","shell.execute_reply":"2025-07-12T07:30:33.755214Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Finding the best optimum number of principal component ","metadata":{}},{"cell_type":"code","source":"pca.explained_variance_ratio_","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:30:33.757108Z","iopub.execute_input":"2025-07-12T07:30:33.757520Z","iopub.status.idle":"2025-07-12T07:30:33.771664Z","shell.execute_reply.started":"2025-07-12T07:30:33.757492Z","shell.execute_reply":"2025-07-12T07:30:33.770902Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pca = PCA(n_components=None)\nX_train_trf = pca.fit_transform(X_train)\nX_test_trf =pca.transform(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:31:55.859350Z","iopub.execute_input":"2025-07-12T07:31:55.859635Z","iopub.status.idle":"2025-07-12T07:32:00.118502Z","shell.execute_reply.started":"2025-07-12T07:31:55.859615Z","shell.execute_reply":"2025-07-12T07:32:00.117673Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pca.explained_variance_.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:33:34.194543Z","iopub.execute_input":"2025-07-12T07:33:34.195322Z","iopub.status.idle":"2025-07-12T07:33:34.200752Z","shell.execute_reply.started":"2025-07-12T07:33:34.195291Z","shell.execute_reply":"2025-07-12T07:33:34.199966Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pca.components_.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:34:29.388157Z","iopub.execute_input":"2025-07-12T07:34:29.388472Z","iopub.status.idle":"2025-07-12T07:34:29.394339Z","shell.execute_reply.started":"2025-07-12T07:34:29.388448Z","shell.execute_reply":"2025-07-12T07:34:29.393514Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pca.explained_variance_ratio_","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:35:26.067567Z","iopub.execute_input":"2025-07-12T07:35:26.067891Z","iopub.status.idle":"2025-07-12T07:35:26.080492Z","shell.execute_reply.started":"2025-07-12T07:35:26.067869Z","shell.execute_reply":"2025-07-12T07:35:26.079630Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"np.cumsum(pca.explained_variance_ratio_) # cumsum batata h ki jaise ex = 1,2,3,4,5,6, h to ye dega 1 , 1+2=3 , 1+2+3=6 ,1+2+3+4=10 ,1+2+3+4+5=15 ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:36:30.506798Z","iopub.execute_input":"2025-07-12T07:36:30.507654Z","iopub.status.idle":"2025-07-12T07:36:30.518555Z","shell.execute_reply.started":"2025-07-12T07:36:30.507619Z","shell.execute_reply":"2025-07-12T07:36:30.517889Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(np.cumsum(pca.explained_variance_ratio_))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-12T07:38:58.987743Z","iopub.execute_input":"2025-07-12T07:38:58.988894Z","iopub.status.idle":"2025-07-12T07:38:59.153217Z","shell.execute_reply.started":"2025-07-12T07:38:58.988863Z","shell.execute_reply":"2025-07-12T07:38:59.152441Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}