{"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":"","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport plotly.express as px\n\n#Feature Engineering\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\n\n#Modelling\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import RandomForestClassifier\n\nfrom sklearn.linear_model import LogisticRegression\n\n#Evaluation\nfrom sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, cohen_kappa_score, roc_auc_score, confusion_matrix\nfrom sklearn.metrics import classification_report\n\nimport os","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:51.330372Z","iopub.execute_input":"2022-07-30T20:35:51.330869Z","iopub.status.idle":"2022-07-30T20:35:53.475923Z","shell.execute_reply.started":"2022-07-30T20:35:51.330778Z","shell.execute_reply":"2022-07-30T20:35:53.474723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/telecom-churn-case-study-hackathon-38/train (1).csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:53.478036Z","iopub.execute_input":"2022-07-30T20:35:53.478501Z","iopub.status.idle":"2022-07-30T20:35:55.611505Z","shell.execute_reply.started":"2022-07-30T20:35:53.478468Z","shell.execute_reply":"2022-07-30T20:35:55.610055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:55.613010Z","iopub.execute_input":"2022-07-30T20:35:55.613352Z","iopub.status.idle":"2022-07-30T20:35:55.657770Z","shell.execute_reply.started":"2022-07-30T20:35:55.613320Z","shell.execute_reply":"2022-07-30T20:35:55.656316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:55.660027Z","iopub.execute_input":"2022-07-30T20:35:55.660559Z","iopub.status.idle":"2022-07-30T20:35:55.690434Z","shell.execute_reply.started":"2022-07-30T20:35:55.660517Z","shell.execute_reply":"2022-07-30T20:35:55.689108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:55.692143Z","iopub.execute_input":"2022-07-30T20:35:55.692772Z","iopub.status.idle":"2022-07-30T20:35:56.540158Z","shell.execute_reply.started":"2022-07-30T20:35:55.692728Z","shell.execute_reply":"2022-07-30T20:35:56.539031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:56.541875Z","iopub.execute_input":"2022-07-30T20:35:56.542557Z","iopub.status.idle":"2022-07-30T20:35:56.550642Z","shell.execute_reply.started":"2022-07-30T20:35:56.542513Z","shell.execute_reply":"2022-07-30T20:35:56.549456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:56.552303Z","iopub.execute_input":"2022-07-30T20:35:56.552894Z","iopub.status.idle":"2022-07-30T20:35:56.646052Z","shell.execute_reply.started":"2022-07-30T20:35:56.552847Z","shell.execute_reply":"2022-07-30T20:35:56.644983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percent_null = df.isnull().sum().sum() / np.product(df.shape) * 100\npercent_null","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:56.647265Z","iopub.execute_input":"2022-07-30T20:35:56.647565Z","iopub.status.idle":"2022-07-30T20:35:56.734142Z","shell.execute_reply.started":"2022-07-30T20:35:56.647530Z","shell.execute_reply":"2022-07-30T20:35:56.733077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colls = []\nfor col in df.columns:\n    null_col = df[col].isnull().sum() / df.shape[0] * 100\n    if null_col>50:\n        colls+=[col]\n    print(\"{} : {:.2f}\".format(col,null_col))","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:56.735534Z","iopub.execute_input":"2022-07-30T20:35:56.735978Z","iopub.status.idle":"2022-07-30T20:35:56.854562Z","shell.execute_reply.started":"2022-07-30T20:35:56.735945Z","shell.execute_reply":"2022-07-30T20:35:56.853558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colls","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:56.858494Z","iopub.execute_input":"2022-07-30T20:35:56.858951Z","iopub.status.idle":"2022-07-30T20:35:56.866024Z","shell.execute_reply.started":"2022-07-30T20:35:56.858918Z","shell.execute_reply":"2022-07-30T20:35:56.864921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.drop(colls,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:56.867754Z","iopub.execute_input":"2022-07-30T20:35:56.868181Z","iopub.status.idle":"2022-07-30T20:35:56.902274Z","shell.execute_reply.started":"2022-07-30T20:35:56.868129Z","shell.execute_reply":"2022-07-30T20:35:56.901046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percent_null = df.isnull().sum().sum() / np.product(df.shape) * 100\npercent_null","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:56.903312Z","iopub.execute_input":"2022-07-30T20:35:56.903639Z","iopub.status.idle":"2022-07-30T20:35:56.980798Z","shell.execute_reply.started":"2022-07-30T20:35:56.903595Z","shell.execute_reply":"2022-07-30T20:35:56.979707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.dropna()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:56.982125Z","iopub.execute_input":"2022-07-30T20:35:56.982545Z","iopub.status.idle":"2022-07-30T20:35:57.087525Z","shell.execute_reply.started":"2022-07-30T20:35:56.982512Z","shell.execute_reply":"2022-07-30T20:35:57.086443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.089219Z","iopub.execute_input":"2022-07-30T20:35:57.089652Z","iopub.status.idle":"2022-07-30T20:35:57.155679Z","shell.execute_reply.started":"2022-07-30T20:35:57.089591Z","shell.execute_reply":"2022-07-30T20:35:57.154631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colls = []\nfor col in df.columns:\n    if df[col].dtype == object:\n        colls+=[col]\n        print(col)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.157265Z","iopub.execute_input":"2022-07-30T20:35:57.157744Z","iopub.status.idle":"2022-07-30T20:35:57.170742Z","shell.execute_reply.started":"2022-07-30T20:35:57.157699Z","shell.execute_reply":"2022-07-30T20:35:57.169625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[colls]","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.172180Z","iopub.execute_input":"2022-07-30T20:35:57.172597Z","iopub.status.idle":"2022-07-30T20:35:57.197435Z","shell.execute_reply.started":"2022-07-30T20:35:57.172556Z","shell.execute_reply":"2022-07-30T20:35:57.196430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.drop(colls,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.199603Z","iopub.execute_input":"2022-07-30T20:35:57.199930Z","iopub.status.idle":"2022-07-30T20:35:57.226812Z","shell.execute_reply.started":"2022-07-30T20:35:57.199901Z","shell.execute_reply":"2022-07-30T20:35:57.225824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.228581Z","iopub.execute_input":"2022-07-30T20:35:57.228912Z","iopub.status.idle":"2022-07-30T20:35:57.252804Z","shell.execute_reply.started":"2022-07-30T20:35:57.228882Z","shell.execute_reply":"2022-07-30T20:35:57.251704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colls = []\nfor col in df.columns:\n    if df[col].nunique() ==1:\n        colls+=[col]\n    print('{} : {}'.format(col,df[col].nunique()))","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.254164Z","iopub.execute_input":"2022-07-30T20:35:57.254904Z","iopub.status.idle":"2022-07-30T20:35:57.526332Z","shell.execute_reply.started":"2022-07-30T20:35:57.254867Z","shell.execute_reply":"2022-07-30T20:35:57.525173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[colls]","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.527998Z","iopub.execute_input":"2022-07-30T20:35:57.528449Z","iopub.status.idle":"2022-07-30T20:35:57.559718Z","shell.execute_reply.started":"2022-07-30T20:35:57.528405Z","shell.execute_reply":"2022-07-30T20:35:57.558646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.drop(colls,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.561120Z","iopub.execute_input":"2022-07-30T20:35:57.561404Z","iopub.status.idle":"2022-07-30T20:35:57.588253Z","shell.execute_reply.started":"2022-07-30T20:35:57.561379Z","shell.execute_reply":"2022-07-30T20:35:57.586953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.590548Z","iopub.execute_input":"2022-07-30T20:35:57.591272Z","iopub.status.idle":"2022-07-30T20:35:57.880550Z","shell.execute_reply.started":"2022-07-30T20:35:57.591223Z","shell.execute_reply":"2022-07-30T20:35:57.879422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colls = []\nfor col in df.columns:\n    if df[col].nunique() <20:\n        colls+=[col]\n        print('{} : {}'.format(col,df[col].nunique()))","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:57.882381Z","iopub.execute_input":"2022-07-30T20:35:57.883063Z","iopub.status.idle":"2022-07-30T20:35:58.019781Z","shell.execute_reply.started":"2022-07-30T20:35:57.883025Z","shell.execute_reply":"2022-07-30T20:35:58.017688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def category_counts(col):\n    plt.figure(figsize=(12,8));\n    sns.countplot(x=df[col],palette='RdYlGn');\n    plt.xlabel(col);\n    plt.ylabel('Counts');\n    plt.title(f\"{col} Value Counts\");\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:58.021447Z","iopub.execute_input":"2022-07-30T20:35:58.021933Z","iopub.status.idle":"2022-07-30T20:35:58.031627Z","shell.execute_reply.started":"2022-07-30T20:35:58.021885Z","shell.execute_reply":"2022-07-30T20:35:58.029218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in colls:\n    category_counts(col)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:58.033503Z","iopub.execute_input":"2022-07-30T20:35:58.039906Z","iopub.status.idle":"2022-07-30T20:35:59.638094Z","shell.execute_reply.started":"2022-07-30T20:35:58.039851Z","shell.execute_reply":"2022-07-30T20:35:59.637024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.639517Z","iopub.execute_input":"2022-07-30T20:35:59.640183Z","iopub.status.idle":"2022-07-30T20:35:59.672423Z","shell.execute_reply.started":"2022-07-30T20:35:59.640148Z","shell.execute_reply":"2022-07-30T20:35:59.671321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df.drop(['churn_probability','id'],axis=1)\ny=df['churn_probability']","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.673767Z","iopub.execute_input":"2022-07-30T20:35:59.674083Z","iopub.status.idle":"2022-07-30T20:35:59.697893Z","shell.execute_reply.started":"2022-07-30T20:35:59.674044Z","shell.execute_reply":"2022-07-30T20:35:59.697001Z"},"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.30,random_state=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.704037Z","iopub.execute_input":"2022-07-30T20:35:59.705229Z","iopub.status.idle":"2022-07-30T20:35:59.772916Z","shell.execute_reply.started":"2022-07-30T20:35:59.705188Z","shell.execute_reply":"2022-07-30T20:35:59.771967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.774286Z","iopub.execute_input":"2022-07-30T20:35:59.774646Z","iopub.status.idle":"2022-07-30T20:35:59.779326Z","shell.execute_reply.started":"2022-07-30T20:35:59.774593Z","shell.execute_reply":"2022-07-30T20:35:59.778152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalized_x_train = pd.DataFrame(scaler.fit_transform(X_train),columns = X_train.columns)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.780999Z","iopub.execute_input":"2022-07-30T20:35:59.781889Z","iopub.status.idle":"2022-07-30T20:35:59.899787Z","shell.execute_reply.started":"2022-07-30T20:35:59.781844Z","shell.execute_reply":"2022-07-30T20:35:59.898521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalized_x_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.900980Z","iopub.execute_input":"2022-07-30T20:35:59.902331Z","iopub.status.idle":"2022-07-30T20:35:59.929717Z","shell.execute_reply.started":"2022-07-30T20:35:59.902294Z","shell.execute_reply":"2022-07-30T20:35:59.928860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalized_x_test = pd.DataFrame(scaler.transform(X_test),columns = X_test.columns)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.931194Z","iopub.execute_input":"2022-07-30T20:35:59.931981Z","iopub.status.idle":"2022-07-30T20:35:59.959484Z","shell.execute_reply.started":"2022-07-30T20:35:59.931938Z","shell.execute_reply":"2022-07-30T20:35:59.958650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def confusion_matrix_plot(matrix=None,classes=None,name='Logistic Regression'):\n    plt.figure(figsize=(12,10))\n    cmap = \"YlGnBu\"\n    ax= plt.subplot()\n    sns.heatmap(matrix, annot=True, fmt='g', ax=ax, cmap=cmap);  #annot=True to annotate cells, ftm='g' to disable scientific notation\n    plt.savefig('/kaggle/working/img1.png')\n    # labels, title and ticks\n    ax.set_xlabel('Predicted labels',fontsize = 15,fontweight = 3);\n    ax.set_ylabel('True labels',fontsize = 15,fontweight = 3); \n    ax.set_title('Confusion Matrix of '+name,fontsize = 25,fontweight = 5); \n    ax.xaxis.set_ticklabels(classes); \n    ax.yaxis.set_ticklabels(classes[::-1]);\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.960972Z","iopub.execute_input":"2022-07-30T20:35:59.961505Z","iopub.status.idle":"2022-07-30T20:35:59.969948Z","shell.execute_reply.started":"2022-07-30T20:35:59.961472Z","shell.execute_reply":"2022-07-30T20:35:59.968752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def cal_score(x_test=None,y_test=None,model=None,name=None):\n    predictions = model.predict(x_test)\n    labels=y_test\n    matrix = confusion_matrix(predictions, labels)\n    print(matrix)\n    print('\\n')\n\n    f1 = f1_score(predictions, labels, average='weighted')\n    print(f'F1 Score: {f1}')\n    print('\\n')\n    classes=[False,True]\n    print(classification_report(predictions, labels, labels=classes))\n    \n    confusion_matrix_plot(matrix = matrix,classes = classes,name = name)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.971365Z","iopub.execute_input":"2022-07-30T20:35:59.972362Z","iopub.status.idle":"2022-07-30T20:35:59.983027Z","shell.execute_reply.started":"2022-07-30T20:35:59.972319Z","shell.execute_reply":"2022-07-30T20:35:59.981810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr = LogisticRegression(max_iter=10000)\nlr.fit(normalized_x_train,y_train)\ncal_score(x_test=normalized_x_test,y_test=y_test,model=lr,name='Logistic Regression')","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:35:59.984875Z","iopub.execute_input":"2022-07-30T20:35:59.985198Z","iopub.status.idle":"2022-07-30T20:36:04.024264Z","shell.execute_reply.started":"2022-07-30T20:35:59.985170Z","shell.execute_reply":"2022-07-30T20:36:04.023154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dr = DecisionTreeClassifier()\ndr.fit(normalized_x_train,y_train)\ncal_score(x_test=normalized_x_test,y_test=y_test,model=dr,name='Decision Tree')","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:04.025506Z","iopub.execute_input":"2022-07-30T20:36:04.026897Z","iopub.status.idle":"2022-07-30T20:36:13.925401Z","shell.execute_reply.started":"2022-07-30T20:36:04.026864Z","shell.execute_reply":"2022-07-30T20:36:13.924004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(normalized_x_train,y_train)\ncal_score(x_test=normalized_x_test,y_test=y_test,model=rf,name='Random Forest')","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:13.927149Z","iopub.execute_input":"2022-07-30T20:36:13.927496Z","iopub.status.idle":"2022-07-30T20:36:51.721999Z","shell.execute_reply.started":"2022-07-30T20:36:13.927466Z","shell.execute_reply":"2022-07-30T20:36:51.720819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame({\n    'Feature':rf.feature_names_in_,\n    'Importance':rf.feature_importances_}).sort_values(by='Importance',ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:51.723709Z","iopub.execute_input":"2022-07-30T20:36:51.724994Z","iopub.status.idle":"2022-07-30T20:36:51.754978Z","shell.execute_reply.started":"2022-07-30T20:36:51.724943Z","shell.execute_reply":"2022-07-30T20:36:51.754102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('../input/telecom-churn-case-study-hackathon-38/test (1).csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:51.756024Z","iopub.execute_input":"2022-07-30T20:36:51.756945Z","iopub.status.idle":"2022-07-30T20:36:52.656588Z","shell.execute_reply.started":"2022-07-30T20:36:51.756906Z","shell.execute_reply":"2022-07-30T20:36:52.655593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sol_df = pd.read_csv('../input/telecom-churn-case-study-hackathon-38/solution (1).csv')\ndict_df = pd.read_csv('../input/telecom-churn-case-study-hackathon-38/data_dictionary.csv')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.657948Z","iopub.execute_input":"2022-07-30T20:36:52.658373Z","iopub.status.idle":"2022-07-30T20:36:52.678338Z","shell.execute_reply.started":"2022-07-30T20:36:52.658333Z","shell.execute_reply":"2022-07-30T20:36:52.677182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.679918Z","iopub.execute_input":"2022-07-30T20:36:52.680542Z","iopub.status.idle":"2022-07-30T20:36:52.707533Z","shell.execute_reply.started":"2022-07-30T20:36:52.680495Z","shell.execute_reply":"2022-07-30T20:36:52.706768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.708745Z","iopub.execute_input":"2022-07-30T20:36:52.709601Z","iopub.status.idle":"2022-07-30T20:36:52.753596Z","shell.execute_reply.started":"2022-07-30T20:36:52.709564Z","shell.execute_reply":"2022-07-30T20:36:52.752472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = test_df['id']","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.754912Z","iopub.execute_input":"2022-07-30T20:36:52.755418Z","iopub.status.idle":"2022-07-30T20:36:52.760093Z","shell.execute_reply.started":"2022-07-30T20:36:52.755385Z","shell.execute_reply":"2022-07-30T20:36:52.758934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = test_df[X.columns]","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.761742Z","iopub.execute_input":"2022-07-30T20:36:52.762037Z","iopub.status.idle":"2022-07-30T20:36:52.782438Z","shell.execute_reply.started":"2022-07-30T20:36:52.762010Z","shell.execute_reply":"2022-07-30T20:36:52.781085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.784222Z","iopub.execute_input":"2022-07-30T20:36:52.784865Z","iopub.status.idle":"2022-07-30T20:36:52.802293Z","shell.execute_reply.started":"2022-07-30T20:36:52.784830Z","shell.execute_reply":"2022-07-30T20:36:52.801301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percent_null = test_df.isnull().sum().sum() / np.product(test_df.shape) * 100\npercent_null","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.803998Z","iopub.execute_input":"2022-07-30T20:36:52.804769Z","iopub.status.idle":"2022-07-30T20:36:52.822341Z","shell.execute_reply.started":"2022-07-30T20:36:52.804724Z","shell.execute_reply":"2022-07-30T20:36:52.821167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in test_df.columns:\n    null_col = test_df[col].isnull().sum() / test_df.shape[0] * 100\n    print(\"{} : {:.2f}\".format(col,null_col))","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.823998Z","iopub.execute_input":"2022-07-30T20:36:52.824745Z","iopub.status.idle":"2022-07-30T20:36:52.869904Z","shell.execute_reply.started":"2022-07-30T20:36:52.824700Z","shell.execute_reply":"2022-07-30T20:36:52.868685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['jun_vbc_3g'].mode()[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.871508Z","iopub.execute_input":"2022-07-30T20:36:52.872110Z","iopub.status.idle":"2022-07-30T20:36:52.881043Z","shell.execute_reply.started":"2022-07-30T20:36:52.872073Z","shell.execute_reply":"2022-07-30T20:36:52.880230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in test_df.columns:\n    null_col = test_df[col].isnull().sum() / test_df.shape[0] * 100\n    if null_col > 0:\n        test_df[col] = test_df[col].fillna(test_df[col].mode()[0])","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:52.882359Z","iopub.execute_input":"2022-07-30T20:36:52.882921Z","iopub.status.idle":"2022-07-30T20:36:53.026854Z","shell.execute_reply.started":"2022-07-30T20:36:52.882889Z","shell.execute_reply":"2022-07-30T20:36:53.021212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:53.028608Z","iopub.execute_input":"2022-07-30T20:36:53.029428Z","iopub.status.idle":"2022-07-30T20:36:53.051792Z","shell.execute_reply.started":"2022-07-30T20:36:53.029378Z","shell.execute_reply":"2022-07-30T20:36:53.050761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_normalized_x_test = pd.DataFrame(scaler.transform(test_df),columns = test_df.columns)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:53.053190Z","iopub.execute_input":"2022-07-30T20:36:53.054196Z","iopub.status.idle":"2022-07-30T20:36:53.096552Z","shell.execute_reply.started":"2022-07-30T20:36:53.054159Z","shell.execute_reply":"2022-07-30T20:36:53.095170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"probabilities = rf.predict(final_normalized_x_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:53.098413Z","iopub.execute_input":"2022-07-30T20:36:53.099429Z","iopub.status.idle":"2022-07-30T20:36:53.879376Z","shell.execute_reply.started":"2022-07-30T20:36:53.099382Z","shell.execute_reply":"2022-07-30T20:36:53.878119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"probabilities.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:53.881100Z","iopub.execute_input":"2022-07-30T20:36:53.881573Z","iopub.status.idle":"2022-07-30T20:36:53.889765Z","shell.execute_reply.started":"2022-07-30T20:36:53.881515Z","shell.execute_reply":"2022-07-30T20:36:53.888499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:53.891328Z","iopub.execute_input":"2022-07-30T20:36:53.892086Z","iopub.status.idle":"2022-07-30T20:36:53.904607Z","shell.execute_reply.started":"2022-07-30T20:36:53.892046Z","shell.execute_reply":"2022-07-30T20:36:53.903768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sol_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:53.907675Z","iopub.execute_input":"2022-07-30T20:36:53.910022Z","iopub.status.idle":"2022-07-30T20:36:53.919317Z","shell.execute_reply.started":"2022-07-30T20:36:53.909984Z","shell.execute_reply":"2022-07-30T20:36:53.918020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame({'id':a,'churn_probability':probabilities})","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:53.920398Z","iopub.execute_input":"2022-07-30T20:36:53.921317Z","iopub.status.idle":"2022-07-30T20:36:53.926510Z","shell.execute_reply.started":"2022-07-30T20:36:53.921282Z","shell.execute_reply":"2022-07-30T20:36:53.925739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('Submission1.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:36:53.927714Z","iopub.execute_input":"2022-07-30T20:36:53.928187Z","iopub.status.idle":"2022-07-30T20:36:53.989333Z","shell.execute_reply.started":"2022-07-30T20:36:53.928156Z","shell.execute_reply":"2022-07-30T20:36:53.988479Z"},"trusted":true},"execution_count":null,"outputs":[]}]}