{"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\nimport seaborn as sns\n\nfrom sklearn.model_selection import *\nfrom sklearn.linear_model import *\nfrom sklearn.metrics import *\nfrom sklearn.preprocessing import *\nfrom sklearn.tree import *\nfrom xgboost import XGBClassifier\nfrom sklearn.ensemble import *\nfrom imblearn.under_sampling import *\nfrom imblearn.over_sampling import *","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:07:37.623724Z","iopub.execute_input":"2023-10-06T12:07:37.624436Z","iopub.status.idle":"2023-10-06T12:07:37.785851Z","shell.execute_reply.started":"2023-10-06T12:07:37.624399Z","shell.execute_reply":"2023-10-06T12:07:37.784937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/datareg_linear_100.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-25T14:24:26.839287Z","iopub.execute_input":"2023-09-25T14:24:26.839771Z","iopub.status.idle":"2023-09-25T14:24:26.869998Z","shell.execute_reply.started":"2023-09-25T14:24:26.839737Z","shell.execute_reply":"2023-09-25T14:24:26.868656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-25T14:24:37.406726Z","iopub.execute_input":"2023-09-25T14:24:37.407119Z","iopub.status.idle":"2023-09-25T14:24:37.426526Z","shell.execute_reply.started":"2023-09-25T14:24:37.407088Z","shell.execute_reply":"2023-09-25T14:24:37.425105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.x\n","metadata":{"execution":{"iopub.status.busy":"2023-09-25T14:25:50.864731Z","iopub.execute_input":"2023-09-25T14:25:50.865236Z","iopub.status.idle":"2023-09-25T14:25:50.876189Z","shell.execute_reply.started":"2023-09-25T14:25:50.865206Z","shell.execute_reply":"2023-09-25T14:25:50.874862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(df.x,df.y)","metadata":{"execution":{"iopub.status.busy":"2023-09-25T14:26:28.118608Z","iopub.execute_input":"2023-09-25T14:26:28.118996Z","iopub.status.idle":"2023-09-25T14:26:28.455814Z","shell.execute_reply.started":"2023-09-25T14:26:28.118968Z","shell.execute_reply":"2023-09-25T14:26:28.454577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = df.x\ny = df.y","metadata":{"execution":{"iopub.status.busy":"2023-09-25T14:38:16.442957Z","iopub.execute_input":"2023-09-25T14:38:16.443387Z","iopub.status.idle":"2023-09-25T14:38:16.450320Z","shell.execute_reply.started":"2023-09-25T14:38:16.443355Z","shell.execute_reply":"2023-09-25T14:38:16.448719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = np.cov(x,y)[0,1]/np.var(x)","metadata":{"execution":{"iopub.status.busy":"2023-09-25T14:39:40.612656Z","iopub.execute_input":"2023-09-25T14:39:40.613015Z","iopub.status.idle":"2023-09-25T14:39:40.620817Z","shell.execute_reply.started":"2023-09-25T14:39:40.612987Z","shell.execute_reply":"2023-09-25T14:39:40.618814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"b = np.mean(y) - a*np.mean(x)","metadata":{"execution":{"iopub.status.busy":"2023-09-25T14:40:05.560108Z","iopub.execute_input":"2023-09-25T14:40:05.560894Z","iopub.status.idle":"2023-09-25T14:40:05.567215Z","shell.execute_reply.started":"2023-09-25T14:40:05.560847Z","shell.execute_reply":"2023-09-25T14:40:05.566378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(x,y)\nplt.plot(x, a*x+b,c = 'red')","metadata":{"execution":{"iopub.status.busy":"2023-09-25T14:41:09.254381Z","iopub.execute_input":"2023-09-25T14:41:09.254765Z","iopub.status.idle":"2023-09-25T14:41:09.553966Z","shell.execute_reply.started":"2023-09-25T14:41:09.254736Z","shell.execute_reply":"2023-09-25T14:41:09.552675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class RegressionLineaire :\n    \n    def __init__(self):\n        self.a = np.random.uniform(0,1)\n        self.b = np.random.uniform(0,1)\n        self.history = []\n    \n    def fit(self,x,y, learning_rate = 0.1,epochs = 600):\n        n = len(y)\n        for i in range(epochs):\n            u = self.predict(x)\n            grad_a = np.sum((u-y)*x)/n\n            grad_b = np.sum((u-y))/n\n            self.a = self.a - grad_a*learning_rate\n            self.b = self.b - grad_b*learning_rate\n            self.history.append(self.mse(y,y_hat))\n        \n    def mse (self,y,y_hat):\n        np.sum((y-y_hat)**2)/len(y)\n        \n    def predict(self,x):\n        return self.a*x + self.b","metadata":{"execution":{"iopub.status.busy":"2023-09-25T15:09:20.338716Z","iopub.execute_input":"2023-09-25T15:09:20.339124Z","iopub.status.idle":"2023-09-25T15:09:20.350361Z","shell.execute_reply.started":"2023-09-25T15:09:20.339095Z","shell.execute_reply":"2023-09-25T15:09:20.348772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = RegressionLineaire()\nmodel.fit(x,y)\ny_hat = model.predict(x)","metadata":{"execution":{"iopub.status.busy":"2023-09-25T15:07:23.780908Z","iopub.execute_input":"2023-09-25T15:07:23.781931Z","iopub.status.idle":"2023-09-25T15:07:24.286362Z","shell.execute_reply.started":"2023-09-25T15:07:23.781897Z","shell.execute_reply":"2023-09-25T15:07:24.285242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(x,y_hat, c='red')\nplt.scatter(x,y)","metadata":{"execution":{"iopub.status.busy":"2023-09-25T15:07:24.557774Z","iopub.execute_input":"2023-09-25T15:07:24.558184Z","iopub.status.idle":"2023-09-25T15:07:24.869984Z","shell.execute_reply.started":"2023-09-25T15:07:24.558153Z","shell.execute_reply":"2023-09-25T15:07:24.868835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/housing.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-25T15:21:34.020220Z","iopub.execute_input":"2023-09-25T15:21:34.020720Z","iopub.status.idle":"2023-09-25T15:21:34.042604Z","shell.execute_reply.started":"2023-09-25T15:21:34.020684Z","shell.execute_reply":"2023-09-25T15:21:34.041534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-25T15:21:41.335444Z","iopub.execute_input":"2023-09-25T15:21:41.336168Z","iopub.status.idle":"2023-09-25T15:21:41.352316Z","shell.execute_reply.started":"2023-09-25T15:21:41.336121Z","shell.execute_reply":"2023-09-25T15:21:41.350848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df.MEDV\nX = df[['RM','LSTAT','PTRATIO']]","metadata":{"execution":{"iopub.status.busy":"2023-09-25T15:24:23.781968Z","iopub.execute_input":"2023-09-25T15:24:23.782456Z","iopub.status.idle":"2023-09-25T15:24:23.796521Z","shell.execute_reply.started":"2023-09-25T15:24:23.782394Z","shell.execute_reply":"2023-09-25T15:24:23.795053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\n\nmodel = LinearRegression()\nmodel.fit(X,y)\ny_hat = model.predict(X)","metadata":{"execution":{"iopub.status.busy":"2023-09-25T15:25:10.433194Z","iopub.execute_input":"2023-09-25T15:25:10.433619Z","iopub.status.idle":"2023-09-25T15:25:11.215511Z","shell.execute_reply.started":"2023-09-25T15:25:10.433586Z","shell.execute_reply":"2023-09-25T15:25:11.214254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import *","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:56:52.685014Z","iopub.execute_input":"2023-09-28T08:56:52.685431Z","iopub.status.idle":"2023-09-28T08:56:52.691159Z","shell.execute_reply.started":"2023-09-28T08:56:52.685400Z","shell.execute_reply":"2023-09-28T08:56:52.690015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/datareg_cos_1000.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:32:35.089583Z","iopub.execute_input":"2023-09-26T06:32:35.089957Z","iopub.status.idle":"2023-09-26T06:32:35.116709Z","shell.execute_reply.started":"2023-09-26T06:32:35.089927Z","shell.execute_reply":"2023-09-26T06:32:35.115794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:32:38.710115Z","iopub.execute_input":"2023-09-26T06:32:38.710941Z","iopub.status.idle":"2023-09-26T06:32:38.721846Z","shell.execute_reply.started":"2023-09-26T06:32:38.710891Z","shell.execute_reply":"2023-09-26T06:32:38.720821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = df.x\ny = df.y\nplt.scatter(x,y)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:32:39.119839Z","iopub.execute_input":"2023-09-26T06:32:39.120225Z","iopub.status.idle":"2023-09-26T06:32:39.421039Z","shell.execute_reply.started":"2023-09-26T06:32:39.120196Z","shell.execute_reply":"2023-09-26T06:32:39.419935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['x2'] = x*x\ndf['x3'] = x*x*x","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:35:20.189647Z","iopub.execute_input":"2023-09-26T06:35:20.190038Z","iopub.status.idle":"2023-09-26T06:35:20.197107Z","shell.execute_reply.started":"2023-09-26T06:35:20.190008Z","shell.execute_reply":"2023-09-26T06:35:20.195836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:35:21.378540Z","iopub.execute_input":"2023-09-26T06:35:21.379462Z","iopub.status.idle":"2023-09-26T06:35:21.390638Z","shell.execute_reply.started":"2023-09-26T06:35:21.379427Z","shell.execute_reply":"2023-09-26T06:35:21.389491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df[['x','x2','x3']]","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:35:24.608824Z","iopub.execute_input":"2023-09-26T06:35:24.609237Z","iopub.status.idle":"2023-09-26T06:35:24.617446Z","shell.execute_reply.started":"2023-09-26T06:35:24.609206Z","shell.execute_reply":"2023-09-26T06:35:24.616336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = LinearRegression()\nmodel.fit(X,y)\ny_hat = model.predict(X)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:35:26.488533Z","iopub.execute_input":"2023-09-26T06:35:26.489452Z","iopub.status.idle":"2023-09-26T06:35:26.517825Z","shell.execute_reply.started":"2023-09-26T06:35:26.489416Z","shell.execute_reply":"2023-09-26T06:35:26.516823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(x,y)\nplt.scatter(X,y_hat, c = 'red')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:37:52.039610Z","iopub.execute_input":"2023-09-26T06:37:52.040031Z","iopub.status.idle":"2023-09-26T06:37:52.384831Z","shell.execute_reply.started":"2023-09-26T06:37:52.039998Z","shell.execute_reply":"2023-09-26T06:37:52.382182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/iris_basic.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:40:29.016851Z","iopub.execute_input":"2023-09-26T06:40:29.017248Z","iopub.status.idle":"2023-09-26T06:40:29.026271Z","shell.execute_reply.started":"2023-09-26T06:40:29.017215Z","shell.execute_reply":"2023-09-26T06:40:29.024996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head\ndf.shape\n","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:00:21.185105Z","iopub.execute_input":"2023-09-26T08:00:21.185484Z","iopub.status.idle":"2023-09-26T08:00:21.192568Z","shell.execute_reply.started":"2023-09-26T08:00:21.185455Z","shell.execute_reply":"2023-09-26T08:00:21.191451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:00:24.892632Z","iopub.execute_input":"2023-09-26T08:00:24.893030Z","iopub.status.idle":"2023-09-26T08:00:24.900817Z","shell.execute_reply.started":"2023-09-26T08:00:24.893001Z","shell.execute_reply":"2023-09-26T08:00:24.899768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:00:40.374949Z","iopub.execute_input":"2023-09-26T08:00:40.375326Z","iopub.status.idle":"2023-09-26T08:00:40.428282Z","shell.execute_reply.started":"2023-09-26T08:00:40.375296Z","shell.execute_reply":"2023-09-26T08:00:40.427290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['species'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:45:18.979997Z","iopub.execute_input":"2023-09-26T06:45:18.980400Z","iopub.status.idle":"2023-09-26T06:45:18.991873Z","shell.execute_reply.started":"2023-09-26T06:45:18.980366Z","shell.execute_reply":"2023-09-26T06:45:18.990779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[['petal_length','petal_width']].loc[5]","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:46:51.719305Z","iopub.execute_input":"2023-09-26T06:46:51.720173Z","iopub.status.idle":"2023-09-26T06:46:51.729491Z","shell.execute_reply.started":"2023-09-26T06:46:51.720130Z","shell.execute_reply":"2023-09-26T06:46:51.728751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:49:13.338723Z","iopub.execute_input":"2023-09-26T06:49:13.339125Z","iopub.status.idle":"2023-09-26T06:49:13.355348Z","shell.execute_reply.started":"2023-09-26T06:49:13.339094Z","shell.execute_reply":"2023-09-26T06:49:13.354247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"    df.sample(n=32)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:49:51.129020Z","iopub.execute_input":"2023-09-26T06:49:51.129381Z","iopub.status.idle":"2023-09-26T06:49:51.149016Z","shell.execute_reply.started":"2023-09-26T06:49:51.129352Z","shell.execute_reply":"2023-09-26T06:49:51.147846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop([2,3])\ndf.drop(['species'],axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:52:21.220220Z","iopub.execute_input":"2023-09-26T06:52:21.220648Z","iopub.status.idle":"2023-09-26T06:52:21.237959Z","shell.execute_reply.started":"2023-09-26T06:52:21.220590Z","shell.execute_reply":"2023-09-26T06:52:21.237176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(data = df, x = 'species', y = 'petal_length')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:54:56.289465Z","iopub.execute_input":"2023-09-26T06:54:56.290559Z","iopub.status.idle":"2023-09-26T06:54:56.510252Z","shell.execute_reply.started":"2023-09-26T06:54:56.290504Z","shell.execute_reply":"2023-09-26T06:54:56.509133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data = df, x = 'petal_length', hue = 'species')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T06:58:33.868766Z","iopub.execute_input":"2023-09-26T06:58:33.869572Z","iopub.status.idle":"2023-09-26T06:58:34.310987Z","shell.execute_reply.started":"2023-09-26T06:58:33.869531Z","shell.execute_reply":"2023-09-26T06:58:34.309806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(data = df, x = 'petal_length',y = 'petal_width', hue = 'species')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T07:06:34.769403Z","iopub.execute_input":"2023-09-26T07:06:34.769854Z","iopub.status.idle":"2023-09-26T07:06:35.379137Z","shell.execute_reply.started":"2023-09-26T07:06:34.769821Z","shell.execute_reply":"2023-09-26T07:06:35.377879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.pairplot(data = df, hue = 'species')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T07:07:14.414999Z","iopub.execute_input":"2023-09-26T07:07:14.415374Z","iopub.status.idle":"2023-09-26T07:07:16.375619Z","shell.execute_reply.started":"2023-09-26T07:07:14.415345Z","shell.execute_reply":"2023-09-26T07:07:16.374511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['species']\nX = df.drop(['species'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T07:44:53.975296Z","iopub.execute_input":"2023-09-26T07:44:53.975798Z","iopub.status.idle":"2023-09-26T07:44:53.983069Z","shell.execute_reply.started":"2023-09-26T07:44:53.975758Z","shell.execute_reply":"2023-09-26T07:44:53.981562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = ","metadata":{"execution":{"iopub.status.busy":"2023-09-26T07:45:51.704448Z","iopub.execute_input":"2023-09-26T07:45:51.704893Z","iopub.status.idle":"2023-09-26T07:45:51.723290Z","shell.execute_reply.started":"2023-09-26T07:45:51.704858Z","shell.execute_reply":"2023-09-26T07:45:51.722058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/heart.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:28:33.294277Z","iopub.execute_input":"2023-09-26T08:28:33.294658Z","iopub.status.idle":"2023-09-26T08:28:33.304596Z","shell.execute_reply.started":"2023-09-26T08:28:33.294627Z","shell.execute_reply":"2023-09-26T08:28:33.303383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['output']\nX = df.drop(['output'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:31:06.585856Z","iopub.execute_input":"2023-09-26T08:31:06.586227Z","iopub.status.idle":"2023-09-26T08:31:06.592466Z","shell.execute_reply.started":"2023-09-26T08:31:06.586199Z","shell.execute_reply":"2023-09-26T08:31:06.591250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = LogisticRegression()\nmodel.fit(X,y)\ny_hat = model.predict(X)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:32:11.334311Z","iopub.execute_input":"2023-09-26T08:32:11.334695Z","iopub.status.idle":"2023-09-26T08:32:11.368675Z","shell.execute_reply.started":"2023-09-26T08:32:11.334664Z","shell.execute_reply":"2023-09-26T08:32:11.367448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()\n","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:32:07.884989Z","iopub.execute_input":"2023-09-26T08:32:07.885373Z","iopub.status.idle":"2023-09-26T08:32:07.937663Z","shell.execute_reply.started":"2023-09-26T08:32:07.885341Z","shell.execute_reply":"2023-09-26T08:32:07.936553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_hat","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:31:41.145411Z","iopub.execute_input":"2023-09-26T08:31:41.146324Z","iopub.status.idle":"2023-09-26T08:31:41.154312Z","shell.execute_reply.started":"2023-09-26T08:31:41.146286Z","shell.execute_reply":"2023-09-26T08:31:41.153330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler  = StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2023-09-26T08:38:38.334136Z","iopub.execute_input":"2023-09-26T08:38:38.334530Z","iopub.status.idle":"2023-09-26T08:38:38.342208Z","shell.execute_reply.started":"2023-09-26T08:38:38.334488Z","shell.execute_reply":"2023-09-26T08:38:38.340800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = DecisionTreeClassifier()\nmodel.fit(X_train,y_train)\ny_hat = model.predict(X_test)\naccuracy_score(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:05:26.332412Z","iopub.execute_input":"2023-09-26T09:05:26.333648Z","iopub.status.idle":"2023-09-26T09:05:26.348619Z","shell.execute_reply.started":"2023-09-26T09:05:26.333611Z","shell.execute_reply":"2023-09-26T09:05:26.347543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:04:59.946689Z","iopub.execute_input":"2023-09-26T09:04:59.947207Z","iopub.status.idle":"2023-09-26T09:04:59.954100Z","shell.execute_reply.started":"2023-09-26T09:04:59.947173Z","shell.execute_reply":"2023-09-26T09:04:59.952936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cross_val_score(model, X, y, cv = 100, scoring = 'accuracy').mean()","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:11:16.904492Z","iopub.execute_input":"2023-09-26T09:11:16.904884Z","iopub.status.idle":"2023-09-26T09:11:17.496756Z","shell.execute_reply.started":"2023-09-26T09:11:16.904855Z","shell.execute_reply":"2023-09-26T09:11:17.495770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.crosstab(y_test,y_hat)\nprint(classification_report(y_test,y_hat))","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:15:11.577119Z","iopub.execute_input":"2023-09-26T09:15:11.577563Z","iopub.status.idle":"2023-09-26T09:15:11.599571Z","shell.execute_reply.started":"2023-09-26T09:15:11.577528Z","shell.execute_reply":"2023-09-26T09:15:11.598468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/cancer.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:29:53.965213Z","iopub.execute_input":"2023-09-26T09:29:53.965604Z","iopub.status.idle":"2023-09-26T09:29:53.998196Z","shell.execute_reply.started":"2023-09-26T09:29:53.965573Z","shell.execute_reply":"2023-09-26T09:29:53.997114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:30:00.735667Z","iopub.execute_input":"2023-09-26T09:30:00.736089Z","iopub.status.idle":"2023-09-26T09:30:00.770628Z","shell.execute_reply.started":"2023-09-26T09:30:00.736057Z","shell.execute_reply":"2023-09-26T09:30:00.769459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/penguins.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:49:42.513010Z","iopub.execute_input":"2023-09-26T09:49:42.513587Z","iopub.status.idle":"2023-09-26T09:49:42.538399Z","shell.execute_reply.started":"2023-09-26T09:49:42.513553Z","shell.execute_reply":"2023-09-26T09:49:42.537190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:44:12.625986Z","iopub.execute_input":"2023-09-26T09:44:12.626337Z","iopub.status.idle":"2023-09-26T09:44:12.642751Z","shell.execute_reply.started":"2023-09-26T09:44:12.626309Z","shell.execute_reply":"2023-09-26T09:44:12.641649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.pairplot(df, hue = 'species')","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:49:47.422483Z","iopub.execute_input":"2023-09-26T09:49:47.422938Z","iopub.status.idle":"2023-09-26T09:49:55.770241Z","shell.execute_reply.started":"2023-09-26T09:49:47.422900Z","shell.execute_reply":"2023-09-26T09:49:55.768931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sex'] = df['sex'].map({'male':0,'female':1})","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:49:55.772462Z","iopub.execute_input":"2023-09-26T09:49:55.772878Z","iopub.status.idle":"2023-09-26T09:49:55.781617Z","shell.execute_reply.started":"2023-09-26T09:49:55.772838Z","shell.execute_reply":"2023-09-26T09:49:55.780191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.get_dummies(df, columns = ['species','island'],dtype = 'int')\n","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:53:40.162625Z","iopub.execute_input":"2023-09-26T09:53:40.163456Z","iopub.status.idle":"2023-09-26T09:53:40.174761Z","shell.execute_reply.started":"2023-09-26T09:53:40.163415Z","shell.execute_reply":"2023-09-26T09:53:40.173747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:53:45.012943Z","iopub.execute_input":"2023-09-26T09:53:45.013374Z","iopub.status.idle":"2023-09-26T09:53:45.039984Z","shell.execute_reply.started":"2023-09-26T09:53:45.013329Z","shell.execute_reply":"2023-09-26T09:53:45.038933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['sex']\nX = df.drop(['sex'],axis = 1)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:55:25.093546Z","iopub.execute_input":"2023-09-26T09:55:25.093974Z","iopub.status.idle":"2023-09-26T09:55:25.101682Z","shell.execute_reply.started":"2023-09-26T09:55:25.093942Z","shell.execute_reply":"2023-09-26T09:55:25.100313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = DecisionTreeClassifier()\nmodel.fit(X,y)\ny_hat = model.predict(X)\naccuracy_score(y,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:55:55.713853Z","iopub.execute_input":"2023-09-26T09:55:55.714304Z","iopub.status.idle":"2023-09-26T09:55:56.429584Z","shell.execute_reply.started":"2023-09-26T09:55:55.714270Z","shell.execute_reply":"2023-09-26T09:55:56.427806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import *\ndf = df.dropna()\nmodel2 = RandomForestClassifier()\ncross_val_score(model2,X,y)","metadata":{"execution":{"iopub.status.busy":"2023-09-26T09:57:53.954675Z","iopub.execute_input":"2023-09-26T09:57:53.955881Z","iopub.status.idle":"2023-09-26T09:57:54.094682Z","shell.execute_reply.started":"2023-09-26T09:57:53.955817Z","shell.execute_reply":"2023-09-26T09:57:54.093072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/titanic.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:48:00.868421Z","iopub.execute_input":"2023-09-28T06:48:00.868783Z","iopub.status.idle":"2023-09-28T06:48:00.886728Z","shell.execute_reply.started":"2023-09-28T06:48:00.868755Z","shell.execute_reply":"2023-09-28T06:48:00.885686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:13:31.306083Z","iopub.execute_input":"2023-09-28T06:13:31.307586Z","iopub.status.idle":"2023-09-28T06:13:31.334503Z","shell.execute_reply.started":"2023-09-28T06:13:31.307532Z","shell.execute_reply":"2023-09-28T06:13:31.333253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.count()\n","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:15:59.016100Z","iopub.execute_input":"2023-09-28T06:15:59.016492Z","iopub.status.idle":"2023-09-28T06:15:59.029601Z","shell.execute_reply.started":"2023-09-28T06:15:59.016461Z","shell.execute_reply":"2023-09-28T06:15:59.027949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Embarked'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:35:28.686141Z","iopub.execute_input":"2023-09-28T06:35:28.686579Z","iopub.status.idle":"2023-09-28T06:35:28.696664Z","shell.execute_reply.started":"2023-09-28T06:35:28.686543Z","shell.execute_reply":"2023-09-28T06:35:28.695356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Age'] = df['Age'].fillna(df['Age'].mean())","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:48:06.544476Z","iopub.execute_input":"2023-09-28T06:48:06.544890Z","iopub.status.idle":"2023-09-28T06:48:06.552214Z","shell.execute_reply.started":"2023-09-28T06:48:06.544854Z","shell.execute_reply":"2023-09-28T06:48:06.551037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.isnan(np.nan)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:25:22.866163Z","iopub.execute_input":"2023-09-28T06:25:22.866600Z","iopub.status.idle":"2023-09-28T06:25:22.873585Z","shell.execute_reply.started":"2023-09-28T06:25:22.866567Z","shell.execute_reply":"2023-09-28T06:25:22.872609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def deck(x) : \n    if pd.isna(x):\n        return 0\n    else : \n        return ord(x[0]) - 64\n","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:48:09.745484Z","iopub.execute_input":"2023-09-28T06:48:09.745889Z","iopub.status.idle":"2023-09-28T06:48:09.750783Z","shell.execute_reply.started":"2023-09-28T06:48:09.745857Z","shell.execute_reply":"2023-09-28T06:48:09.750001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Cabin'] = df['Cabin'].apply(deck)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:48:11.015719Z","iopub.execute_input":"2023-09-28T06:48:11.016545Z","iopub.status.idle":"2023-09-28T06:48:11.023828Z","shell.execute_reply.started":"2023-09-28T06:48:11.016502Z","shell.execute_reply":"2023-09-28T06:48:11.023103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:48:23.355322Z","iopub.execute_input":"2023-09-28T06:48:23.356260Z","iopub.status.idle":"2023-09-28T06:48:23.373091Z","shell.execute_reply.started":"2023-09-28T06:48:23.356226Z","shell.execute_reply":"2023-09-28T06:48:23.372071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Sex'] = df['Sex'].map({'male':0,'female':1})\ndf = pd.get_dummies(df, columns = ['Embarked'],dtype = 'int')","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:48:20.795974Z","iopub.execute_input":"2023-09-28T06:48:20.796392Z","iopub.status.idle":"2023-09-28T06:48:20.809141Z","shell.execute_reply.started":"2023-09-28T06:48:20.796355Z","shell.execute_reply":"2023-09-28T06:48:20.808122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['Survived']\nX = df.drop(['Survived','Ticket','Name','PassengerId'],axis = 1)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:48:29.466351Z","iopub.execute_input":"2023-09-28T06:48:29.466771Z","iopub.status.idle":"2023-09-28T06:48:29.473384Z","shell.execute_reply.started":"2023-09-28T06:48:29.466735Z","shell.execute_reply":"2023-09-28T06:48:29.472254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:48:31.713433Z","iopub.execute_input":"2023-09-28T06:48:31.713809Z","iopub.status.idle":"2023-09-28T06:48:31.726791Z","shell.execute_reply.started":"2023-09-28T06:48:31.713777Z","shell.execute_reply":"2023-09-28T06:48:31.726080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model1 = RandomForestClassifier()\ncross_val_score(model1,X,y,cv = 10).mean()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:52:24.425343Z","iopub.execute_input":"2023-09-28T06:52:24.425754Z","iopub.status.idle":"2023-09-28T06:52:27.186281Z","shell.execute_reply.started":"2023-09-28T06:52:24.425722Z","shell.execute_reply":"2023-09-28T06:52:27.185458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:53:37.892502Z","iopub.execute_input":"2023-09-28T06:53:37.892891Z","iopub.status.idle":"2023-09-28T06:53:37.897385Z","shell.execute_reply.started":"2023-09-28T06:53:37.892858Z","shell.execute_reply":"2023-09-28T06:53:37.896444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2 = XGBClassifier()\ncross_val_score(model2,X,y,cv = 10).mean()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T06:54:06.545379Z","iopub.execute_input":"2023-09-28T06:54:06.545747Z","iopub.status.idle":"2023-09-28T06:54:09.653564Z","shell.execute_reply.started":"2023-09-28T06:54:06.545719Z","shell.execute_reply":"2023-09-28T06:54:09.652335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2.fit(X,y)\nmodel2.feature_importances_","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:05:45.866702Z","iopub.execute_input":"2023-09-28T07:05:45.867112Z","iopub.status.idle":"2023-09-28T07:05:45.988087Z","shell.execute_reply.started":"2023-09-28T07:05:45.867083Z","shell.execute_reply":"2023-09-28T07:05:45.987183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.columns","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:06:49.136365Z","iopub.execute_input":"2023-09-28T07:06:49.136807Z","iopub.status.idle":"2023-09-28T07:06:49.145277Z","shell.execute_reply.started":"2023-09-28T07:06:49.136769Z","shell.execute_reply":"2023-09-28T07:06:49.143920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/churn-big.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:58:37.055051Z","iopub.execute_input":"2023-09-28T07:58:37.055451Z","iopub.status.idle":"2023-09-28T07:58:37.075273Z","shell.execute_reply.started":"2023-09-28T07:58:37.055421Z","shell.execute_reply":"2023-09-28T07:58:37.073778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()\n","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:53:34.427038Z","iopub.execute_input":"2023-09-28T07:53:34.427745Z","iopub.status.idle":"2023-09-28T07:53:34.456262Z","shell.execute_reply.started":"2023-09-28T07:53:34.427708Z","shell.execute_reply":"2023-09-28T07:53:34.454457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndf['Voice mail plan'] = df['Voice mail plan'].map({'No':0,'Yes':1})\ndf['International plan'] = df['International plan'].map({'No':0,'Yes':1})\ndf['State'] = df['State'].apply(ordre)\ndf = pd.get_dummies(df, columns = ['Area code'])","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:58:40.627761Z","iopub.execute_input":"2023-09-28T07:58:40.628511Z","iopub.status.idle":"2023-09-28T07:58:40.651692Z","shell.execute_reply.started":"2023-09-28T07:58:40.628473Z","shell.execute_reply":"2023-09-28T07:58:40.650331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def ordre(x) :\n    if pd.isna(x):\n        return 0\n    else:\n        return int(str(ord(x[0])-64)+str(ord(x[1])-64))","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:58:42.094625Z","iopub.execute_input":"2023-09-28T07:58:42.095832Z","iopub.status.idle":"2023-09-28T07:58:42.102328Z","shell.execute_reply.started":"2023-09-28T07:58:42.095780Z","shell.execute_reply":"2023-09-28T07:58:42.101127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['Churn']\nX = df.drop(['Churn'],axis = 1)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:58:42.736600Z","iopub.execute_input":"2023-09-28T07:58:42.737053Z","iopub.status.idle":"2023-09-28T07:58:42.745498Z","shell.execute_reply.started":"2023-09-28T07:58:42.737018Z","shell.execute_reply":"2023-09-28T07:58:42.743982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:26:55.796162Z","iopub.execute_input":"2023-09-28T07:26:55.796580Z","iopub.status.idle":"2023-09-28T07:26:55.805328Z","shell.execute_reply.started":"2023-09-28T07:26:55.796544Z","shell.execute_reply":"2023-09-28T07:26:55.804203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2 = XGBClassifier()\ncross_val_score(model2,X,y,cv = 10).mean()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:32:47.226067Z","iopub.execute_input":"2023-09-28T07:32:47.226552Z","iopub.status.idle":"2023-09-28T07:32:50.020444Z","shell.execute_reply.started":"2023-09-28T07:32:47.226508Z","shell.execute_reply":"2023-09-28T07:32:50.019445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model1 = RandomForestClassifier()\nmodel1.fit(X_train1,y_train1)\ny_hat = model1.predict(X_test)\naccuracy_score(y_test,y_hat)\npd.crosstab(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:24:13.341962Z","iopub.execute_input":"2023-09-28T08:24:13.342940Z","iopub.status.idle":"2023-09-28T08:24:13.720023Z","shell.execute_reply.started":"2023-09-28T08:24:13.342887Z","shell.execute_reply":"2023-09-28T08:24:13.718905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T07:58:49.175135Z","iopub.execute_input":"2023-09-28T07:58:49.175538Z","iopub.status.idle":"2023-09-28T07:58:49.184225Z","shell.execute_reply.started":"2023-09-28T07:58:49.175506Z","shell.execute_reply":"2023-09-28T07:58:49.183066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from imblearn.under_sampling import RandomUnderSampler \n\nsampler = RandomUnderSampler()\nX_train1, y_train1 = sampler.fit_resample(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:23:41.592329Z","iopub.execute_input":"2023-09-28T08:23:41.592788Z","iopub.status.idle":"2023-09-28T08:23:41.608495Z","shell.execute_reply.started":"2023-09-28T08:23:41.592753Z","shell.execute_reply":"2023-09-28T08:23:41.607179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train1.value_counts()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train1.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:23:43.913366Z","iopub.execute_input":"2023-09-28T08:23:43.914081Z","iopub.status.idle":"2023-09-28T08:23:43.924130Z","shell.execute_reply.started":"2023-09-28T08:23:43.914024Z","shell.execute_reply":"2023-09-28T08:23:43.922565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/kc_house_data.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:50:38.272537Z","iopub.execute_input":"2023-09-28T08:50:38.273016Z","iopub.status.idle":"2023-09-28T08:50:38.363903Z","shell.execute_reply.started":"2023-09-28T08:50:38.272961Z","shell.execute_reply":"2023-09-28T08:50:38.362643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head().T","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:51:15.573554Z","iopub.execute_input":"2023-09-28T08:51:15.574050Z","iopub.status.idle":"2023-09-28T08:51:15.593060Z","shell.execute_reply.started":"2023-09-28T08:51:15.574010Z","shell.execute_reply":"2023-09-28T08:51:15.592039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Year'] = df['date'][:3]","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:48:01.422984Z","iopub.execute_input":"2023-09-28T08:48:01.423394Z","iopub.status.idle":"2023-09-28T08:48:01.431828Z","shell.execute_reply.started":"2023-09-28T08:48:01.423362Z","shell.execute_reply":"2023-09-28T08:48:01.430546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df.price<2000000].plot(kind = 'scatter', x = 'long', y = 'lat', c = 'price', cmap = 'rainbow', figsize = (12,12))","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:43:38.713087Z","iopub.execute_input":"2023-09-28T08:43:38.714399Z","iopub.status.idle":"2023-09-28T08:43:40.234020Z","shell.execute_reply.started":"2023-09-28T08:43:38.714359Z","shell.execute_reply":"2023-09-28T08:43:40.232823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.groupby(['year','mounth'])[prine].mean().plot(kind = 'bar')","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:46:10.930545Z","iopub.execute_input":"2023-09-28T08:46:10.931016Z","iopub.status.idle":"2023-09-28T08:46:11.468449Z","shell.execute_reply.started":"2023-09-28T08:46:10.930980Z","shell.execute_reply":"2023-09-28T08:46:11.466728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.clustermap(abs(df.corr()))","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:51:24.570430Z","iopub.execute_input":"2023-09-28T08:51:24.570986Z","iopub.status.idle":"2023-09-28T08:51:25.551197Z","shell.execute_reply.started":"2023-09-28T08:51:24.570923Z","shell.execute_reply":"2023-09-28T08:51:25.549894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.drop(['id','date'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:51:22.222373Z","iopub.execute_input":"2023-09-28T08:51:22.223557Z","iopub.status.idle":"2023-09-28T08:51:22.231371Z","shell.execute_reply.started":"2023-09-28T08:51:22.223516Z","shell.execute_reply":"2023-09-28T08:51:22.229882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['price']\nX = df.drop(['price'],axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:56:15.142641Z","iopub.execute_input":"2023-09-28T08:56:15.143096Z","iopub.status.idle":"2023-09-28T08:56:15.151425Z","shell.execute_reply.started":"2023-09-28T08:56:15.143059Z","shell.execute_reply":"2023-09-28T08:56:15.150351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = LinearRegression()\nmodel.fit(X_train,y_train)\ny_hat = model.predict(X_test)\nprint(np.sqrt(mean_squared_error(y_test,y_hat)))\nprint(mean_absolute_error(y_test,y_hat))\nprint(r2_score(y_test,y_hat))","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:01:01.172907Z","iopub.execute_input":"2023-09-28T09:01:01.173368Z","iopub.status.idle":"2023-09-28T09:01:01.220413Z","shell.execute_reply.started":"2023-09-28T09:01:01.173332Z","shell.execute_reply":"2023-09-28T09:01:01.218293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.2)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:59:39.302598Z","iopub.execute_input":"2023-09-28T08:59:39.303025Z","iopub.status.idle":"2023-09-28T08:59:39.315951Z","shell.execute_reply.started":"2023-09-28T08:59:39.302994Z","shell.execute_reply":"2023-09-28T08:59:39.314647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-09-28T08:57:45.131924Z","iopub.execute_input":"2023-09-28T08:57:45.132326Z","iopub.status.idle":"2023-09-28T08:57:46.274514Z","shell.execute_reply.started":"2023-09-28T08:57:45.132295Z","shell.execute_reply":"2023-09-28T08:57:46.273219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Zalando\n****","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/fashionmnist/fashion-mnist_test.csv')\ndf2 = pd.read_csv('/kaggle/input/fashionmnist/fashion-mnist_train.csv')","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:29:30.107100Z","iopub.execute_input":"2023-09-28T09:29:30.107482Z","iopub.status.idle":"2023-09-28T09:29:37.821933Z","shell.execute_reply.started":"2023-09-28T09:29:30.107447Z","shell.execute_reply":"2023-09-28T09:29:37.820936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:19:28.104439Z","iopub.execute_input":"2023-09-28T09:19:28.104805Z","iopub.status.idle":"2023-09-28T09:19:28.139260Z","shell.execute_reply.started":"2023-09-28T09:19:28.104752Z","shell.execute_reply":"2023-09-28T09:19:28.137972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = df2['label']\nX_train= df2.drop(['label'],axis = 1)\n\ny_test = df['label']\nX_test = df.drop(['label'],axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:29:40.557433Z","iopub.execute_input":"2023-09-28T09:29:40.557795Z","iopub.status.idle":"2023-09-28T09:29:40.698688Z","shell.execute_reply.started":"2023-09-28T09:29:40.557763Z","shell.execute_reply":"2023-09-28T09:29:40.697527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2 = XGBClassifier(tree_method = 'gpu_hist',gpu_id = 0)\nmodel2.fit(X_train,y_train)\ny_hat = model2.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:30:07.576381Z","iopub.execute_input":"2023-09-28T09:30:07.576769Z","iopub.status.idle":"2023-09-28T09:30:26.805582Z","shell.execute_reply.started":"2023-09-28T09:30:07.576737Z","shell.execute_reply":"2023-09-28T09:30:26.804636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(y_test,y_hat))\npd.crosstab(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:30:29.844491Z","iopub.execute_input":"2023-09-28T09:30:29.845142Z","iopub.status.idle":"2023-09-28T09:30:29.885869Z","shell.execute_reply.started":"2023-09-28T09:30:29.845109Z","shell.execute_reply":"2023-09-28T09:30:29.884707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = X_test.values.reshape(X_test.shape[0],28,28)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:35:14.868510Z","iopub.execute_input":"2023-09-28T09:35:14.869482Z","iopub.status.idle":"2023-09-28T09:35:14.875037Z","shell.execute_reply.started":"2023-09-28T09:35:14.869435Z","shell.execute_reply":"2023-09-28T09:35:14.873956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,20))\nfor i in range(1,50):\n    plt.subplot(10,5,i)\n    plt.imshow(images[i], cmap = 'gray_r')\n    plt.title(str(y_test.values[i])+'/'+str(y_hat[i]))\n    plt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:44:12.387899Z","iopub.execute_input":"2023-09-28T09:44:12.388437Z","iopub.status.idle":"2023-09-28T09:44:16.224920Z","shell.execute_reply.started":"2023-09-28T09:44:12.388394Z","shell.execute_reply":"2023-09-28T09:44:16.223694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test = df['label']\nX_test = df.drop(['label'],axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:42:34.806143Z","iopub.execute_input":"2023-09-28T09:42:34.806735Z","iopub.status.idle":"2023-09-28T09:42:34.828744Z","shell.execute_reply.started":"2023-09-28T09:42:34.806698Z","shell.execute_reply":"2023-09-28T09:42:34.827684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.shape","metadata":{"execution":{"iopub.status.busy":"2023-09-28T09:33:55.074469Z","iopub.execute_input":"2023-09-28T09:33:55.075257Z","iopub.status.idle":"2023-09-28T09:33:55.081116Z","shell.execute_reply.started":"2023-09-28T09:33:55.075221Z","shell.execute_reply":"2023-09-28T09:33:55.080186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Exercices** Coeur","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/cancer.csv')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:31:47.329221Z","iopub.execute_input":"2023-10-01T16:31:47.329575Z","iopub.status.idle":"2023-10-01T16:31:47.362834Z","shell.execute_reply.started":"2023-10-01T16:31:47.329547Z","shell.execute_reply":"2023-10-01T16:31:47.362020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:32:29.405063Z","iopub.execute_input":"2023-10-01T16:32:29.405527Z","iopub.status.idle":"2023-10-01T16:32:29.411749Z","shell.execute_reply.started":"2023-10-01T16:32:29.405497Z","shell.execute_reply":"2023-10-01T16:32:29.410924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:32:54.179741Z","iopub.execute_input":"2023-10-01T16:32:54.180058Z","iopub.status.idle":"2023-10-01T16:32:54.207414Z","shell.execute_reply.started":"2023-10-01T16:32:54.180032Z","shell.execute_reply":"2023-10-01T16:32:54.206309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.diagnosis.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:33:34.699285Z","iopub.execute_input":"2023-10-01T16:33:34.699641Z","iopub.status.idle":"2023-10-01T16:33:34.710015Z","shell.execute_reply.started":"2023-10-01T16:33:34.699614Z","shell.execute_reply":"2023-10-01T16:33:34.708987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['diagnosis']\nX = df.drop(['diagnosis','Unnamed: 32'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:35:22.835105Z","iopub.execute_input":"2023-10-01T16:35:22.835628Z","iopub.status.idle":"2023-10-01T16:35:22.842115Z","shell.execute_reply.started":"2023-10-01T16:35:22.835592Z","shell.execute_reply":"2023-10-01T16:35:22.840854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.2)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:36:03.446816Z","iopub.execute_input":"2023-10-01T16:36:03.447152Z","iopub.status.idle":"2023-10-01T16:36:03.453634Z","shell.execute_reply.started":"2023-10-01T16:36:03.447125Z","shell.execute_reply":"2023-10-01T16:36:03.452449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = DecisionTreeClassifier()\nmodel.fit(X_train,y_train)\ny_hat = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:37:20.985626Z","iopub.execute_input":"2023-10-01T16:37:20.985950Z","iopub.status.idle":"2023-10-01T16:37:21.003898Z","shell.execute_reply.started":"2023-10-01T16:37:20.985919Z","shell.execute_reply":"2023-10-01T16:37:21.002861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:37:52.188790Z","iopub.execute_input":"2023-10-01T16:37:52.189129Z","iopub.status.idle":"2023-10-01T16:37:52.196472Z","shell.execute_reply.started":"2023-10-01T16:37:52.189102Z","shell.execute_reply":"2023-10-01T16:37:52.195631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.crosstab(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:38:24.629981Z","iopub.execute_input":"2023-10-01T16:38:24.630421Z","iopub.status.idle":"2023-10-01T16:38:24.664261Z","shell.execute_reply.started":"2023-10-01T16:38:24.630361Z","shell.execute_reply":"2023-10-01T16:38:24.663371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Exercices** Champignons","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/mushrooms.csv')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:53:02.998762Z","iopub.execute_input":"2023-10-01T16:53:02.999084Z","iopub.status.idle":"2023-10-01T16:53:03.022239Z","shell.execute_reply.started":"2023-10-01T16:53:02.999058Z","shell.execute_reply":"2023-10-01T16:53:03.021444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:52:16.994975Z","iopub.execute_input":"2023-10-01T16:52:16.996030Z","iopub.status.idle":"2023-10-01T16:52:17.012517Z","shell.execute_reply.started":"2023-10-01T16:52:16.995990Z","shell.execute_reply":"2023-10-01T16:52:17.011655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"class\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:41:54.274706Z","iopub.execute_input":"2023-10-01T16:41:54.275045Z","iopub.status.idle":"2023-10-01T16:41:54.283209Z","shell.execute_reply.started":"2023-10-01T16:41:54.275019Z","shell.execute_reply":"2023-10-01T16:41:54.282319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['class']\nX = df.drop(['class'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:51:01.311432Z","iopub.execute_input":"2023-10-01T16:51:01.311772Z","iopub.status.idle":"2023-10-01T16:51:01.318486Z","shell.execute_reply.started":"2023-10-01T16:51:01.311747Z","shell.execute_reply":"2023-10-01T16:51:01.317476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.2)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:53:09.614041Z","iopub.execute_input":"2023-10-01T16:53:09.614364Z","iopub.status.idle":"2023-10-01T16:53:09.624260Z","shell.execute_reply.started":"2023-10-01T16:53:09.614338Z","shell.execute_reply":"2023-10-01T16:53:09.623414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:52:20.189896Z","iopub.execute_input":"2023-10-01T16:52:20.190228Z","iopub.status.idle":"2023-10-01T16:52:20.196742Z","shell.execute_reply.started":"2023-10-01T16:52:20.190203Z","shell.execute_reply":"2023-10-01T16:52:20.195886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['cap-shape'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:47:13.302831Z","iopub.execute_input":"2023-10-01T16:47:13.303178Z","iopub.status.idle":"2023-10-01T16:47:13.310854Z","shell.execute_reply.started":"2023-10-01T16:47:13.303152Z","shell.execute_reply":"2023-10-01T16:47:13.309956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.get_dummies(df, columns = ['class', 'cap-shape', 'cap-surface', 'cap-color', 'bruises', 'odor',\n       'gill-attachment', 'gill-spacing', 'gill-size', 'gill-color',\n       'stalk-shape', 'stalk-root', 'stalk-surface-above-ring',\n       'stalk-surface-below-ring', 'stalk-color-above-ring',\n       'stalk-color-below-ring', 'veil-type', 'veil-color', 'ring-number',\n       'ring-type', 'spore-print-color', 'population', 'habitat'])","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:53:07.057476Z","iopub.execute_input":"2023-10-01T16:53:07.057795Z","iopub.status.idle":"2023-10-01T16:53:07.091376Z","shell.execute_reply.started":"2023-10-01T16:53:07.057771Z","shell.execute_reply":"2023-10-01T16:53:07.090608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = RandomForestClassifier()\n\nmodel3 = RandomForestClassifier()\nmodel.fit(X_train,y_train)\ny_hat = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:53:12.061782Z","iopub.execute_input":"2023-10-01T16:53:12.062106Z","iopub.status.idle":"2023-10-01T16:53:12.379680Z","shell.execute_reply.started":"2023-10-01T16:53:12.062082Z","shell.execute_reply":"2023-10-01T16:53:12.378779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:53:15.358510Z","iopub.execute_input":"2023-10-01T16:53:15.358829Z","iopub.status.idle":"2023-10-01T16:53:15.368211Z","shell.execute_reply.started":"2023-10-01T16:53:15.358805Z","shell.execute_reply":"2023-10-01T16:53:15.367310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.crosstab(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:53:33.014036Z","iopub.execute_input":"2023-10-01T16:53:33.014352Z","iopub.status.idle":"2023-10-01T16:53:33.030371Z","shell.execute_reply.started":"2023-10-01T16:53:33.014328Z","shell.execute_reply":"2023-10-01T16:53:33.029463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2 = ExtraTreesClassifier()\nscore = cross_val_score(model2, X_train,y_train, cv = 10)\nscore.mean()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:57:29.627800Z","iopub.execute_input":"2023-10-01T16:57:29.628433Z","iopub.status.idle":"2023-10-01T16:57:32.519103Z","shell.execute_reply.started":"2023-10-01T16:57:29.628383Z","shell.execute_reply":"2023-10-01T16:57:32.518201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model3 = GradientBoostingClassifier()\nscore = cross_val_score(model3, X_train,y_train, cv = 10)\nscore.mean()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T16:57:13.799598Z","iopub.execute_input":"2023-10-01T16:57:13.799926Z","iopub.status.idle":"2023-10-01T16:57:24.394973Z","shell.execute_reply.started":"2023-10-01T16:57:13.799894Z","shell.execute_reply":"2023-10-01T16:57:24.394091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Exercices** Diabete","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/diabetes.csv')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T17:02:38.460077Z","iopub.execute_input":"2023-10-01T17:02:38.460436Z","iopub.status.idle":"2023-10-01T17:02:38.487415Z","shell.execute_reply.started":"2023-10-01T17:02:38.460380Z","shell.execute_reply":"2023-10-01T17:02:38.486647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T17:02:43.120564Z","iopub.execute_input":"2023-10-01T17:02:43.120967Z","iopub.status.idle":"2023-10-01T17:02:43.138279Z","shell.execute_reply.started":"2023-10-01T17:02:43.120924Z","shell.execute_reply":"2023-10-01T17:02:43.137454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['Outcome']\nX = df.drop(['Outcome'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T17:04:24.516475Z","iopub.execute_input":"2023-10-01T17:04:24.516804Z","iopub.status.idle":"2023-10-01T17:04:24.522115Z","shell.execute_reply.started":"2023-10-01T17:04:24.516779Z","shell.execute_reply":"2023-10-01T17:04:24.521220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.2)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T17:04:25.397208Z","iopub.execute_input":"2023-10-01T17:04:25.397886Z","iopub.status.idle":"2023-10-01T17:04:25.404464Z","shell.execute_reply.started":"2023-10-01T17:04:25.397857Z","shell.execute_reply":"2023-10-01T17:04:25.403203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model3 = GradientBoostingClassifier()\nmodel3.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T17:06:19.737741Z","iopub.execute_input":"2023-10-01T17:06:19.738072Z","iopub.status.idle":"2023-10-01T17:06:19.894326Z","shell.execute_reply.started":"2023-10-01T17:06:19.738047Z","shell.execute_reply":"2023-10-01T17:06:19.893474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"importances = model3.feature_importances_\nindices = np.argsort(importances)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T17:06:51.080082Z","iopub.execute_input":"2023-10-01T17:06:51.080465Z","iopub.status.idle":"2023-10-01T17:06:51.087904Z","shell.execute_reply.started":"2023-10-01T17:06:51.080430Z","shell.execute_reply":"2023-10-01T17:06:51.086963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,5))\nplt.barh(range(len(indices)),importances[indices])\nplt.yticks(range(len(indices)),X_train.columns[indices])\nplt.title('Importance des caractéristiques')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T17:08:34.799312Z","iopub.execute_input":"2023-10-01T17:08:34.799679Z","iopub.status.idle":"2023-10-01T17:08:35.090805Z","shell.execute_reply.started":"2023-10-01T17:08:34.799654Z","shell.execute_reply":"2023-10-01T17:08:35.089942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Exercices** Covid","metadata":{"execution":{"iopub.status.busy":"2023-10-01T17:11:33.241075Z","iopub.execute_input":"2023-10-01T17:11:33.241446Z","iopub.status.idle":"2023-10-01T17:11:33.247241Z","shell.execute_reply.started":"2023-10-01T17:11:33.241406Z","shell.execute_reply":"2023-10-01T17:11:33.246004Z"}}},{"cell_type":"code","source":"df = pd.read_excel('/kaggle/input/covid19/dataset.xlsx')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:48:36.974239Z","iopub.execute_input":"2023-10-01T18:48:36.974548Z","iopub.status.idle":"2023-10-01T18:48:37.856731Z","shell.execute_reply.started":"2023-10-01T18:48:36.974522Z","shell.execute_reply":"2023-10-01T18:48:37.855856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:31:07.792091Z","iopub.execute_input":"2023-10-01T18:31:07.792550Z","iopub.status.idle":"2023-10-01T18:31:07.824851Z","shell.execute_reply.started":"2023-10-01T18:31:07.792520Z","shell.execute_reply":"2023-10-01T18:31:07.823942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.drop(['Patient ID'], axis = 1)\ndf['SARS-Cov-2 exam result'] = df['SARS-Cov-2 exam result'].map({'negative':0, 'positive': 1})","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:48:39.751871Z","iopub.execute_input":"2023-10-01T18:48:39.752459Z","iopub.status.idle":"2023-10-01T18:48:39.761772Z","shell.execute_reply.started":"2023-10-01T18:48:39.752431Z","shell.execute_reply":"2023-10-01T18:48:39.760812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['SARS-Cov-2 exam result'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:34:34.036508Z","iopub.execute_input":"2023-10-01T18:34:34.036871Z","iopub.status.idle":"2023-10-01T18:34:34.047584Z","shell.execute_reply.started":"2023-10-01T18:34:34.036845Z","shell.execute_reply":"2023-10-01T18:34:34.046611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['SARS-Cov-2 exam result']\nX = df.drop(['SARS-Cov-2 exam result'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:43:13.220473Z","iopub.execute_input":"2023-10-01T18:43:13.220813Z","iopub.status.idle":"2023-10-01T18:43:13.229067Z","shell.execute_reply.started":"2023-10-01T18:43:13.220785Z","shell.execute_reply":"2023-10-01T18:43:13.228156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.2)\n","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:43:15.129828Z","iopub.execute_input":"2023-10-01T18:43:15.130141Z","iopub.status.idle":"2023-10-01T18:43:15.141854Z","shell.execute_reply.started":"2023-10-01T18:43:15.130119Z","shell.execute_reply":"2023-10-01T18:43:15.140900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def NanToZero(x) : \n    if pd.isna(x):\n        return 0\n    else : \n        return x\n","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:52:13.860781Z","iopub.execute_input":"2023-10-01T18:52:13.861454Z","iopub.status.idle":"2023-10-01T18:52:13.865429Z","shell.execute_reply.started":"2023-10-01T18:52:13.861423Z","shell.execute_reply":"2023-10-01T18:52:13.864579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns[0]","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:51:13.627616Z","iopub.execute_input":"2023-10-01T18:51:13.628088Z","iopub.status.idle":"2023-10-01T18:51:13.646288Z","shell.execute_reply.started":"2023-10-01T18:51:13.628047Z","shell.execute_reply":"2023-10-01T18:51:13.643296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for colonne in df.columns:\n    df[colonne] = df[colonne].apply(NanToZero)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:52:15.839260Z","iopub.execute_input":"2023-10-01T18:52:15.839582Z","iopub.status.idle":"2023-10-01T18:52:16.249839Z","shell.execute_reply.started":"2023-10-01T18:52:15.839557Z","shell.execute_reply":"2023-10-01T18:52:16.248932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Urine - Protein'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T18:56:35.810315Z","iopub.execute_input":"2023-10-01T18:56:35.810626Z","iopub.status.idle":"2023-10-01T18:56:35.818465Z","shell.execute_reply.started":"2023-10-01T18:56:35.810599Z","shell.execute_reply":"2023-10-01T18:56:35.817622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier\nxgb = XGBClassifier(scale_pos_weight = 5086/558)\nxgb.fit(X_train,y_train)\ny_hat = xgb.predict(X_test)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Exercices** MNIST\n","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/mnist-in-csv/mnist_train.csv')\ndf2 = pd.read_csv('/kaggle/input/mnist-in-csv/mnist_test.csv')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T19:05:39.885210Z","iopub.execute_input":"2023-10-01T19:05:39.885536Z","iopub.status.idle":"2023-10-01T19:05:44.906678Z","shell.execute_reply.started":"2023-10-01T19:05:39.885511Z","shell.execute_reply":"2023-10-01T19:05:44.905791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-01T19:05:56.240252Z","iopub.execute_input":"2023-10-01T19:05:56.240644Z","iopub.status.idle":"2023-10-01T19:05:56.266038Z","shell.execute_reply.started":"2023-10-01T19:05:56.240610Z","shell.execute_reply":"2023-10-01T19:05:56.265308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = df['label']\ny_test = df2['label']\nX_train = df.drop(['label'],axis = 1)\nX_test = df2.drop(['label'],axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T19:24:38.839554Z","iopub.execute_input":"2023-10-01T19:24:38.839900Z","iopub.status.idle":"2023-10-01T19:24:38.967159Z","shell.execute_reply.started":"2023-10-01T19:24:38.839874Z","shell.execute_reply":"2023-10-01T19:24:38.965989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model3 = GradientBoostingClassifier()\nscore = cross_val_score(model3, X_train,y_train, cv = 1)\nscore.mean()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = RandomForestClassifier()\nmodel.fit(X_train,y_train)\ny_hat = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T19:25:29.205461Z","iopub.execute_input":"2023-10-01T19:25:29.205814Z","iopub.status.idle":"2023-10-01T19:26:09.863562Z","shell.execute_reply.started":"2023-10-01T19:25:29.205783Z","shell.execute_reply":"2023-10-01T19:26:09.862603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T19:26:17.790433Z","iopub.execute_input":"2023-10-01T19:26:17.791385Z","iopub.status.idle":"2023-10-01T19:26:17.799889Z","shell.execute_reply.started":"2023-10-01T19:26:17.791342Z","shell.execute_reply":"2023-10-01T19:26:17.798797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Exercice ** Strokes","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/stroke.csv')","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:18:23.219438Z","iopub.execute_input":"2023-10-06T12:18:23.220178Z","iopub.status.idle":"2023-10-06T12:18:23.278375Z","shell.execute_reply.started":"2023-10-06T12:18:23.220141Z","shell.execute_reply":"2023-10-06T12:18:23.277421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-06T11:54:54.998582Z","iopub.execute_input":"2023-10-06T11:54:54.999258Z","iopub.status.idle":"2023-10-06T11:54:55.012540Z","shell.execute_reply.started":"2023-10-06T11:54:54.999226Z","shell.execute_reply":"2023-10-06T11:54:55.011454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['gender'] = df['gender'].fillna('Other')\ndf['smoking_status'] = df['smoking_status'].fillna('unknown')\ndf['bmi'] = df['bmi'].fillna(df.bmi.mean())\ndf = df.drop(['id'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:18:26.843963Z","iopub.execute_input":"2023-10-06T12:18:26.844645Z","iopub.status.idle":"2023-10-06T12:18:26.862183Z","shell.execute_reply.started":"2023-10-06T12:18:26.844613Z","shell.execute_reply":"2023-10-06T12:18:26.861095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['stroke']\nX = df.drop(['stroke'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:18:31.476916Z","iopub.execute_input":"2023-10-06T12:18:31.477630Z","iopub.status.idle":"2023-10-06T12:18:31.484664Z","shell.execute_reply.started":"2023-10-06T12:18:31.477595Z","shell.execute_reply":"2023-10-06T12:18:31.483640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.get_dummies(df, ['gender', 'ever_married',\n       'work_type', 'Residence_type',\n       'smoking_status'])","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:18:29.550486Z","iopub.execute_input":"2023-10-06T12:18:29.551450Z","iopub.status.idle":"2023-10-06T12:18:29.588969Z","shell.execute_reply.started":"2023-10-06T12:18:29.551410Z","shell.execute_reply":"2023-10-06T12:18:29.587728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"UnderSampling _____________________________________________________________________________________","metadata":{}},{"cell_type":"code","source":"sampler = RandomUnderSampler()\nX,y = sampler.fit_resample(X,y)\ny.value_counts()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"_______________________","metadata":{}},{"cell_type":"markdown","source":"OverSampling ____________________________","metadata":{}},{"cell_type":"code","source":"sampler = SMOTE()\nX_train,y_train = sampler.fit_resample(X_train,y_train)\ny_train.value_counts()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"________________________________________________________","metadata":{}},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.2)\n","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:18:46.950611Z","iopub.execute_input":"2023-10-06T12:18:46.951718Z","iopub.status.idle":"2023-10-06T12:18:46.963821Z","shell.execute_reply.started":"2023-10-06T12:18:46.951677Z","shell.execute_reply":"2023-10-06T12:18:46.962854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = RandomForestClassifier()\nmodel.fit(X_train,y_train)\ny_hat = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:09:59.745188Z","iopub.execute_input":"2023-10-06T12:09:59.745836Z","iopub.status.idle":"2023-10-06T12:10:00.054029Z","shell.execute_reply.started":"2023-10-06T12:09:59.745800Z","shell.execute_reply":"2023-10-06T12:10:00.053125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:10:00.833409Z","iopub.execute_input":"2023-10-06T12:10:00.833738Z","iopub.status.idle":"2023-10-06T12:10:00.841315Z","shell.execute_reply.started":"2023-10-06T12:10:00.833713Z","shell.execute_reply":"2023-10-06T12:10:00.840433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"confusion_matrix(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:10:04.402847Z","iopub.execute_input":"2023-10-06T12:10:04.403506Z","iopub.status.idle":"2023-10-06T12:10:04.412355Z","shell.execute_reply.started":"2023-10-06T12:10:04.403475Z","shell.execute_reply":"2023-10-06T12:10:04.411044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"XGBoostClassifier Pondéré ___________________","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:19:53.302490Z","iopub.execute_input":"2023-10-06T12:19:53.302850Z","iopub.status.idle":"2023-10-06T12:19:53.309979Z","shell.execute_reply.started":"2023-10-06T12:19:53.302823Z","shell.execute_reply":"2023-10-06T12:19:53.308696Z"}}},{"cell_type":"code","source":"model = XGBClassifier(scale_pos_weight = 34095/625)\nmodel.fit(X_train,y_train)\ny_hat = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:18:55.202745Z","iopub.execute_input":"2023-10-06T12:18:55.203484Z","iopub.status.idle":"2023-10-06T12:18:58.541396Z","shell.execute_reply.started":"2023-10-06T12:18:55.203449Z","shell.execute_reply":"2023-10-06T12:18:58.540670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:19:06.245935Z","iopub.execute_input":"2023-10-06T12:19:06.246618Z","iopub.status.idle":"2023-10-06T12:19:06.255358Z","shell.execute_reply.started":"2023-10-06T12:19:06.246584Z","shell.execute_reply":"2023-10-06T12:19:06.254294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"confusion_matrix(y_test,y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:19:12.936603Z","iopub.execute_input":"2023-10-06T12:19:12.937335Z","iopub.status.idle":"2023-10-06T12:19:12.947323Z","shell.execute_reply.started":"2023-10-06T12:19:12.937303Z","shell.execute_reply":"2023-10-06T12:19:12.946124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"______________________","metadata":{}},{"cell_type":"markdown","source":"**AUTO ML**","metadata":{}},{"cell_type":"code","source":"!pip install --pre pycaret","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:26:46.597980Z","iopub.execute_input":"2023-10-06T12:26:46.598692Z","iopub.status.idle":"2023-10-06T12:27:34.303507Z","shell.execute_reply.started":"2023-10-06T12:26:46.598660Z","shell.execute_reply":"2023-10-06T12:27:34.302302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pycaret.classification import *","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:29:03.649488Z","iopub.execute_input":"2023-10-06T12:29:03.649885Z","iopub.status.idle":"2023-10-06T12:29:12.085579Z","shell.execute_reply.started":"2023-10-06T12:29:03.649844Z","shell.execute_reply":"2023-10-06T12:29:12.084452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"","metadata":{}},{"cell_type":"markdown","source":"setup(data = df, target = 'stroke', imputation_type = 'iterative', fix_imbalance = True)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:30:13.729937Z","iopub.execute_input":"2023-10-06T12:30:13.730512Z","iopub.status.idle":"2023-10-06T12:30:16.420886Z","shell.execute_reply.started":"2023-10-06T12:30:13.730481Z","shell.execute_reply":"2023-10-06T12:30:16.419965Z"}}},{"cell_type":"code","source":"setup(data = df, target = 'stroke', imputation_type = 'iterative', fix_imbalance = True)","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:39:55.381176Z","iopub.execute_input":"2023-10-06T12:39:55.381545Z","iopub.status.idle":"2023-10-06T12:39:56.849608Z","shell.execute_reply.started":"2023-10-06T12:39:55.381519Z","shell.execute_reply":"2023-10-06T12:39:56.848597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"models = compare_models()","metadata":{"execution":{"iopub.status.busy":"2023-10-06T12:40:04.846878Z","iopub.execute_input":"2023-10-06T12:40:04.847551Z","iopub.status.idle":"2023-10-06T12:50:04.229035Z","shell.execute_reply.started":"2023-10-06T12:40:04.847514Z","shell.execute_reply":"2023-10-06T12:50:04.227975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}