{"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":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":0.029588,"end_time":"2023-01-08T22:08:14.936677","exception":false,"start_time":"2023-01-08T22:08:14.907089","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-01-09T08:31:43.299252Z","iopub.execute_input":"2023-01-09T08:31:43.300209Z","iopub.status.idle":"2023-01-09T08:31:43.332613Z","shell.execute_reply.started":"2023-01-09T08:31:43.300114Z","shell.execute_reply":"2023-01-09T08:31:43.331414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/emsi-5iir-ds/train.csv')","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:08:14.948630Z","iopub.status.busy":"2023-01-08T22:08:14.948207Z","iopub.status.idle":"2023-01-08T22:08:24.193940Z","shell.execute_reply":"2023-01-08T22:08:24.192649Z"},"papermill":{"duration":9.254858,"end_time":"2023-01-08T22:08:24.196809","exception":false,"start_time":"2023-01-08T22:08:14.941951","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train\nX = train.drop('id', axis=1, inplace=False)\nX.drop('f_27', axis=1, inplace=True)\nX.drop('target', axis=1, inplace=True)\nX.describe()","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:08:24.208871Z","iopub.status.busy":"2023-01-08T22:08:24.208471Z","iopub.status.idle":"2023-01-08T22:08:25.631177Z","shell.execute_reply":"2023-01-08T22:08:25.629982Z"},"papermill":{"duration":1.43192,"end_time":"2023-01-08T22:08:25.634023","exception":false,"start_time":"2023-01-08T22:08:24.202103","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = train['target']\ny.describe()","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:08:25.647050Z","iopub.status.busy":"2023-01-08T22:08:25.645862Z","iopub.status.idle":"2023-01-08T22:08:25.679954Z","shell.execute_reply":"2023-01-08T22:08:25.678884Z"},"papermill":{"duration":0.043367,"end_time":"2023-01-08T22:08:25.682715","exception":false,"start_time":"2023-01-08T22:08:25.639348","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"existing_columns = X.columns\nfor (column) in existing_columns:\n    if (X[column].corr(train[\"target\"]) <= 0.04):\n        X.drop(column,inplace=True, axis=1)\n\nprint(\"Les Colonnes non-enlevés : \") \nfeatures = X.columns;\nfor (column) in X.columns:\n    print(column)\n\nprint(\"Nombre de colonnes : \" + str(X.columns.size))","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:08:25.696044Z","iopub.status.busy":"2023-01-08T22:08:25.695011Z","iopub.status.idle":"2023-01-08T22:08:27.128115Z","shell.execute_reply":"2023-01-08T22:08:27.126833Z"},"papermill":{"duration":1.443205,"end_time":"2023-01-08T22:08:27.131572","exception":false,"start_time":"2023-01-08T22:08:25.688367","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# hists = X.hist()\ncolumns_to_normalize =  [\"f_00\", \"f_01\", \"f_02\", \"f_05\", \"f_21\", \"f_22\", \"f_23\", \"f_24\", \"f_26\", \"f_28\"]\nto_normalize = X;\nfor column in X.columns :\n    if column not in columns_to_normalize:\n        to_normalize.drop(column, axis=1, inplace=True)\n\nto_normalize.hist()","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:08:27.145644Z","iopub.status.busy":"2023-01-08T22:08:27.145261Z","iopub.status.idle":"2023-01-08T22:08:28.371403Z","shell.execute_reply":"2023-01-08T22:08:28.370047Z"},"papermill":{"duration":1.235919,"end_time":"2023-01-08T22:08:28.373882","exception":false,"start_time":"2023-01-08T22:08:27.137963","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.datasets import load_iris\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.neighbors import KNeighborsClassifier\n\ndef executeKNN(trainS,testS,K):\n    # Split the data into training and test sets\n    X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=trainS, test_size=testS)\n    # Create the KNN classifier\n    knn = KNeighborsClassifier(n_neighbors=K)\n\n    # Fit the classifier to the training data\n    knn.fit(X_train, y_train)\n\n    # Make predictions on the test data\n    y_pred = knn.predict(X_test)\n\n    # Calculate the accuracy of the predictions\n    accuracy = knn.score(X_test, y_test)\n    print(\"Accuracy:\", accuracy)","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:08:28.387564Z","iopub.status.busy":"2023-01-08T22:08:28.387121Z","iopub.status.idle":"2023-01-08T22:08:29.579134Z","shell.execute_reply":"2023-01-08T22:08:29.577708Z"},"papermill":{"duration":1.202182,"end_time":"2023-01-08T22:08:29.582066","exception":false,"start_time":"2023-01-08T22:08:28.379884","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"executeKNN(0.3, 0.1, 7)\n","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:08:29.597541Z","iopub.status.busy":"2023-01-08T22:08:29.597007Z","iopub.status.idle":"2023-01-08T22:09:07.749000Z","shell.execute_reply":"2023-01-08T22:09:07.747431Z"},"papermill":{"duration":38.167357,"end_time":"2023-01-08T22:09:07.756339","exception":false,"start_time":"2023-01-08T22:08:29.588982","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/emsi-5iir-ds/train.csv')\ntest= pd.read_csv('/kaggle/input/emsi-5iir-ds/test.csv')","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:09:07.770765Z","iopub.status.busy":"2023-01-08T22:09:07.770307Z","iopub.status.idle":"2023-01-08T22:09:19.787665Z","shell.execute_reply":"2023-01-08T22:09:19.786381Z"},"papermill":{"duration":12.027079,"end_time":"2023-01-08T22:09:19.790207","exception":false,"start_time":"2023-01-08T22:09:07.763128","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train[features]\ny_train = train['target']\nX_test = test[features]","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:09:19.804458Z","iopub.status.busy":"2023-01-08T22:09:19.803529Z","iopub.status.idle":"2023-01-08T22:09:19.836438Z","shell.execute_reply":"2023-01-08T22:09:19.835172Z"},"papermill":{"duration":0.042934,"end_time":"2023-01-08T22:09:19.839218","exception":false,"start_time":"2023-01-08T22:09:19.796284","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.head()\n","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:09:19.853137Z","iopub.status.busy":"2023-01-08T22:09:19.852675Z","iopub.status.idle":"2023-01-08T22:09:19.870380Z","shell.execute_reply":"2023-01-08T22:09:19.868944Z"},"papermill":{"duration":0.02788,"end_time":"2023-01-08T22:09:19.873073","exception":false,"start_time":"2023-01-08T22:09:19.845193","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test.head()\n","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:09:19.887434Z","iopub.status.busy":"2023-01-08T22:09:19.887050Z","iopub.status.idle":"2023-01-08T22:09:19.902926Z","shell.execute_reply":"2023-01-08T22:09:19.901510Z"},"papermill":{"duration":0.025763,"end_time":"2023-01-08T22:09:19.905145","exception":false,"start_time":"2023-01-08T22:09:19.879382","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.head()\n","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:09:19.920276Z","iopub.status.busy":"2023-01-08T22:09:19.919503Z","iopub.status.idle":"2023-01-08T22:09:19.927929Z","shell.execute_reply":"2023-01-08T22:09:19.926817Z"},"papermill":{"duration":0.018375,"end_time":"2023-01-08T22:09:19.930311","exception":false,"start_time":"2023-01-08T22:09:19.911936","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier\nmodel = KNeighborsClassifier(n_neighbors=7)\nmodel.fit(X_train,y_train)","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:09:19.946927Z","iopub.status.busy":"2023-01-08T22:09:19.945889Z","iopub.status.idle":"2023-01-08T22:09:23.140264Z","shell.execute_reply":"2023-01-08T22:09:23.138991Z"},"papermill":{"duration":3.204762,"end_time":"2023-01-08T22:09:23.142884","exception":false,"start_time":"2023-01-08T22:09:19.938122","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(X_test)\n","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:09:23.157960Z","iopub.status.busy":"2023-01-08T22:09:23.157548Z","iopub.status.idle":"2023-01-08T22:23:12.162088Z","shell.execute_reply":"2023-01-08T22:23:12.160785Z"},"papermill":{"duration":829.015384,"end_time":"2023-01-08T22:23:12.165050","exception":false,"start_time":"2023-01-08T22:09:23.149666","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submition = test[[\"id\"]]\nsubmition[\"target\"] = predictions\nsubmition.to_csv('submission.csv', index=False)\nsubmition","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:23:12.180449Z","iopub.status.busy":"2023-01-08T22:23:12.180069Z","iopub.status.idle":"2023-01-08T22:23:12.920610Z","shell.execute_reply":"2023-01-08T22:23:12.919400Z"},"papermill":{"duration":0.750994,"end_time":"2023-01-08T22:23:12.923023","exception":false,"start_time":"2023-01-08T22:23:12.172029","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from IPython.display import HTML\nimport pandas as pd\nimport numpy as np\n\ndef create_download_link(title = \"Download CSV file\", filename = \"data.csv\"):  \n    html = '<a href={filename}>{title}</a>'\n    html = html.format(title=title,filename=filename)\n    return HTML(html)\ncreate_download_link(filename='submission.csv')","metadata":{"execution":{"iopub.execute_input":"2023-01-08T22:23:12.938012Z","iopub.status.busy":"2023-01-08T22:23:12.937626Z","iopub.status.idle":"2023-01-08T22:23:12.946198Z","shell.execute_reply":"2023-01-08T22:23:12.945197Z"},"papermill":{"duration":0.018416,"end_time":"2023-01-08T22:23:12.948197","exception":false,"start_time":"2023-01-08T22:23:12.929781","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]}]}