{"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":"markdown","source":"# Exploratory Data Analysis","metadata":{}},{"cell_type":"code","source":"from pathlib import Path\n\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n%matplotlib inline\nplt.rcParams[\"figure.figsize\"] = (14, 8)\nsns.set_theme(context=\"notebook\", style=\"whitegrid\")","metadata":{"execution":{"iopub.status.busy":"2022-07-09T17:43:26.630820Z","iopub.execute_input":"2022-07-09T17:43:26.631328Z","iopub.status.idle":"2022-07-09T17:43:27.041121Z","shell.execute_reply.started":"2022-07-09T17:43:26.631232Z","shell.execute_reply":"2022-07-09T17:43:27.040204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Config","metadata":{}},{"cell_type":"code","source":"# file paths\nDATA_DIR = Path(\"../input/tabular-playground-series-jun-2021\")\n\n# data\nTRAIN_DATA = DATA_DIR / \"train.csv\"\n\n# columns in the data\nINDEX_COL = \"id\"\n\nTARGET_COL = \"target\"\n\n# random state\nRANDOM_STATE = 42","metadata":{"execution":{"iopub.status.busy":"2022-07-09T17:43:27.042342Z","iopub.execute_input":"2022-07-09T17:43:27.042607Z","iopub.status.idle":"2022-07-09T17:43:27.047413Z","shell.execute_reply.started":"2022-07-09T17:43:27.042581Z","shell.execute_reply":"2022-07-09T17:43:27.046385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Loading the data","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv(TRAIN_DATA, index_col=INDEX_COL)\ndf.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T17:43:27.049119Z","iopub.execute_input":"2022-07-09T17:43:27.049398Z","iopub.status.idle":"2022-07-09T17:43:27.995365Z","shell.execute_reply.started":"2022-07-09T17:43:27.049370Z","shell.execute_reply":"2022-07-09T17:43:27.994151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Pandas profiling report","metadata":{}},{"cell_type":"code","source":"from pandas_profiling import ProfileReport\n\nprofile = ProfileReport(df, minimal=True)\nprofile","metadata":{"execution":{"iopub.status.busy":"2022-07-09T17:43:27.996845Z","iopub.execute_input":"2022-07-09T17:43:27.997233Z","iopub.status.idle":"2022-07-09T17:44:05.864469Z","shell.execute_reply.started":"2022-07-09T17:43:27.997200Z","shell.execute_reply":"2022-07-09T17:44:05.863477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Separate features from target","metadata":{}},{"cell_type":"code","source":"y = df[TARGET_COL]\nX = df.drop(TARGET_COL, axis=1)\n\nnumeric_dtypes = [\"int64\", \"float64\"]\ncategorical_df = X.select_dtypes(exclude=numeric_dtypes)\nnumeric_df = X.select_dtypes(include=numeric_dtypes)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T17:44:05.865798Z","iopub.execute_input":"2022-07-09T17:44:05.866127Z","iopub.status.idle":"2022-07-09T17:44:05.986644Z","shell.execute_reply.started":"2022-07-09T17:44:05.866096Z","shell.execute_reply":"2022-07-09T17:44:05.985558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Mutual information","metadata":{}},{"cell_type":"code","source":"from sklearn.feature_selection import mutual_info_classif\n\nmi_scores = mutual_info_classif(X, y, random_state=RANDOM_STATE)\nmi_scores = pd.Series(mi_scores, name=\"MI Scores\", index=X.columns)\nmi_scores = mi_scores.sort_values(ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T17:44:05.988030Z","iopub.execute_input":"2022-07-09T17:44:05.988326Z","iopub.status.idle":"2022-07-09T17:47:39.378224Z","shell.execute_reply.started":"2022-07-09T17:44:05.988294Z","shell.execute_reply":"2022-07-09T17:47:39.376975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(14, len(X.columns)//3))\n\nsns.barplot(x=mi_scores.values, y=mi_scores.index, ax=ax, color=\"tab:blue\")\nax.set_title(\"Mutual information scores\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T17:47:39.380083Z","iopub.execute_input":"2022-07-09T17:47:39.380528Z","iopub.status.idle":"2022-07-09T17:47:40.791299Z","shell.execute_reply.started":"2022-07-09T17:47:39.380480Z","shell.execute_reply":"2022-07-09T17:47:40.790271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}