{"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 numpy as np\nimport pandas as pd\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\ntrain_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')","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:03:14.600553Z","iopub.execute_input":"2022-08-11T16:03:14.600904Z","iopub.status.idle":"2022-08-11T16:03:14.728707Z","shell.execute_reply.started":"2022-08-11T16:03:14.600873Z","shell.execute_reply":"2022-08-11T16:03:14.727773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-08-11T14:57:29.649143Z","iopub.execute_input":"2022-08-11T14:57:29.649523Z","iopub.status.idle":"2022-08-11T14:57:29.686730Z","shell.execute_reply.started":"2022-08-11T14:57:29.649485Z","shell.execute_reply":"2022-08-11T14:57:29.685618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T14:57:29.688112Z","iopub.execute_input":"2022-08-11T14:57:29.688544Z","iopub.status.idle":"2022-08-11T14:57:29.707452Z","shell.execute_reply.started":"2022-08-11T14:57:29.688508Z","shell.execute_reply":"2022-08-11T14:57:29.706381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.drop(columns=['id','product_code','attribute_0','attribute_1','attribute_2','attribute_3','measurement_0','measurement_1','measurement_2'],axis=1,inplace=True)\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:03:19.146758Z","iopub.execute_input":"2022-08-11T16:03:19.147131Z","iopub.status.idle":"2022-08-11T16:03:19.172074Z","shell.execute_reply.started":"2022-08-11T16:03:19.147098Z","shell.execute_reply":"2022-08-11T16:03:19.170845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20,25))\nsns.heatmap(train_df.corr(),annot=True,cmap='viridis')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T14:58:49.312953Z","iopub.execute_input":"2022-08-11T14:58:49.313637Z","iopub.status.idle":"2022-08-11T14:58:50.995742Z","shell.execute_reply.started":"2022-08-11T14:58:49.313601Z","shell.execute_reply":"2022-08-11T14:58:50.994887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-08-11T14:59:21.615915Z","iopub.execute_input":"2022-08-11T14:59:21.616644Z","iopub.status.idle":"2022-08-11T14:59:21.655290Z","shell.execute_reply.started":"2022-08-11T14:59:21.616607Z","shell.execute_reply":"2022-08-11T14:59:21.654184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.drop(columns=['id','product_code','attribute_0','attribute_1','attribute_2','attribute_3','measurement_0','measurement_1','measurement_2'],axis=1,inplace=True)\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:05:05.307619Z","iopub.execute_input":"2022-08-11T16:05:05.308000Z","iopub.status.idle":"2022-08-11T16:05:05.334459Z","shell.execute_reply.started":"2022-08-11T16:05:05.307963Z","shell.execute_reply":"2022-08-11T16:05:05.333491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train_df.drop(columns='failure',axis=1)\ny=train_df['failure']","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:00:24.560273Z","iopub.execute_input":"2022-08-11T15:00:24.560862Z","iopub.status.idle":"2022-08-11T15:00:24.567732Z","shell.execute_reply.started":"2022-08-11T15:00:24.560826Z","shell.execute_reply":"2022-08-11T15:00:24.566467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:00:27.058270Z","iopub.execute_input":"2022-08-11T15:00:27.058624Z","iopub.status.idle":"2022-08-11T15:00:27.087735Z","shell.execute_reply.started":"2022-08-11T15:00:27.058592Z","shell.execute_reply":"2022-08-11T15:00:27.086598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:00:33.787002Z","iopub.execute_input":"2022-08-11T15:00:33.787567Z","iopub.status.idle":"2022-08-11T15:00:33.795223Z","shell.execute_reply.started":"2022-08-11T15:00:33.787532Z","shell.execute_reply":"2022-08-11T15:00:33.794267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.impute import KNNImputer\nknn=KNNImputer()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:12:11.633013Z","iopub.execute_input":"2022-08-11T15:12:11.634031Z","iopub.status.idle":"2022-08-11T15:12:11.687789Z","shell.execute_reply.started":"2022-08-11T15:12:11.633985Z","shell.execute_reply":"2022-08-11T15:12:11.686840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_impute=knn.fit_transform(x)\nx_impute","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:12:58.308808Z","iopub.execute_input":"2022-08-11T15:12:58.309760Z","iopub.status.idle":"2022-08-11T15:13:29.610818Z","shell.execute_reply.started":"2022-08-11T15:12:58.309723Z","shell.execute_reply":"2022-08-11T15:13:29.609781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=pd.DataFrame(x_impute,columns=x.columns)\nx","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:13:32.201920Z","iopub.execute_input":"2022-08-11T15:13:32.202313Z","iopub.status.idle":"2022-08-11T15:13:32.229924Z","shell.execute_reply.started":"2022-08-11T15:13:32.202282Z","shell.execute_reply":"2022-08-11T15:13:32.229007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:13:43.921564Z","iopub.execute_input":"2022-08-11T15:13:43.921959Z","iopub.status.idle":"2022-08-11T15:13:43.934003Z","shell.execute_reply.started":"2022-08-11T15:13:43.921903Z","shell.execute_reply":"2022-08-11T15:13:43.932992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df_impute=knn.transform(test_df)\ntest_df=pd.DataFrame(test_df_impute,columns=test_df.columns)\ntest_df.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:14:32.312329Z","iopub.execute_input":"2022-08-11T15:14:32.312754Z","iopub.status.idle":"2022-08-11T15:14:55.616239Z","shell.execute_reply.started":"2022-08-11T15:14:32.312717Z","shell.execute_reply":"2022-08-11T15:14:55.614970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:00:41.512607Z","iopub.execute_input":"2022-08-11T15:00:41.513217Z","iopub.status.idle":"2022-08-11T15:00:41.524432Z","shell.execute_reply.started":"2022-08-11T15:00:41.513174Z","shell.execute_reply":"2022-08-11T15:00:41.523130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:01:37.864532Z","iopub.execute_input":"2022-08-11T15:01:37.865386Z","iopub.status.idle":"2022-08-11T15:01:37.994775Z","shell.execute_reply.started":"2022-08-11T15:01:37.865348Z","shell.execute_reply":"2022-08-11T15:01:37.993837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr=LogisticRegression()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:01:49.827739Z","iopub.execute_input":"2022-08-11T15:01:49.828113Z","iopub.status.idle":"2022-08-11T15:01:49.832891Z","shell.execute_reply.started":"2022-08-11T15:01:49.828082Z","shell.execute_reply":"2022-08-11T15:01:49.831579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import GridSearchCV\n\nparam_grid={'penalty' : ['l1', 'l2', 'elasticnet', 'none'],\n            'solver' : ['liblinear', 'sag', 'saga'],\n            'max_iter':[100,750,3000]\n}","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:08:59.718077Z","iopub.execute_input":"2022-08-11T15:08:59.718640Z","iopub.status.idle":"2022-08-11T15:08:59.724464Z","shell.execute_reply.started":"2022-08-11T15:08:59.718606Z","shell.execute_reply":"2022-08-11T15:08:59.723450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(param_grid)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:09:01.800639Z","iopub.execute_input":"2022-08-11T15:09:01.801489Z","iopub.status.idle":"2022-08-11T15:09:01.806912Z","shell.execute_reply.started":"2022-08-11T15:09:01.801441Z","shell.execute_reply":"2022-08-11T15:09:01.805787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings(action='ignore')\nlr_grid=GridSearchCV(estimator=lr,param_grid=param_grid,cv=7)\nlr_grid.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:16:16.462799Z","iopub.execute_input":"2022-08-11T15:16:16.463527Z","iopub.status.idle":"2022-08-11T15:23:28.809806Z","shell.execute_reply.started":"2022-08-11T15:16:16.463490Z","shell.execute_reply":"2022-08-11T15:23:28.808884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr_grid.best_score_","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:24:46.792540Z","iopub.execute_input":"2022-08-11T15:24:46.792908Z","iopub.status.idle":"2022-08-11T15:24:46.800039Z","shell.execute_reply.started":"2022-08-11T15:24:46.792875Z","shell.execute_reply":"2022-08-11T15:24:46.798994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_grid=lr_grid.best_estimator_\nbest_grid","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:24:49.992076Z","iopub.execute_input":"2022-08-11T15:24:49.992436Z","iopub.status.idle":"2022-08-11T15:24:49.999340Z","shell.execute_reply.started":"2022-08-11T15:24:49.992404Z","shell.execute_reply":"2022-08-11T15:24:49.998258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=best_grid.predict(test_df)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:25:34.005224Z","iopub.execute_input":"2022-08-11T15:25:34.005808Z","iopub.status.idle":"2022-08-11T15:25:34.016776Z","shell.execute_reply.started":"2022-08-11T15:25:34.005773Z","shell.execute_reply":"2022-08-11T15:25:34.014160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission=pd.DataFrame({'id':sub_df['id'],'failure':y_pred})\nsubmission","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:26:07.878892Z","iopub.execute_input":"2022-08-11T15:26:07.879721Z","iopub.status.idle":"2022-08-11T15:26:07.895051Z","shell.execute_reply.started":"2022-08-11T15:26:07.879682Z","shell.execute_reply":"2022-08-11T15:26:07.893980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['failure'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:26:21.005367Z","iopub.execute_input":"2022-08-11T15:26:21.005860Z","iopub.status.idle":"2022-08-11T15:26:21.015753Z","shell.execute_reply.started":"2022-08-11T15:26:21.005802Z","shell.execute_reply":"2022-08-11T15:26:21.014693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('tps_august_2022.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:26:51.518926Z","iopub.execute_input":"2022-08-11T15:26:51.519854Z","iopub.status.idle":"2022-08-11T15:26:51.545310Z","shell.execute_reply.started":"2022-08-11T15:26:51.519805Z","shell.execute_reply":"2022-08-11T15:26:51.544365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from imblearn.over_sampling import SMOTE\nsmote=SMOTE()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:30:23.738781Z","iopub.execute_input":"2022-08-11T15:30:23.739776Z","iopub.status.idle":"2022-08-11T15:30:23.744861Z","shell.execute_reply.started":"2022-08-11T15:30:23.739738Z","shell.execute_reply":"2022-08-11T15:30:23.743484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_sm,y_sm=smote.fit_resample(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:31:14.719282Z","iopub.execute_input":"2022-08-11T15:31:14.720335Z","iopub.status.idle":"2022-08-11T15:31:15.465911Z","shell.execute_reply.started":"2022-08-11T15:31:14.720294Z","shell.execute_reply":"2022-08-11T15:31:15.464920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_sm.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:31:26.548533Z","iopub.execute_input":"2022-08-11T15:31:26.549013Z","iopub.status.idle":"2022-08-11T15:31:26.558556Z","shell.execute_reply.started":"2022-08-11T15:31:26.548967Z","shell.execute_reply":"2022-08-11T15:31:26.557639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_grid.fit(x_sm,y_sm)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:32:19.552921Z","iopub.execute_input":"2022-08-11T15:32:19.553315Z","iopub.status.idle":"2022-08-11T15:32:21.104438Z","shell.execute_reply.started":"2022-08-11T15:32:19.553284Z","shell.execute_reply":"2022-08-11T15:32:21.103328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred2=best_grid.predict(test_df)\nsubmission2=pd.DataFrame({'id':sub_df['id'],'failure':y_pred2})","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:33:11.716523Z","iopub.execute_input":"2022-08-11T15:33:11.717490Z","iopub.status.idle":"2022-08-11T15:33:11.730356Z","shell.execute_reply.started":"2022-08-11T15:33:11.717451Z","shell.execute_reply":"2022-08-11T15:33:11.728845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission2['failure'].value_counts(normalize=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:33:36.661667Z","iopub.execute_input":"2022-08-11T15:33:36.662046Z","iopub.status.idle":"2022-08-11T15:33:36.671158Z","shell.execute_reply.started":"2022-08-11T15:33:36.662013Z","shell.execute_reply":"2022-08-11T15:33:36.670109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission2.to_csv('tps_august_2022_2.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:34:05.292455Z","iopub.execute_input":"2022-08-11T15:34:05.292816Z","iopub.status.idle":"2022-08-11T15:34:05.320538Z","shell.execute_reply.started":"2022-08-11T15:34:05.292783Z","shell.execute_reply":"2022-08-11T15:34:05.319639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import RidgeClassifier\nridge=RidgeClassifier(random_state=1001)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:42:12.579414Z","iopub.execute_input":"2022-08-11T15:42:12.579781Z","iopub.status.idle":"2022-08-11T15:42:12.584682Z","shell.execute_reply.started":"2022-08-11T15:42:12.579748Z","shell.execute_reply":"2022-08-11T15:42:12.583433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"param_grid={'max_iter':[100,400,1200,3150],\n            'tol':[2e-3,1e-4],\n            'solver' : ['svd', 'cholesky', 'lsqr', 'sparse_cg','sag', 'saga', 'lbfgs']\n            \n        }","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:42:38.451552Z","iopub.execute_input":"2022-08-11T15:42:38.451918Z","iopub.status.idle":"2022-08-11T15:42:38.456901Z","shell.execute_reply.started":"2022-08-11T15:42:38.451884Z","shell.execute_reply":"2022-08-11T15:42:38.455984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(param_grid)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:42:51.656408Z","iopub.execute_input":"2022-08-11T15:42:51.656761Z","iopub.status.idle":"2022-08-11T15:42:51.662709Z","shell.execute_reply.started":"2022-08-11T15:42:51.656730Z","shell.execute_reply":"2022-08-11T15:42:51.661424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ridge_grid=GridSearchCV(estimator=ridge,param_grid=param_grid,cv=6)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:43:39.139493Z","iopub.execute_input":"2022-08-11T15:43:39.140090Z","iopub.status.idle":"2022-08-11T15:43:39.144988Z","shell.execute_reply.started":"2022-08-11T15:43:39.140056Z","shell.execute_reply":"2022-08-11T15:43:39.143737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ridge_grid.fit(x_sm,y_sm)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:44:20.393617Z","iopub.execute_input":"2022-08-11T15:44:20.394003Z","iopub.status.idle":"2022-08-11T15:46:38.680600Z","shell.execute_reply.started":"2022-08-11T15:44:20.393966Z","shell.execute_reply":"2022-08-11T15:46:38.678771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ridge_grid.best_score_","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:48:28.593803Z","iopub.execute_input":"2022-08-11T15:48:28.594701Z","iopub.status.idle":"2022-08-11T15:48:28.601446Z","shell.execute_reply.started":"2022-08-11T15:48:28.594650Z","shell.execute_reply":"2022-08-11T15:48:28.600444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_grid=ridge_grid.best_estimator_\nbest_grid","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:48:31.342908Z","iopub.execute_input":"2022-08-11T15:48:31.343924Z","iopub.status.idle":"2022-08-11T15:48:31.350768Z","shell.execute_reply.started":"2022-08-11T15:48:31.343885Z","shell.execute_reply":"2022-08-11T15:48:31.349754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred3=best_grid.predict(test_df)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:48:50.198675Z","iopub.execute_input":"2022-08-11T15:48:50.199056Z","iopub.status.idle":"2022-08-11T15:48:50.209969Z","shell.execute_reply.started":"2022-08-11T15:48:50.199021Z","shell.execute_reply":"2022-08-11T15:48:50.208628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission3=pd.DataFrame({'id':sub_df['id'],'failure':y_pred3})\nsubmission3['failure'].value_counts(normalize=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:49:17.692215Z","iopub.execute_input":"2022-08-11T15:49:17.693265Z","iopub.status.idle":"2022-08-11T15:49:17.704175Z","shell.execute_reply.started":"2022-08-11T15:49:17.693221Z","shell.execute_reply":"2022-08-11T15:49:17.703141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission3.to_csv('tps_august_2022_3.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T15:49:20.781643Z","iopub.execute_input":"2022-08-11T15:49:20.782024Z","iopub.status.idle":"2022-08-11T15:49:20.810759Z","shell.execute_reply.started":"2022-08-11T15:49:20.781985Z","shell.execute_reply":"2022-08-11T15:49:20.809863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.experimental import enable_iterative_imputer\nfrom sklearn.impute import IterativeImputer","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:00:42.401687Z","iopub.execute_input":"2022-08-11T16:00:42.402367Z","iopub.status.idle":"2022-08-11T16:00:42.407151Z","shell.execute_reply.started":"2022-08-11T16:00:42.402329Z","shell.execute_reply":"2022-08-11T16:00:42.405914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imputer = IterativeImputer(max_iter = 8, random_state = 0, skip_complete = True, n_nearest_features = 12)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:00:44.130307Z","iopub.execute_input":"2022-08-11T16:00:44.131270Z","iopub.status.idle":"2022-08-11T16:00:44.136194Z","shell.execute_reply.started":"2022-08-11T16:00:44.131230Z","shell.execute_reply":"2022-08-11T16:00:44.134991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train_df.drop(columns='failure',axis=1)\ny=train_df['failure']","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:03:44.696320Z","iopub.execute_input":"2022-08-11T16:03:44.696689Z","iopub.status.idle":"2022-08-11T16:03:44.703237Z","shell.execute_reply.started":"2022-08-11T16:03:44.696659Z","shell.execute_reply":"2022-08-11T16:03:44.702178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:03:47.445630Z","iopub.execute_input":"2022-08-11T16:03:47.446012Z","iopub.status.idle":"2022-08-11T16:03:47.455481Z","shell.execute_reply.started":"2022-08-11T16:03:47.445977Z","shell.execute_reply":"2022-08-11T16:03:47.454374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_impute=imputer.fit_transform(x)\nx=pd.DataFrame(x_impute,columns=x.columns)\nx","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:03:59.894816Z","iopub.execute_input":"2022-08-11T16:03:59.895271Z","iopub.status.idle":"2022-08-11T16:04:05.160562Z","shell.execute_reply.started":"2022-08-11T16:03:59.895228Z","shell.execute_reply":"2022-08-11T16:04:05.159304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df_impute=imputer.transform(test_df)\ntest_df=pd.DataFrame(test_df_impute,columns=test_df.columns)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:05:10.526194Z","iopub.execute_input":"2022-08-11T16:05:10.526643Z","iopub.status.idle":"2022-08-11T16:05:10.869015Z","shell.execute_reply.started":"2022-08-11T16:05:10.526606Z","shell.execute_reply":"2022-08-11T16:05:10.867318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:05:31.159291Z","iopub.execute_input":"2022-08-11T16:05:31.159799Z","iopub.status.idle":"2022-08-11T16:05:31.175076Z","shell.execute_reply.started":"2022-08-11T16:05:31.159756Z","shell.execute_reply":"2022-08-11T16:05:31.174067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nsc=StandardScaler()\nx_scale=sc.fit_transform(x)\nx=pd.DataFrame(x_scale,columns=x.columns)\n\ntest_df_scale=sc.transform(test_df)\ntest_df=pd.DataFrame(test_df_scale,columns=test_df.columns)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:08:02.107812Z","iopub.execute_input":"2022-08-11T16:08:02.108409Z","iopub.status.idle":"2022-08-11T16:08:02.126603Z","shell.execute_reply.started":"2022-08-11T16:08:02.108372Z","shell.execute_reply":"2022-08-11T16:08:02.125646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:08:06.535509Z","iopub.execute_input":"2022-08-11T16:08:06.535990Z","iopub.status.idle":"2022-08-11T16:08:06.569680Z","shell.execute_reply.started":"2022-08-11T16:08:06.535922Z","shell.execute_reply":"2022-08-11T16:08:06.568716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:08:11.771394Z","iopub.execute_input":"2022-08-11T16:08:11.771846Z","iopub.status.idle":"2022-08-11T16:08:11.825680Z","shell.execute_reply.started":"2022-08-11T16:08:11.771807Z","shell.execute_reply":"2022-08-11T16:08:11.824601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr = LogisticRegression(max_iter = 200, C=0.05, penalty='l1', solver='liblinear')\nlr.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:09:27.338620Z","iopub.execute_input":"2022-08-11T16:09:27.339002Z","iopub.status.idle":"2022-08-11T16:09:27.433654Z","shell.execute_reply.started":"2022-08-11T16:09:27.338968Z","shell.execute_reply":"2022-08-11T16:09:27.432642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred4=lr.predict(test_df)\nsubmission4=pd.DataFrame({'id':sub_df['id'],'failure':y_pred4})\nsubmission4['failure'].value_counts(normalize=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:10:41.340567Z","iopub.execute_input":"2022-08-11T16:10:41.340926Z","iopub.status.idle":"2022-08-11T16:10:41.366398Z","shell.execute_reply.started":"2022-08-11T16:10:41.340895Z","shell.execute_reply":"2022-08-11T16:10:41.365230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission4.to_csv('tps_august_2022_4.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:11:12.480741Z","iopub.execute_input":"2022-08-11T16:11:12.481107Z","iopub.status.idle":"2022-08-11T16:11:12.508172Z","shell.execute_reply.started":"2022-08-11T16:11:12.481076Z","shell.execute_reply":"2022-08-11T16:11:12.507208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_sm,y_sm=smote.fit_resample(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:11:43.203539Z","iopub.execute_input":"2022-08-11T16:11:43.204344Z","iopub.status.idle":"2022-08-11T16:11:44.095227Z","shell.execute_reply.started":"2022-08-11T16:11:43.204304Z","shell.execute_reply":"2022-08-11T16:11:44.093945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_sm","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:11:46.774737Z","iopub.execute_input":"2022-08-11T16:11:46.775144Z","iopub.status.idle":"2022-08-11T16:11:46.809005Z","shell.execute_reply.started":"2022-08-11T16:11:46.775109Z","shell.execute_reply":"2022-08-11T16:11:46.807604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_sm","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:11:55.765593Z","iopub.execute_input":"2022-08-11T16:11:55.766294Z","iopub.status.idle":"2022-08-11T16:11:55.774555Z","shell.execute_reply.started":"2022-08-11T16:11:55.766250Z","shell.execute_reply":"2022-08-11T16:11:55.773532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_sm.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:12:12.836532Z","iopub.execute_input":"2022-08-11T16:12:12.837057Z","iopub.status.idle":"2022-08-11T16:12:12.848670Z","shell.execute_reply.started":"2022-08-11T16:12:12.837016Z","shell.execute_reply":"2022-08-11T16:12:12.847627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr = LogisticRegression(max_iter = 200, C=0.05, penalty='l1', solver='liblinear')\nlr.fit(x_sm,y_sm)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:12:48.532633Z","iopub.execute_input":"2022-08-11T16:12:48.533574Z","iopub.status.idle":"2022-08-11T16:12:48.695925Z","shell.execute_reply.started":"2022-08-11T16:12:48.533534Z","shell.execute_reply":"2022-08-11T16:12:48.694981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred5=lr.predict(test_df)\nsubmission5=pd.DataFrame({'id':sub_df['id'],'failure':y_pred5})\nsubmission5['failure'].value_counts(normalize=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:13:50.188395Z","iopub.execute_input":"2022-08-11T16:13:50.188775Z","iopub.status.idle":"2022-08-11T16:13:50.212266Z","shell.execute_reply.started":"2022-08-11T16:13:50.188730Z","shell.execute_reply":"2022-08-11T16:13:50.210807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission5.to_csv('tps_august_2022_5.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-11T16:14:18.244115Z","iopub.execute_input":"2022-08-11T16:14:18.244770Z","iopub.status.idle":"2022-08-11T16:14:18.274178Z","shell.execute_reply.started":"2022-08-11T16:14:18.244734Z","shell.execute_reply":"2022-08-11T16:14:18.273175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}