{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-07T16:02:09.140920Z","iopub.execute_input":"2023-11-07T16:02:09.141701Z","iopub.status.idle":"2023-11-07T16:02:09.160150Z","shell.execute_reply.started":"2023-11-07T16:02:09.141660Z","shell.execute_reply":"2023-11-07T16:02:09.159003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n\nimport tensorflow\nfrom tensorflow import keras\nfrom tensorflow.keras import Sequential\nfrom tensorflow.keras.layers import Dense,Flatten\nfrom sklearn.metrics import accuracy_score\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense\nfrom tensorflow.keras.datasets import cifar10\nfrom tensorflow.keras.layers import *\nfrom tensorflow.keras.preprocessing import *\nfrom tensorflow.keras.applications import *\n\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\n\nfrom matplotlib import pyplot as plt\n\nfrom sklearn.linear_model import *\nfrom sklearn.metrics import *\nfrom sklearn.model_selection import *\nfrom sklearn.ensemble import *\nfrom sklearn.preprocessing import *\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.model_selection import train_test_split\n\nfrom tensorflow.keras.layers import *\nfrom imblearn.under_sampling import RandomUnderSampler\nfrom xgboost import *\nfrom xgboost import XGBClassifier","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:09.162440Z","iopub.execute_input":"2023-11-07T16:02:09.163144Z","iopub.status.idle":"2023-11-07T16:02:09.177149Z","shell.execute_reply.started":"2023-11-07T16:02:09.163099Z","shell.execute_reply":"2023-11-07T16:02:09.175712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Diabète","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/basic-datasets/diabetes.csv')","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:09.179011Z","iopub.execute_input":"2023-11-07T16:02:09.179612Z","iopub.status.idle":"2023-11-07T16:02:09.201086Z","shell.execute_reply.started":"2023-11-07T16:02:09.179568Z","shell.execute_reply":"2023-11-07T16:02:09.199238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.sample(5)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:09.203842Z","iopub.execute_input":"2023-11-07T16:02:09.204733Z","iopub.status.idle":"2023-11-07T16:02:09.223798Z","shell.execute_reply.started":"2023-11-07T16:02:09.204697Z","shell.execute_reply":"2023-11-07T16:02:09.222609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop('Pregnancies', axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:09.225285Z","iopub.execute_input":"2023-11-07T16:02:09.226757Z","iopub.status.idle":"2023-11-07T16:02:09.256233Z","shell.execute_reply.started":"2023-11-07T16:02:09.226703Z","shell.execute_reply":"2023-11-07T16:02:09.254736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(df, x= 'DiabetesPedigreeFunction', y= 'BMI' , hue='Outcome', fill=True, alpha = 0.5)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:09.257946Z","iopub.execute_input":"2023-11-07T16:02:09.258328Z","iopub.status.idle":"2023-11-07T16:02:10.292216Z","shell.execute_reply.started":"2023-11-07T16:02:09.258295Z","shell.execute_reply":"2023-11-07T16:02:10.290747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(df, x= 'BloodPressure', y= 'DiabetesPedigreeFunction' , hue='Outcome', fill=True, alpha = 0.5)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:10.293765Z","iopub.execute_input":"2023-11-07T16:02:10.294143Z","iopub.status.idle":"2023-11-07T16:02:11.339288Z","shell.execute_reply.started":"2023-11-07T16:02:10.294112Z","shell.execute_reply":"2023-11-07T16:02:11.337892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df.drop('Outcome', axis=1)\ny = df['Outcome']","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:11.341438Z","iopub.execute_input":"2023-11-07T16:02:11.342824Z","iopub.status.idle":"2023-11-07T16:02:11.351218Z","shell.execute_reply.started":"2023-11-07T16:02:11.342761Z","shell.execute_reply":"2023-11-07T16:02:11.349648Z"},"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.04)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:11.356577Z","iopub.execute_input":"2023-11-07T16:02:11.357026Z","iopub.status.idle":"2023-11-07T16:02:11.366146Z","shell.execute_reply.started":"2023-11-07T16:02:11.356994Z","shell.execute_reply":"2023-11-07T16:02:11.364648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = StandardScaler()\nscaler.fit(X)\nX1 = scaler.transform(X)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:11.369731Z","iopub.execute_input":"2023-11-07T16:02:11.370133Z","iopub.status.idle":"2023-11-07T16:02:11.383877Z","shell.execute_reply.started":"2023-11-07T16:02:11.370103Z","shell.execute_reply":"2023-11-07T16:02:11.382512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = LogisticRegression()\nmodel.fit(X_train,y_train)\ny_hat = model.predict(X_test)\naccuracy_score(y_test, y_hat)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:11.385877Z","iopub.execute_input":"2023-11-07T16:02:11.386396Z","iopub.status.idle":"2023-11-07T16:02:11.430029Z","shell.execute_reply.started":"2023-11-07T16:02:11.386358Z","shell.execute_reply":"2023-11-07T16:02:11.428639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Chiffres","metadata":{}},{"cell_type":"code","source":"repertoire = \"/kaggle/input/digit-recognizer/\"","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:11.431755Z","iopub.execute_input":"2023-11-07T16:02:11.432903Z","iopub.status.idle":"2023-11-07T16:02:11.438437Z","shell.execute_reply.started":"2023-11-07T16:02:11.432865Z","shell.execute_reply":"2023-11-07T16:02:11.437084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(X_train,y_train),(X_test,y_test)=keras.datasets.mnist.load_data()","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:11.440638Z","iopub.execute_input":"2023-11-07T16:02:11.441059Z","iopub.status.idle":"2023-11-07T16:02:11.830903Z","shell.execute_reply.started":"2023-11-07T16:02:11.441024Z","shell.execute_reply":"2023-11-07T16:02:11.829542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.max()","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:11.833592Z","iopub.execute_input":"2023-11-07T16:02:11.835168Z","iopub.status.idle":"2023-11-07T16:02:11.850876Z","shell.execute_reply.started":"2023-11-07T16:02:11.835106Z","shell.execute_reply":"2023-11-07T16:02:11.849905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=X_train/255 # Pour avoir des valeurs entre 0 et 1\nX_test=X_test/255","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:11.852256Z","iopub.execute_input":"2023-11-07T16:02:11.852616Z","iopub.status.idle":"2023-11-07T16:02:12.066745Z","shell.execute_reply.started":"2023-11-07T16:02:11.852582Z","shell.execute_reply":"2023-11-07T16:02:12.065229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(Flatten(input_shape=(28,28))) # Ce sont des images 28x28\nmodel.add(Dense(128,activation=\"relu\"))\nmodel.add(Dense(10, activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:12.068725Z","iopub.execute_input":"2023-11-07T16:02:12.069214Z","iopub.status.idle":"2023-11-07T16:02:12.129194Z","shell.execute_reply.started":"2023-11-07T16:02:12.069173Z","shell.execute_reply":"2023-11-07T16:02:12.127784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:12.131032Z","iopub.execute_input":"2023-11-07T16:02:12.131501Z","iopub.status.idle":"2023-11-07T16:02:12.147812Z","shell.execute_reply.started":"2023-11-07T16:02:12.131471Z","shell.execute_reply":"2023-11-07T16:02:12.146163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history=model.fit(X_train,y_train,epochs=10,validation_split=0.2)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:02:12.149767Z","iopub.execute_input":"2023-11-07T16:02:12.150194Z","iopub.status.idle":"2023-11-07T16:03:23.987741Z","shell.execute_reply.started":"2023-11-07T16:02:12.150157Z","shell.execute_reply":"2023-11-07T16:03:23.985990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['val_accuracy'], c = 'green')\nplt.plot(history.history['accuracy'], c= 'blue')","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:03:23.989563Z","iopub.execute_input":"2023-11-07T16:03:23.989938Z","iopub.status.idle":"2023-11-07T16:03:24.314038Z","shell.execute_reply.started":"2023-11-07T16:03:23.989907Z","shell.execute_reply":"2023-11-07T16:03:24.312453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_hat = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:03:24.315696Z","iopub.execute_input":"2023-11-07T16:03:24.316065Z","iopub.status.idle":"2023-11-07T16:03:25.805473Z","shell.execute_reply.started":"2023-11-07T16:03:24.316035Z","shell.execute_reply":"2023-11-07T16:03:25.804189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_hat","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:03:25.810367Z","iopub.execute_input":"2023-11-07T16:03:25.810780Z","iopub.status.idle":"2023-11-07T16:03:25.820187Z","shell.execute_reply.started":"2023-11-07T16:03:25.810747Z","shell.execute_reply":"2023-11-07T16:03:25.818565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predit = y_hat.argmax(axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:03:25.821796Z","iopub.execute_input":"2023-11-07T16:03:25.822293Z","iopub.status.idle":"2023-11-07T16:03:25.831691Z","shell.execute_reply.started":"2023-11-07T16:03:25.822248Z","shell.execute_reply":"2023-11-07T16:03:25.830212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,y_predit)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T16:03:25.833426Z","iopub.execute_input":"2023-11-07T16:03:25.834084Z","iopub.status.idle":"2023-11-07T16:03:25.846433Z","shell.execute_reply.started":"2023-11-07T16:03:25.834035Z","shell.execute_reply":"2023-11-07T16:03:25.845099Z"},"trusted":true},"execution_count":null,"outputs":[]}]}