{"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":"code","source":"import numpy as np\nimport pandas as pd \nfrom matplotlib import pyplot as plt\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.model_selection import train_test_split","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-07-02T03:00:10.438716Z","iopub.execute_input":"2021-07-02T03:00:10.439082Z","iopub.status.idle":"2021-07-02T03:00:11.504276Z","shell.execute_reply.started":"2021-07-02T03:00:10.439046Z","shell.execute_reply":"2021-07-02T03:00:11.503585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_csv('../input/Kannada-MNIST/train.csv')\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:11.505900Z","iopub.execute_input":"2021-07-02T03:00:11.506565Z","iopub.status.idle":"2021-07-02T03:00:16.513612Z","shell.execute_reply.started":"2021-07-02T03:00:11.506524Z","shell.execute_reply":"2021-07-02T03:00:16.512603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range (6):\n    a=data.iloc[i,1:].values\n    a=a.reshape(28,28).astype('uint8')\n    fig = plt.figure(figsize=(5, 3))\n    plt.imshow(a)","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:16.515523Z","iopub.execute_input":"2021-07-02T03:00:16.516102Z","iopub.status.idle":"2021-07-02T03:00:17.274189Z","shell.execute_reply.started":"2021-07-02T03:00:16.516060Z","shell.execute_reply":"2021-07-02T03:00:17.273096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_x=data.iloc[:,1:]\ndf_y=data.iloc[:,0]","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:17.275697Z","iopub.execute_input":"2021-07-02T03:00:17.275980Z","iopub.status.idle":"2021-07-02T03:00:17.280869Z","shell.execute_reply.started":"2021-07-02T03:00:17.275940Z","shell.execute_reply":"2021-07-02T03:00:17.280009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train, x_test, y_train, y_test = train_test_split(df_x, df_y, test_size=0.2, random_state=4)","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:17.282154Z","iopub.execute_input":"2021-07-02T03:00:17.282436Z","iopub.status.idle":"2021-07-02T03:00:17.666446Z","shell.execute_reply.started":"2021-07-02T03:00:17.282408Z","shell.execute_reply":"2021-07-02T03:00:17.665669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:17.667571Z","iopub.execute_input":"2021-07-02T03:00:17.668035Z","iopub.status.idle":"2021-07-02T03:00:17.685858Z","shell.execute_reply.started":"2021-07-02T03:00:17.667991Z","shell.execute_reply":"2021-07-02T03:00:17.685163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:17.686902Z","iopub.execute_input":"2021-07-02T03:00:17.687375Z","iopub.status.idle":"2021-07-02T03:00:17.699414Z","shell.execute_reply.started":"2021-07-02T03:00:17.687332Z","shell.execute_reply":"2021-07-02T03:00:17.698524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf=RandomForestClassifier(n_estimators=100)\nrf.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:17.701937Z","iopub.execute_input":"2021-07-02T03:00:17.702272Z","iopub.status.idle":"2021-07-02T03:00:44.542999Z","shell.execute_reply.started":"2021-07-02T03:00:17.702243Z","shell.execute_reply":"2021-07-02T03:00:44.542153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=rf.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:44.544842Z","iopub.execute_input":"2021-07-02T03:00:44.545137Z","iopub.status.idle":"2021-07-02T03:00:44.920428Z","shell.execute_reply.started":"2021-07-02T03:00:44.545110Z","shell.execute_reply":"2021-07-02T03:00:44.919452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred[0:5]","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:44.921646Z","iopub.execute_input":"2021-07-02T03:00:44.921913Z","iopub.status.idle":"2021-07-02T03:00:44.927691Z","shell.execute_reply.started":"2021-07-02T03:00:44.921887Z","shell.execute_reply":"2021-07-02T03:00:44.926753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test[0:5]","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:44.928751Z","iopub.execute_input":"2021-07-02T03:00:44.929045Z","iopub.status.idle":"2021-07-02T03:00:44.940355Z","shell.execute_reply.started":"2021-07-02T03:00:44.929014Z","shell.execute_reply":"2021-07-02T03:00:44.939753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s=y_test.values\ncount=0","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:44.941342Z","iopub.execute_input":"2021-07-02T03:00:44.941824Z","iopub.status.idle":"2021-07-02T03:00:44.950447Z","shell.execute_reply.started":"2021-07-02T03:00:44.941795Z","shell.execute_reply":"2021-07-02T03:00:44.949677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(len(pred)):\n    if pred[i]==s[i]:\n        count=count+1","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:44.951339Z","iopub.execute_input":"2021-07-02T03:00:44.951596Z","iopub.status.idle":"2021-07-02T03:00:44.970871Z","shell.execute_reply.started":"2021-07-02T03:00:44.951562Z","shell.execute_reply":"2021-07-02T03:00:44.970052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:44.971867Z","iopub.execute_input":"2021-07-02T03:00:44.972152Z","iopub.status.idle":"2021-07-02T03:00:44.983528Z","shell.execute_reply.started":"2021-07-02T03:00:44.972126Z","shell.execute_reply":"2021-07-02T03:00:44.982777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(pred)","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:44.984521Z","iopub.execute_input":"2021-07-02T03:00:44.984785Z","iopub.status.idle":"2021-07-02T03:00:44.996221Z","shell.execute_reply.started":"2021-07-02T03:00:44.984760Z","shell.execute_reply":"2021-07-02T03:00:44.995029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"11760/12000","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:44.997792Z","iopub.execute_input":"2021-07-02T03:00:44.998403Z","iopub.status.idle":"2021-07-02T03:00:45.006626Z","shell.execute_reply.started":"2021-07-02T03:00:44.998211Z","shell.execute_reply":"2021-07-02T03:00:45.005707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score,confusion_matrix,classification_report\n","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:45.008101Z","iopub.execute_input":"2021-07-02T03:00:45.008692Z","iopub.status.idle":"2021-07-02T03:00:45.015432Z","shell.execute_reply.started":"2021-07-02T03:00:45.008653Z","shell.execute_reply":"2021-07-02T03:00:45.014516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,pred)","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:45.016790Z","iopub.execute_input":"2021-07-02T03:00:45.017337Z","iopub.status.idle":"2021-07-02T03:00:45.029731Z","shell.execute_reply.started":"2021-07-02T03:00:45.017298Z","shell.execute_reply":"2021-07-02T03:00:45.028743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"confusion_matrix(y_test,pred)","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:45.030792Z","iopub.execute_input":"2021-07-02T03:00:45.031310Z","iopub.status.idle":"2021-07-02T03:00:45.058727Z","shell.execute_reply.started":"2021-07-02T03:00:45.031258Z","shell.execute_reply":"2021-07-02T03:00:45.057990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(y_test,pred))","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:45.060010Z","iopub.execute_input":"2021-07-02T03:00:45.060546Z","iopub.status.idle":"2021-07-02T03:00:45.093482Z","shell.execute_reply.started":"2021-07-02T03:00:45.060501Z","shell.execute_reply":"2021-07-02T03:00:45.092775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('../input/Kannada-MNIST/test.csv')\ndf1=df.iloc[500:510,1:]\ndf1.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:03:31.176134Z","iopub.execute_input":"2021-07-02T03:03:31.176488Z","iopub.status.idle":"2021-07-02T03:03:31.533224Z","shell.execute_reply.started":"2021-07-02T03:03:31.176459Z","shell.execute_reply":"2021-07-02T03:03:31.532596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:00:45.554454Z","iopub.execute_input":"2021-07-02T03:00:45.555157Z","iopub.status.idle":"2021-07-02T03:00:45.561229Z","shell.execute_reply.started":"2021-07-02T03:00:45.555085Z","shell.execute_reply":"2021-07-02T03:00:45.560396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf.predict(df1)","metadata":{"execution":{"iopub.status.busy":"2021-07-02T03:03:48.772273Z","iopub.execute_input":"2021-07-02T03:03:48.772789Z","iopub.status.idle":"2021-07-02T03:03:48.796655Z","shell.execute_reply.started":"2021-07-02T03:03:48.772759Z","shell.execute_reply":"2021-07-02T03:03:48.795392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}