{"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 plotly.express as px\nimport plotly.graph_objects as go\nimport plotly.figure_factory as ff\nfrom plotly.subplots import make_subplots\nimport matplotlib.pyplot as plt\nfrom colorama import Fore\nfrom pandas_profiling import ProfileReport\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:16:18.723475Z","iopub.execute_input":"2022-08-02T10:16:18.723911Z","iopub.status.idle":"2022-08-02T10:16:18.730212Z","shell.execute_reply.started":"2022-08-02T10:16:18.723875Z","shell.execute_reply":"2022-08-02T10:16:18.729034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":{"execution":{"iopub.status.busy":"2022-08-02T10:16:32.710280Z","iopub.execute_input":"2022-08-02T10:16:32.710671Z","iopub.status.idle":"2022-08-02T10:16:32.718852Z","shell.execute_reply.started":"2022-08-02T10:16:32.710640Z","shell.execute_reply":"2022-08-02T10:16:32.717817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/tabular-playground-series-aug-2022/train.csv')\ntest_df = pd.read_csv('../input/tabular-playground-series-aug-2022/test.csv')\nsub_df = pd.read_csv('../input/tabular-playground-series-aug-2022/sample_submission.csv')\n\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:16:34.176342Z","iopub.execute_input":"2022-08-02T10:16:34.177200Z","iopub.status.idle":"2022-08-02T10:16:34.381312Z","shell.execute_reply.started":"2022-08-02T10:16:34.177148Z","shell.execute_reply":"2022-08-02T10:16:34.380132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_cols = train_df.drop(['id', 'failure'], axis=1).columns\n\nnumerical_columns = train_df[feature_cols].select_dtypes(include=['int64','float64']).columns\ncategorical_columns = train_df[feature_cols].select_dtypes(exclude=['int64','float64']).columns\n\nprint(len(numerical_columns), len(categorical_columns))","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:16:35.430500Z","iopub.execute_input":"2022-08-02T10:16:35.430898Z","iopub.status.idle":"2022-08-02T10:16:35.450132Z","shell.execute_reply.started":"2022-08-02T10:16:35.430866Z","shell.execute_reply":"2022-08-02T10:16:35.449287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_indexs = train_df.index\ntest_indexs = test_df.index\n\ndf =  pd.concat(objs=[train_df, test_df], axis=0).reset_index(drop=True)\ndf = df.drop(['id', 'failure'], axis=1)\n\nprint(df.shape)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:16:36.036149Z","iopub.execute_input":"2022-08-02T10:16:36.038823Z","iopub.status.idle":"2022-08-02T10:16:36.076691Z","shell.execute_reply.started":"2022-08-02T10:16:36.038779Z","shell.execute_reply":"2022-08-02T10:16:36.075356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"profile = ProfileReport(train_df)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:16:36.451879Z","iopub.execute_input":"2022-08-02T10:16:36.452258Z","iopub.status.idle":"2022-08-02T10:16:36.460022Z","shell.execute_reply.started":"2022-08-02T10:16:36.452226Z","shell.execute_reply":"2022-08-02T10:16:36.458742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"profile","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:16:37.300807Z","iopub.execute_input":"2022-08-02T10:16:37.301209Z","iopub.status.idle":"2022-08-02T10:19:16.310429Z","shell.execute_reply.started":"2022-08-02T10:16:37.301171Z","shell.execute_reply":"2022-08-02T10:19:16.308844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.histogram(train_df, x='failure')\nfig.update_layout(\n    title_text='Target distribution',\n    xaxis_title_text='Value', \n    yaxis_title_text='Count', \n    bargap=0.2,\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:19:47.627352Z","iopub.execute_input":"2022-08-02T10:19:47.628263Z","iopub.status.idle":"2022-08-02T10:19:47.693369Z","shell.execute_reply.started":"2022-08-02T10:19:47.628217Z","shell.execute_reply":"2022-08-02T10:19:47.692578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df[numerical_columns].columns)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:19:53.659177Z","iopub.execute_input":"2022-08-02T10:19:53.659649Z","iopub.status.idle":"2022-08-02T10:19:53.668863Z","shell.execute_reply.started":"2022-08-02T10:19:53.659613Z","shell.execute_reply":"2022-08-02T10:19:53.667931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_rows, num_cols = 5,5\nf, axes = plt.subplots(nrows=num_rows, ncols=num_cols, figsize=(12, 12))\nf.suptitle('Distribution of Features', fontsize=16)\n\nfor index, column in enumerate(df[numerical_columns].columns):\n    i,j = (index // num_cols, index % num_cols)\n    sns.kdeplot(train_df.loc[train_df['failure'] == 0, column], color='m', shade=True, ax=axes[i,j])\n    sns.kdeplot(train_df.loc[train_df['failure'] == 1, column], color='b', shade=True, ax=axes[i,j])\n\nfor i in range(1,5): \n    f.delaxes(axes[4,i])\nf","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:19:54.287563Z","iopub.execute_input":"2022-08-02T10:19:54.288328Z","iopub.status.idle":"2022-08-02T10:19:59.899824Z","shell.execute_reply.started":"2022-08-02T10:19:54.288278Z","shell.execute_reply":"2022-08-02T10:19:59.898588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr = df[numerical_columns].corr().abs()\nmask = np.triu(np.ones_like(corr, dtype=np.bool))\n\nfig, ax = plt.subplots(figsize=(12, 12))\n\n# plot heatmap\nsns.heatmap(corr, mask=mask, annot=True, fmt=\".2f\", cmap='coolwarm',\n            cbar_kws={\"shrink\": .75}, vmin=0, vmax=1)\n\nplt.yticks(rotation=0)\nfig","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:27:47.974053Z","iopub.execute_input":"2022-08-02T10:27:47.974757Z","iopub.status.idle":"2022-08-02T10:27:50.976151Z","shell.execute_reply.started":"2022-08-02T10:27:47.974701Z","shell.execute_reply":"2022-08-02T10:27:50.974927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Credit : \nbackground_color = \"#f0f4f9\"\n\nfig = plt.figure(figsize=(12, 16), facecolor=background_color)\ngs = fig.add_gridspec(1, 1)\nax0 = fig.add_subplot(gs[0, 0])\n\nax0.set_facecolor(background_color)\nax0.text(-0.01, -1.26, 'Correlation of Continuous Features with Target', fontsize=20, fontweight='bold', fontfamily='serif')\nax0.text(+0.01, -0.7, 'There is no features that pass 0.15 correlation with target(Failure)', fontsize=13, fontweight='light', fontfamily='serif')\n\nchart_df = pd.DataFrame(train_df[numerical_columns].corrwith(train_df['failure']))\nchart_df.columns = ['corr']\nsns.barplot(x=chart_df['corr'], y=chart_df.index, ax=ax0, color=\"#496595\", zorder=3, edgecolor='black', linewidth=1.75)\nax0.grid(which='major', axis='y', zorder=0, color='gray', linestyle=':', dashes=(1,5))\nax0.set_ylabel('')\n\nfor s in [\"top\",\"right\", 'left']:\n    ax0.spines[s].set_visible(False)\n\nfig","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:29:48.877069Z","iopub.execute_input":"2022-08-02T10:29:48.877555Z","iopub.status.idle":"2022-08-02T10:29:49.267006Z","shell.execute_reply.started":"2022-08-02T10:29:48.877513Z","shell.execute_reply":"2022-08-02T10:29:49.265796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_0_df = train_df.loc[train_df['failure'] == 0]\ntrain_1_df = train_df.loc[train_df['failure'] == 1]\n\nnum_rows, num_cols = 3,1\nfig = make_subplots(rows=num_rows, cols=num_cols)\n\nfor index, column in enumerate(df[categorical_columns].columns):\n    i,j = ((index // num_cols)+1, (index % num_cols)+1)\n    data = train_0_df.groupby(column)[column].count().sort_values(ascending=False)\n    data = data if len(data) < 10 else data[:10]\n    fig.add_trace(go.Bar(\n        x = data.index,\n        y = data.values,\n        name='Label: 0',\n    ), row=i, col=j)\n\n    data = train_1_df.groupby(column)[column].count().sort_values(ascending=False)\n    data = data if len(data) < 10 else data[:10]\n    fig.add_trace(go.Bar(\n        x = data.index,\n        y = data.values,\n        name='Label: 1'\n    ), row=i, col=j)\n    \n    fig.update_xaxes(title=column, row=i, col=j)\n    fig.update_layout(barmode='stack')\n    \nfig.update_layout(\n    autosize=False,\n    width=600,\n    height=1200,\n    showlegend=False,\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-02T10:21:55.787435Z","iopub.execute_input":"2022-08-02T10:21:55.790927Z","iopub.status.idle":"2022-08-02T10:21:55.905230Z","shell.execute_reply.started":"2022-08-02T10:21:55.790869Z","shell.execute_reply":"2022-08-02T10:21:55.903945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}