{"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:35:03.351394Z","iopub.execute_input":"2022-07-09T17:35:03.351850Z","iopub.status.idle":"2022-07-09T17:35:03.683235Z","shell.execute_reply.started":"2022-07-09T17:35:03.351751Z","shell.execute_reply":"2022-07-09T17:35:03.682076Z"},"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-may-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:35:03.685514Z","iopub.execute_input":"2022-07-09T17:35:03.685920Z","iopub.status.idle":"2022-07-09T17:35:03.690066Z","shell.execute_reply.started":"2022-07-09T17:35:03.685884Z","shell.execute_reply":"2022-07-09T17:35:03.689305Z"},"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:35:03.691575Z","iopub.execute_input":"2022-07-09T17:35:03.692090Z","iopub.status.idle":"2022-07-09T17:35:04.021382Z","shell.execute_reply.started":"2022-07-09T17:35:03.692025Z","shell.execute_reply":"2022-07-09T17:35:04.020569Z"},"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:35:04.022362Z","iopub.execute_input":"2022-07-09T17:35:04.022773Z","iopub.status.idle":"2022-07-09T17:35:26.368425Z","shell.execute_reply.started":"2022-07-09T17:35:04.022742Z","shell.execute_reply":"2022-07-09T17:35:26.367247Z"},"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)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T17:35:26.369996Z","iopub.execute_input":"2022-07-09T17:35:26.370299Z","iopub.status.idle":"2022-07-09T17:35:26.392224Z","shell.execute_reply.started":"2022-07-09T17:35:26.370270Z","shell.execute_reply":"2022-07-09T17:35:26.391161Z"},"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:35:26.393465Z","iopub.execute_input":"2022-07-09T17:35:26.393868Z","iopub.status.idle":"2022-07-09T17:36:17.225121Z","shell.execute_reply.started":"2022-07-09T17:35:26.393837Z","shell.execute_reply":"2022-07-09T17:36:17.224098Z"},"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:36:17.226358Z","iopub.execute_input":"2022-07-09T17:36:17.226655Z","iopub.status.idle":"2022-07-09T17:36:17.935276Z","shell.execute_reply.started":"2022-07-09T17:36:17.226624Z","shell.execute_reply":"2022-07-09T17:36:17.934504Z"},"trusted":true},"execution_count":null,"outputs":[]}]}