{"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\nBASE_FOLDER = \"/kaggle/input/prostate-cancer-grade-assessment/\"\n!ls {BASE_FOLDER}\n\ntrain = pd.read_csv(BASE_FOLDER+\"train.csv\")\ntrain.head","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt \n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:47:57.007896Z","iopub.execute_input":"2022-11-18T18:47:57.008308Z","iopub.status.idle":"2022-11-18T18:47:57.01697Z","shell.execute_reply.started":"2022-11-18T18:47:57.008274Z","shell.execute_reply":"2022-11-18T18:47:57.015704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nenc=LabelEncoder()\ntrain['image_id']=enc.fit_transform(train['image_id'])\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:47:59.26198Z","iopub.execute_input":"2022-11-18T18:47:59.26251Z","iopub.status.idle":"2022-11-18T18:47:59.311304Z","shell.execute_reply.started":"2022-11-18T18:47:59.262455Z","shell.execute_reply":"2022-11-18T18:47:59.309848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:48:00.619976Z","iopub.execute_input":"2022-11-18T18:48:00.620438Z","iopub.status.idle":"2022-11-18T18:48:00.634042Z","shell.execute_reply.started":"2022-11-18T18:48:00.620402Z","shell.execute_reply":"2022-11-18T18:48:00.632833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=train['image_id']\ny=train['isup_grade']","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:48:01.763547Z","iopub.execute_input":"2022-11-18T18:48:01.76404Z","iopub.status.idle":"2022-11-18T18:48:01.771095Z","shell.execute_reply.started":"2022-11-18T18:48:01.763995Z","shell.execute_reply":"2022-11-18T18:48:01.769631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:48:04.08041Z","iopub.execute_input":"2022-11-18T18:48:04.081915Z","iopub.status.idle":"2022-11-18T18:48:04.092471Z","shell.execute_reply.started":"2022-11-18T18:48:04.081858Z","shell.execute_reply":"2022-11-18T18:48:04.091069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:48:05.239821Z","iopub.execute_input":"2022-11-18T18:48:05.240287Z","iopub.status.idle":"2022-11-18T18:48:05.251334Z","shell.execute_reply.started":"2022-11-18T18:48:05.240254Z","shell.execute_reply":"2022-11-18T18:48:05.249762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:48:13.726429Z","iopub.execute_input":"2022-11-18T18:48:13.726958Z","iopub.status.idle":"2022-11-18T18:48:13.738949Z","shell.execute_reply.started":"2022-11-18T18:48:13.726917Z","shell.execute_reply":"2022-11-18T18:48:13.737853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import PolynomialFeatures\npol = PolynomialFeatures(degree=6)\n\nfrom sklearn.metrics import mean_absolute_error,mean_squared_error,r2_score\nfrom sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.1, random_state=0)\nfrom sklearn.linear_model import LinearRegression\nreg1 = LinearRegression()\nreg1.fit(X_train.values.reshape(-1,1),y_train)\ny_p1 = reg1.predict(X_test.values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:52:41.741762Z","iopub.execute_input":"2022-11-18T18:52:41.742221Z","iopub.status.idle":"2022-11-18T18:52:41.760713Z","shell.execute_reply.started":"2022-11-18T18:52:41.742188Z","shell.execute_reply":"2022-11-18T18:52:41.758822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_absolute_error\nprint(mean_absolute_error(y_test,y_p1))","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:52:44.873499Z","iopub.execute_input":"2022-11-18T18:52:44.873907Z","iopub.status.idle":"2022-11-18T18:52:44.880981Z","shell.execute_reply.started":"2022-11-18T18:52:44.873874Z","shell.execute_reply":"2022-11-18T18:52:44.879454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_absolute_error,mean_squared_error, r2_score\n\nprint(mean_absolute_error(y_test,y_p1))\nprint(mean_squared_error(y_test,y_p1))\nprint(r2_score(y_test,y_p1))","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:54:43.034849Z","iopub.execute_input":"2022-11-18T18:54:43.03534Z","iopub.status.idle":"2022-11-18T18:54:43.046688Z","shell.execute_reply.started":"2022-11-18T18:54:43.035302Z","shell.execute_reply":"2022-11-18T18:54:43.044992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_p1","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:55:38.756818Z","iopub.execute_input":"2022-11-18T18:55:38.75731Z","iopub.status.idle":"2022-11-18T18:55:38.766609Z","shell.execute_reply.started":"2022-11-18T18:55:38.757274Z","shell.execute_reply":"2022-11-18T18:55:38.765224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:55:51.550688Z","iopub.execute_input":"2022-11-18T18:55:51.551197Z","iopub.status.idle":"2022-11-18T18:55:51.561601Z","shell.execute_reply.started":"2022-11-18T18:55:51.551157Z","shell.execute_reply":"2022-11-18T18:55:51.560359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:56:27.81893Z","iopub.execute_input":"2022-11-18T18:56:27.819436Z","iopub.status.idle":"2022-11-18T18:56:27.830026Z","shell.execute_reply.started":"2022-11-18T18:56:27.819395Z","shell.execute_reply":"2022-11-18T18:56:27.828636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, confusion_matrix, classification_report\n\nres=confusion_matrix(y_train,predictions)\nprint(\"Training confusion matrix\")\nprint(res)\npredictions= svc_s_model.predict(X_test)\npercentage=svc_s_model.score(X_test,y_test)\nres=confusion_matrix(y_test,predictions)\nprint(\"validation confusion matrix\")\nprint(res)\nprint(classification_report(y_test, predictions))\n# check the accuracy on the training set\nprint('training accuracy = '+str(svc_s_model.score(X_train, y_train)*100))\nprint('testing accuracy = '+str(svc_s_model.score(X_test, y_test)*100))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"regressor.fit(x_train.values.reshape(-1,1),y_train)\ny_pred = regressor.predict(x_test.values.reshape(-1,1))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" X_train.reshape(1, -1)\n X_test.reshape(1, -1)\nfrom sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.1, random_state=0)","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:23:11.545299Z","iopub.execute_input":"2022-11-18T18:23:11.545794Z","iopub.status.idle":"2022-11-18T18:23:11.571054Z","shell.execute_reply.started":"2022-11-18T18:23:11.545748Z","shell.execute_reply":"2022-11-18T18:23:11.568849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nfrom sklearn.linear_model import LinearRegression\nreg1 = LinearRegression()\nreg1.fit(X_train,y_train)\ny_p1 = reg1.predict(X_test)\nfrom sklearn.metrics import mean_absolute_error\nprint(mean_absolute_error(y_test,y_p1))\n\n\nreg2 = LinearRegression()\nreg2.fit(X_train1,y_train1)\ny_pred2= reg2.predict(X_test1)\n\nprint(mean_absolute_error(y_test1,y_pred2))","metadata":{"execution":{"iopub.status.busy":"2022-11-18T18:21:54.703317Z","iopub.execute_input":"2022-11-18T18:21:54.703734Z","iopub.status.idle":"2022-11-18T18:21:54.733368Z","shell.execute_reply.started":"2022-11-18T18:21:54.703694Z","shell.execute_reply":"2022-11-18T18:21:54.731906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfrom sklearn.linear_model import LinearRegression\nreg = LinearRegression()\nreg.fit(X_train,y_train)\ny_pred = reg.predict(X_test)\ny_prd2 = reg.predict(X_train)\nprint(y_prd2)\nprint(y_train)\nprint(y_test)\nprint(y_pred)","metadata":{"execution":{"iopub.status.busy":"2022-11-18T17:59:48.708834Z","iopub.execute_input":"2022-11-18T17:59:48.709297Z","iopub.status.idle":"2022-11-18T17:59:48.824146Z","shell.execute_reply.started":"2022-11-18T17:59:48.709261Z","shell.execute_reply":"2022-11-18T17:59:48.822316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X\n","metadata":{"execution":{"iopub.status.busy":"2022-11-18T17:56:24.520897Z","iopub.execute_input":"2022-11-18T17:56:24.521422Z","iopub.status.idle":"2022-11-18T17:56:24.532546Z","shell.execute_reply.started":"2022-11-18T17:56:24.521381Z","shell.execute_reply":"2022-11-18T17:56:24.531129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T01:50:19.830769Z","iopub.execute_input":"2022-11-18T01:50:19.831119Z","iopub.status.idle":"2022-11-18T01:50:19.843251Z","shell.execute_reply.started":"2022-11-18T01:50:19.831089Z","shell.execute_reply":"2022-11-18T01:50:19.841905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=train.drop_duplicates()\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T01:50:21.027418Z","iopub.execute_input":"2022-11-18T01:50:21.027787Z","iopub.status.idle":"2022-11-18T01:50:21.046003Z","shell.execute_reply.started":"2022-11-18T01:50:21.027757Z","shell.execute_reply":"2022-11-18T01:50:21.045259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nenc=LabelEncoder()\ntrain['image_id']=enc.fit_transform(train['image_id'])\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T01:50:22.144888Z","iopub.execute_input":"2022-11-18T01:50:22.145248Z","iopub.status.idle":"2022-11-18T01:50:22.181916Z","shell.execute_reply.started":"2022-11-18T01:50:22.145216Z","shell.execute_reply":"2022-11-18T01:50:22.180859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T01:50:23.867351Z","iopub.execute_input":"2022-11-18T01:50:23.867785Z","iopub.status.idle":"2022-11-18T01:50:23.879005Z","shell.execute_reply.started":"2022-11-18T01:50:23.867749Z","shell.execute_reply":"2022-11-18T01:50:23.877742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X","metadata":{"execution":{"iopub.status.busy":"2022-11-18T01:50:35.374453Z","iopub.execute_input":"2022-11-18T01:50:35.374841Z","iopub.status.idle":"2022-11-18T01:50:35.381938Z","shell.execute_reply.started":"2022-11-18T01:50:35.374811Z","shell.execute_reply":"2022-11-18T01:50:35.381015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y","metadata":{"execution":{"iopub.status.busy":"2022-11-18T01:39:51.264237Z","iopub.execute_input":"2022-11-18T01:39:51.264584Z","iopub.status.idle":"2022-11-18T01:39:51.272061Z","shell.execute_reply.started":"2022-11-18T01:39:51.264554Z","shell.execute_reply":"2022-11-18T01:39:51.271205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T01:39:56.637284Z","iopub.execute_input":"2022-11-18T01:39:56.637634Z","iopub.status.idle":"2022-11-18T01:39:56.65016Z","shell.execute_reply.started":"2022-11-18T01:39:56.637604Z","shell.execute_reply":"2022-11-18T01:39:56.64904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.compose import ColumnTransformer\nfrom sklearn.preprocessing import OneHotEncoder\nct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1]    )], remainder='passthrough')\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-18T01:40:27.718485Z","iopub.execute_input":"2022-11-18T01:40:27.718867Z","iopub.status.idle":"2022-11-18T01:40:27.731425Z","shell.execute_reply.started":"2022-11-18T01:40:27.718834Z","shell.execute_reply":"2022-11-18T01:40:27.730034Z"},"trusted":true},"execution_count":null,"outputs":[]}]}