{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":81933,"databundleVersionId":9643020,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-12-17T16:51:32.411132Z","iopub.execute_input":"2024-12-17T16:51:32.411584Z","iopub.status.idle":"2024-12-17T16:51:37.225011Z","shell.execute_reply.started":"2024-12-17T16:51:32.411534Z","shell.execute_reply":"2024-12-17T16:51:37.223837Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom sklearn.metrics import cohen_kappa_score\nfrom xgboost import XGBRegressor\nfrom sklearn.model_selection import train_test_split,RandomizedSearchCV,cross_val_score\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.ensemble import RandomForestRegressor,ExtraTreesRegressor,VotingRegressor\nfrom lightgbm import LGBMRegressor\nfrom catboost import CatBoostRegressor\nimport optuna\nimport warnings\nwarnings.simplefilter('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:37.227354Z","iopub.execute_input":"2024-12-17T16:51:37.228381Z","iopub.status.idle":"2024-12-17T16:51:40.278733Z","shell.execute_reply.started":"2024-12-17T16:51:37.228325Z","shell.execute_reply":"2024-12-17T16:51:40.277515Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df=pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')\ntest_df=pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')\nprint(train_df.shape)\nprint(test_df.shape)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.280233Z","iopub.execute_input":"2024-12-17T16:51:40.281018Z","iopub.status.idle":"2024-12-17T16:51:40.361770Z","shell.execute_reply.started":"2024-12-17T16:51:40.280963Z","shell.execute_reply":"2024-12-17T16:51:40.360413Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.363215Z","iopub.execute_input":"2024-12-17T16:51:40.363783Z","iopub.status.idle":"2024-12-17T16:51:40.400194Z","shell.execute_reply.started":"2024-12-17T16:51:40.363738Z","shell.execute_reply":"2024-12-17T16:51:40.399117Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.402443Z","iopub.execute_input":"2024-12-17T16:51:40.402794Z","iopub.status.idle":"2024-12-17T16:51:40.436954Z","shell.execute_reply.started":"2024-12-17T16:51:40.402758Z","shell.execute_reply":"2024-12-17T16:51:40.435904Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.438122Z","iopub.execute_input":"2024-12-17T16:51:40.438463Z","iopub.status.idle":"2024-12-17T16:51:40.450051Z","shell.execute_reply.started":"2024-12-17T16:51:40.438431Z","shell.execute_reply":"2024-12-17T16:51:40.448912Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submit_id=test_df['id']","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.451431Z","iopub.execute_input":"2024-12-17T16:51:40.451787Z","iopub.status.idle":"2024-12-17T16:51:40.460008Z","shell.execute_reply.started":"2024-12-17T16:51:40.451751Z","shell.execute_reply":"2024-12-17T16:51:40.458979Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def kappa_score(y_true,y_pred):\n    return cohen_kappa_score(y_true,y_pred,weights='quadratic')","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.461355Z","iopub.execute_input":"2024-12-17T16:51:40.461725Z","iopub.status.idle":"2024-12-17T16:51:40.471870Z","shell.execute_reply.started":"2024-12-17T16:51:40.461689Z","shell.execute_reply":"2024-12-17T16:51:40.470781Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"threshold=[31,50,80]\ndef convert(score,thresholds):\n    score=np.array(score)*1.3\n    result=np.where(score<thresholds[0],0,\n                    np.where(score<thresholds[1],1,\n                    np.where(score<thresholds[2],2,3)))\n    return result","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.473209Z","iopub.execute_input":"2024-12-17T16:51:40.473569Z","iopub.status.idle":"2024-12-17T16:51:40.486182Z","shell.execute_reply.started":"2024-12-17T16:51:40.473533Z","shell.execute_reply":"2024-12-17T16:51:40.485110Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# categorical encoding\ndef cat_encode(dataframe):\n    for col in dataframe.select_dtypes('object').columns:\n        dataframe[col].fillna(dataframe[col].mode()[0])\n        dataframe[col]=dataframe[col].replace({'Fall':1,'Winter':2,'Summer':3,'Spring':4})\n    return dataframe","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.487642Z","iopub.execute_input":"2024-12-17T16:51:40.488079Z","iopub.status.idle":"2024-12-17T16:51:40.499964Z","shell.execute_reply.started":"2024-12-17T16:51:40.488030Z","shell.execute_reply":"2024-12-17T16:51:40.498856Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# numerical encoding\ndef num_encode(dataframe):\n    for col in dataframe.select_dtypes(exclude='object'):\n        dataframe[col]=dataframe[col].fillna(dataframe[col].mean())\n    return dataframe","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.501361Z","iopub.execute_input":"2024-12-17T16:51:40.501734Z","iopub.status.idle":"2024-12-17T16:51:40.514769Z","shell.execute_reply.started":"2024-12-17T16:51:40.501681Z","shell.execute_reply":"2024-12-17T16:51:40.513436Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df=cat_encode(train_df)\ntrain_df=num_encode(train_df)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.516101Z","iopub.execute_input":"2024-12-17T16:51:40.516491Z","iopub.status.idle":"2024-12-17T16:51:40.604963Z","shell.execute_reply.started":"2024-12-17T16:51:40.516451Z","shell.execute_reply":"2024-12-17T16:51:40.603657Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.columns","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.606201Z","iopub.execute_input":"2024-12-17T16:51:40.606567Z","iopub.status.idle":"2024-12-17T16:51:40.613948Z","shell.execute_reply.started":"2024-12-17T16:51:40.606530Z","shell.execute_reply":"2024-12-17T16:51:40.612886Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.619278Z","iopub.execute_input":"2024-12-17T16:51:40.619672Z","iopub.status.idle":"2024-12-17T16:51:40.647602Z","shell.execute_reply.started":"2024-12-17T16:51:40.619637Z","shell.execute_reply":"2024-12-17T16:51:40.646496Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df=cat_encode(test_df)\ntest_df=num_encode(test_df)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.648789Z","iopub.execute_input":"2024-12-17T16:51:40.649132Z","iopub.status.idle":"2024-12-17T16:51:40.690727Z","shell.execute_reply.started":"2024-12-17T16:51:40.649095Z","shell.execute_reply":"2024-12-17T16:51:40.689718Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# correlation\ncorr=train_df.corr(numeric_only=True)\ncorr_matrix=pd.DataFrame(corr[\"PCIAT-PCIAT_Total\"].sort_values(ascending=False))\ncorr_matrix","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.691857Z","iopub.execute_input":"2024-12-17T16:51:40.692170Z","iopub.status.idle":"2024-12-17T16:51:40.779991Z","shell.execute_reply.started":"2024-12-17T16:51:40.692135Z","shell.execute_reply":"2024-12-17T16:51:40.778888Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df=train_df.drop('id',axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.781415Z","iopub.execute_input":"2024-12-17T16:51:40.781763Z","iopub.status.idle":"2024-12-17T16:51:40.792601Z","shell.execute_reply.started":"2024-12-17T16:51:40.781727Z","shell.execute_reply":"2024-12-17T16:51:40.791191Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pciat_del=['PCIAT-PCIAT_01', 'PCIAT-PCIAT_02',\n       'PCIAT-PCIAT_03', 'PCIAT-PCIAT_04', 'PCIAT-PCIAT_05', 'PCIAT-PCIAT_06',\n       'PCIAT-PCIAT_07', 'PCIAT-PCIAT_08', 'PCIAT-PCIAT_09', 'PCIAT-PCIAT_10',\n       'PCIAT-PCIAT_11', 'PCIAT-PCIAT_12', 'PCIAT-PCIAT_13', 'PCIAT-PCIAT_14',\n       'PCIAT-PCIAT_15', 'PCIAT-PCIAT_16', 'PCIAT-PCIAT_17', 'PCIAT-PCIAT_18']\ntrain_df=train_df.drop(pciat_del,axis=1)\ntrain_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.794097Z","iopub.execute_input":"2024-12-17T16:51:40.794600Z","iopub.status.idle":"2024-12-17T16:51:40.811607Z","shell.execute_reply.started":"2024-12-17T16:51:40.794544Z","shell.execute_reply":"2024-12-17T16:51:40.810331Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df=train_df.drop(['PCIAT-PCIAT_19', 'PCIAT-PCIAT_20'],axis=1)\ncorr=train_df.corr()['PCIAT-PCIAT_Total'].sort_values(ascending=False)\ncorr","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.813080Z","iopub.execute_input":"2024-12-17T16:51:40.813464Z","iopub.status.idle":"2024-12-17T16:51:40.869375Z","shell.execute_reply.started":"2024-12-17T16:51:40.813425Z","shell.execute_reply":"2024-12-17T16:51:40.868230Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"com_col=train_df.columns.intersection(test_df.columns)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.870760Z","iopub.execute_input":"2024-12-17T16:51:40.871101Z","iopub.status.idle":"2024-12-17T16:51:40.878465Z","shell.execute_reply.started":"2024-12-17T16:51:40.871066Z","shell.execute_reply":"2024-12-17T16:51:40.877283Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_train_df=train_df[com_col]\nnew_train_df['PCIAT-PCIAT_Total']=train_df['PCIAT-PCIAT_Total']\ncorr=new_train_df.corr()['PCIAT-PCIAT_Total'].sort_values(ascending=False)\ncorr","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.879867Z","iopub.execute_input":"2024-12-17T16:51:40.880331Z","iopub.status.idle":"2024-12-17T16:51:40.939982Z","shell.execute_reply.started":"2024-12-17T16:51:40.880269Z","shell.execute_reply":"2024-12-17T16:51:40.938946Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"del_col=['BIA-BIA_FFMI','FGC-FGC_GSD','BIA-BIA_FMI','FGC-FGC_GSND','BIA-BIA_Activity_Level_num',               \n'Physical-Diastolic_BP','BIA-BIA_LST','BIA-BIA_DEE','BIA-BIA_SMM','BIA-BIA_ICW',   \n'FGC-FGC_PU_Zone','BIA-BIA_TBW','BIA-BIA_Fat','BIA-BIA_BMR','BIA-BIA_FFM','BIA-BIA_ECW',                               \n'BIA-Season','BIA-BIA_LDM','CGAS-Season','SDS-Season','FGC-Season', 'Fitness_Endurance-Time_Sec',               \n'FGC-FGC_GSD_Zone','PAQ_A-PAQ_A_Total','FGC-FGC_CU_Zone','BIA-BIA_BMC','FGC-FGC_GSND_Zone',                        \n'PAQ_C-PAQ_C_Total','PAQ_C-Season','Physical-Season','Fitness_Endurance-Max_Stage',\n'Basic_Demos-Enroll_Season','Fitness_Endurance-Time_Mins','Fitness_Endurance-Season','PreInt_EduHx-Season',                      \n'FGC-FGC_TL_Zone','Physical-HeartRate','CGAS-CGAS_Score','PAQ_A-Season','FGC-FGC_SRR','FGC-FGC_SRL',                              \n'Basic_Demos-Sex','FGC-FGC_SRR_Zone']\nnew_train_df=new_train_df.drop(del_col,axis=1)\nnew_test_df=test_df[com_col]\nnew_test_df=new_test_df.drop(del_col,axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.941359Z","iopub.execute_input":"2024-12-17T16:51:40.941790Z","iopub.status.idle":"2024-12-17T16:51:40.955280Z","shell.execute_reply.started":"2024-12-17T16:51:40.941738Z","shell.execute_reply":"2024-12-17T16:51:40.954097Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y=new_train_df['PCIAT-PCIAT_Total']","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.956880Z","iopub.execute_input":"2024-12-17T16:51:40.957235Z","iopub.status.idle":"2024-12-17T16:51:40.970568Z","shell.execute_reply.started":"2024-12-17T16:51:40.957199Z","shell.execute_reply":"2024-12-17T16:51:40.969356Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_train_df.columns","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.971919Z","iopub.execute_input":"2024-12-17T16:51:40.972373Z","iopub.status.idle":"2024-12-17T16:51:40.985211Z","shell.execute_reply.started":"2024-12-17T16:51:40.972321Z","shell.execute_reply":"2024-12-17T16:51:40.984034Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_train_df.corr()['PCIAT-PCIAT_Total'].sort_values(ascending=False)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:40.986753Z","iopub.execute_input":"2024-12-17T16:51:40.987234Z","iopub.status.idle":"2024-12-17T16:51:41.008680Z","shell.execute_reply.started":"2024-12-17T16:51:40.987177Z","shell.execute_reply":"2024-12-17T16:51:41.006989Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_train_df=new_train_df.drop(['Physical-BMI','Physical-Waist_Circumference','SDS-SDS_Total_Raw'],\n                               axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:41.010220Z","iopub.execute_input":"2024-12-17T16:51:41.010700Z","iopub.status.idle":"2024-12-17T16:51:41.018681Z","shell.execute_reply.started":"2024-12-17T16:51:41.010650Z","shell.execute_reply":"2024-12-17T16:51:41.017395Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_test_df=new_test_df.drop(['Physical-BMI','Physical-Waist_Circumference','SDS-SDS_Total_Raw'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:41.020118Z","iopub.execute_input":"2024-12-17T16:51:41.020519Z","iopub.status.idle":"2024-12-17T16:51:41.030874Z","shell.execute_reply.started":"2024-12-17T16:51:41.020480Z","shell.execute_reply":"2024-12-17T16:51:41.029696Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_train_df=new_train_df.drop('PCIAT-PCIAT_Total',axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.032622Z","iopub.execute_input":"2024-12-17T16:51:41.033803Z","iopub.status.idle":"2024-12-17T16:51:41.045154Z","shell.execute_reply.started":"2024-12-17T16:51:41.033748Z","shell.execute_reply":"2024-12-17T16:51:41.043624Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train,x_val,y_train,y_val=train_test_split(new_train_df,y,test_size=0.2,random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.047003Z","iopub.execute_input":"2024-12-17T16:51:41.047505Z","iopub.status.idle":"2024-12-17T16:51:41.062026Z","shell.execute_reply.started":"2024-12-17T16:51:41.047442Z","shell.execute_reply":"2024-12-17T16:51:41.060666Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# rnd_model=RandomForestRegressor(n_estimators=59,max_depth=3,n_jobs=-1)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:41.063414Z","iopub.execute_input":"2024-12-17T16:51:41.063908Z","iopub.status.idle":"2024-12-17T16:51:41.071677Z","shell.execute_reply.started":"2024-12-17T16:51:41.063868Z","shell.execute_reply":"2024-12-17T16:51:41.070127Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.073273Z","iopub.execute_input":"2024-12-17T16:51:41.073656Z","iopub.status.idle":"2024-12-17T16:51:41.087351Z","shell.execute_reply.started":"2024-12-17T16:51:41.073620Z","shell.execute_reply":"2024-12-17T16:51:41.086366Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# rnd_model.fit(x_train,y_train)\n# pred=rnd_model.predict(x_val)\n# pred=convert(pred,threshold)\n# y_true=convert(y_val,threshold)\n# kappa_score(y_true,pred)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:41.088708Z","iopub.execute_input":"2024-12-17T16:51:41.089030Z","iopub.status.idle":"2024-12-17T16:51:41.097689Z","shell.execute_reply.started":"2024-12-17T16:51:41.088995Z","shell.execute_reply":"2024-12-17T16:51:41.096504Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int('n_estimators',30,100),\n#         \"max_depth\": trial.suggest_int(\"max_depth\", 1, 10),\n#         'min_samples_split': trial.suggest_int('min_samples_split', 2, 32),\n#         'min_samples_leaf': trial.suggest_int('min_samples_leaf', 1, 32),\n#         'max_features': trial.suggest_categorical('max_features', ['sqrt', 'log2']),\n#         'criterion': trial.suggest_categorical('criterion', [\"squared_error\", \"absolute_error\", \"friedman_mse\", \"poisson\"]),\n#     }\n#     model=RandomForestRegressor(**params,n_jobs=-1)\n#     model.fit(x_train, y_train)\n#     predictions = model.predict(x_val)\n#     y_pred=convert(predictions,threshold)\n#     y_true=convert(y_val,threshold)\n#     score=kappa_score(y_pred,y_true)\n#     return score","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:41.098998Z","iopub.execute_input":"2024-12-17T16:51:41.099388Z","iopub.status.idle":"2024-12-17T16:51:41.111898Z","shell.execute_reply.started":"2024-12-17T16:51:41.099351Z","shell.execute_reply":"2024-12-17T16:51:41.110867Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# study=optuna.create_study(direction='maximize')\n# study.optimize(objective,n_trials=100)","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:41.113537Z","iopub.execute_input":"2024-12-17T16:51:41.113926Z","iopub.status.idle":"2024-12-17T16:51:41.128802Z","shell.execute_reply.started":"2024-12-17T16:51:41.113891Z","shell.execute_reply":"2024-12-17T16:51:41.127776Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_params=study.best_params","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:41.130611Z","iopub.execute_input":"2024-12-17T16:51:41.130960Z","iopub.status.idle":"2024-12-17T16:51:41.141399Z","shell.execute_reply.started":"2024-12-17T16:51:41.130925Z","shell.execute_reply":"2024-12-17T16:51:41.140340Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_params","metadata":{"execution":{"iopub.status.busy":"2024-12-17T16:51:41.142879Z","iopub.execute_input":"2024-12-17T16:51:41.143248Z","iopub.status.idle":"2024-12-17T16:51:41.155848Z","shell.execute_reply.started":"2024-12-17T16:51:41.143211Z","shell.execute_reply":"2024-12-17T16:51:41.154625Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_rnd_model=RandomForestRegressor(**best_params)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.157279Z","iopub.execute_input":"2024-12-17T16:51:41.157687Z","iopub.status.idle":"2024-12-17T16:51:41.172008Z","shell.execute_reply.started":"2024-12-17T16:51:41.157644Z","shell.execute_reply":"2024-12-17T16:51:41.170841Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# cat_model=CatBoostRegressor(verbose=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.173418Z","iopub.execute_input":"2024-12-17T16:51:41.173896Z","iopub.status.idle":"2024-12-17T16:51:41.188967Z","shell.execute_reply.started":"2024-12-17T16:51:41.173839Z","shell.execute_reply":"2024-12-17T16:51:41.187383Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# cat_model.fit(x_train,y_train)\n# pred=cat_model.predict(x_val)\n# pred=convert(pred,threshold)\n# y_true=convert(y_val,threshold)\n# kappa_score(pred,y_true)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.190655Z","iopub.execute_input":"2024-12-17T16:51:41.191158Z","iopub.status.idle":"2024-12-17T16:51:41.205180Z","shell.execute_reply.started":"2024-12-17T16:51:41.191103Z","shell.execute_reply":"2024-12-17T16:51:41.204035Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"iterations\": trial.suggest_int(\"iterations\",30,1000),\n#         \"learning_rate\": trial.suggest_float(\"learning_rate\", 1e-3, 0.1, log=True),\n#         \"depth\": trial.suggest_int(\"depth\", 1, 10),\n#         \"subsample\": trial.suggest_float(\"subsample\", 0.05, 1.0),\n#         \"colsample_bylevel\": trial.suggest_float(\"colsample_bylevel\", 0.05, 1.0),\n#         \"min_data_in_leaf\": trial.suggest_int(\"min_data_in_leaf\", 1, 100),\n#     }\n#     model=CatBoostRegressor(**params,verbose=False)\n#     model.fit(x_train, y_train)\n#     predictions = model.predict(x_val)\n#     y_pred=convert(predictions,threshold)\n#     y_true=convert(y_val,threshold)\n#     score=kappa_score(y_pred,y_true)\n#     return score","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.206571Z","iopub.execute_input":"2024-12-17T16:51:41.207035Z","iopub.status.idle":"2024-12-17T16:51:41.218874Z","shell.execute_reply.started":"2024-12-17T16:51:41.206987Z","shell.execute_reply":"2024-12-17T16:51:41.217768Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# study1=optuna.create_study(direction='maximize')\n# study1.optimize(objective,n_trials=100)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.225833Z","iopub.execute_input":"2024-12-17T16:51:41.226245Z","iopub.status.idle":"2024-12-17T16:51:41.233389Z","shell.execute_reply.started":"2024-12-17T16:51:41.226207Z","shell.execute_reply":"2024-12-17T16:51:41.232260Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_params=study1.best_params\n# best_params","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.234735Z","iopub.execute_input":"2024-12-17T16:51:41.235180Z","iopub.status.idle":"2024-12-17T16:51:41.252093Z","shell.execute_reply.started":"2024-12-17T16:51:41.235127Z","shell.execute_reply":"2024-12-17T16:51:41.250886Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_cat_model=CatBoostRegressor(**best_params,verbose=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.253659Z","iopub.execute_input":"2024-12-17T16:51:41.253996Z","iopub.status.idle":"2024-12-17T16:51:41.265714Z","shell.execute_reply.started":"2024-12-17T16:51:41.253959Z","shell.execute_reply":"2024-12-17T16:51:41.264571Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# xg_model=XGBRegressor(n_estimators=59,n_jobs=-1,verbose=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.267579Z","iopub.execute_input":"2024-12-17T16:51:41.267909Z","iopub.status.idle":"2024-12-17T16:51:41.278713Z","shell.execute_reply.started":"2024-12-17T16:51:41.267875Z","shell.execute_reply":"2024-12-17T16:51:41.277432Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# xg_model.fit(x_train,y_train)\n# pred=xg_model.predict(x_val)\n# pred=convert(pred,threshold)\n# kappa_score(pred,y_true)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.280178Z","iopub.execute_input":"2024-12-17T16:51:41.280647Z","iopub.status.idle":"2024-12-17T16:51:41.291404Z","shell.execute_reply.started":"2024-12-17T16:51:41.280603Z","shell.execute_reply":"2024-12-17T16:51:41.290006Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int(\"n_Estimators\",100,1000),\n#         \"verbosity\": 0,\n#         \"learning_rate\": trial.suggest_float(\"learning_rate\", 1e-3, 0.1, log=True),\n#         \"max_depth\": trial.suggest_int(\"max_depth\", 1, 10),\n#         \"subsample\": trial.suggest_float(\"subsample\", 0.05, 1.0),\n#         \"colsample_bytree\": trial.suggest_float(\"colsample_bytree\", 0.05, 1.0),\n#         \"min_child_weight\": trial.suggest_int(\"min_child_weight\", 1, 20),\n#     }\n\n#     model = XGBRegressor(**params,verbose=False,n_jobs=-1)\n#     model.fit(x_train, y_train)\n#     pred = model.predict(x_val)\n#     pred=convert(pred,threshold)\n#     score=kappa_score(pred,y_true)\n#     return score","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.292707Z","iopub.execute_input":"2024-12-17T16:51:41.293131Z","iopub.status.idle":"2024-12-17T16:51:41.305698Z","shell.execute_reply.started":"2024-12-17T16:51:41.293092Z","shell.execute_reply":"2024-12-17T16:51:41.304630Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# study2=optuna.create_study(direction=\"maximize\")\n# study2.optimize(objective,n_trials=100)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.307247Z","iopub.execute_input":"2024-12-17T16:51:41.307686Z","iopub.status.idle":"2024-12-17T16:51:41.321181Z","shell.execute_reply.started":"2024-12-17T16:51:41.307648Z","shell.execute_reply":"2024-12-17T16:51:41.319817Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_params=study2.best_params\n# best_params","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.323082Z","iopub.execute_input":"2024-12-17T16:51:41.323555Z","iopub.status.idle":"2024-12-17T16:51:41.335483Z","shell.execute_reply.started":"2024-12-17T16:51:41.323502Z","shell.execute_reply":"2024-12-17T16:51:41.334238Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_xg_model=XGBRegressor(**best_params)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.336858Z","iopub.execute_input":"2024-12-17T16:51:41.337339Z","iopub.status.idle":"2024-12-17T16:51:41.348952Z","shell.execute_reply.started":"2024-12-17T16:51:41.337258Z","shell.execute_reply":"2024-12-17T16:51:41.347817Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# xg_model=XGBRegressor(learning_rate=0.05,\n#     max_depth=6,\n#     n_estimators=200,\n#     subsample=0.8,\n#     colsample_bytree = 0.8,\n#     reg_alpha=1,\n#     reg_lambda=5,\n#     random_state=42)\n# xg_model.fit(new_train_df,y)\n# pred=xg_model.predict(new_test_df)\n# pred=convert(pred,threshold)\n# df=pd.DataFrame({\"id\":submit_id,\"sii\":pred})\n# df.to_csv(\"submission.csv\",index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.350822Z","iopub.execute_input":"2024-12-17T16:51:41.351245Z","iopub.status.idle":"2024-12-17T16:51:41.366663Z","shell.execute_reply.started":"2024-12-17T16:51:41.351203Z","shell.execute_reply":"2024-12-17T16:51:41.365414Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# lgb_model=LGBMRegressor(n_estimators=59,verbose=0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.368321Z","iopub.execute_input":"2024-12-17T16:51:41.368812Z","iopub.status.idle":"2024-12-17T16:51:41.379796Z","shell.execute_reply.started":"2024-12-17T16:51:41.368756Z","shell.execute_reply":"2024-12-17T16:51:41.378532Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# lgb_model.fit(x_train,y_train)\n# pred=lgb_model.predict(x_val)\n# pred=convert(pred,threshold)\n# y_true=convert(y_val,threshold)\n# kappa_score(pred,y_true)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.381349Z","iopub.execute_input":"2024-12-17T16:51:41.382684Z","iopub.status.idle":"2024-12-17T16:51:41.391687Z","shell.execute_reply.started":"2024-12-17T16:51:41.382610Z","shell.execute_reply":"2024-12-17T16:51:41.390653Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int(\"n_estimators\",30,200),\n#         \"learning_rate\": trial.suggest_float(\"learning_rate\", 1e-3, 0.1, log=True),\n#         \"num_leaves\": trial.suggest_int(\"num_leaves\", 2, 2**10),\n#         \"subsample\": trial.suggest_float(\"subsample\", 0.05, 1.0),\n#         \"colsample_bytree\": trial.suggest_float(\"colsample_bytree\", 0.05, 1.0),\n#         \"min_data_in_leaf\": trial.suggest_int(\"min_data_in_leaf\", 1, 100),\n#     }\n\n#     model = LGBMRegressor(**params)\n#     model.fit(x_train, y_train)\n#     pred = model.predict(x_val)\n#     y_pred=convert(pred,threshold)\n#     y_true=convert(y_val,threshold)\n#     score=kappa_score(y_true,y_pred)\n#     return score","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.393603Z","iopub.execute_input":"2024-12-17T16:51:41.394186Z","iopub.status.idle":"2024-12-17T16:51:41.404783Z","shell.execute_reply.started":"2024-12-17T16:51:41.394110Z","shell.execute_reply":"2024-12-17T16:51:41.403665Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# study3=optuna.create_study(direction='maximize')\n# study3.optimize(objective,n_trials=100)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.406421Z","iopub.execute_input":"2024-12-17T16:51:41.406913Z","iopub.status.idle":"2024-12-17T16:51:41.420565Z","shell.execute_reply.started":"2024-12-17T16:51:41.406855Z","shell.execute_reply":"2024-12-17T16:51:41.419437Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_params=study3.best_params\n# best_params","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.422591Z","iopub.execute_input":"2024-12-17T16:51:41.422953Z","iopub.status.idle":"2024-12-17T16:51:41.432703Z","shell.execute_reply.started":"2024-12-17T16:51:41.422916Z","shell.execute_reply":"2024-12-17T16:51:41.431389Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# best_lgb_model_1=LGBMRegressor(**best_params,verbose=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.434419Z","iopub.execute_input":"2024-12-17T16:51:41.434888Z","iopub.status.idle":"2024-12-17T16:51:41.445314Z","shell.execute_reply.started":"2024-12-17T16:51:41.434835Z","shell.execute_reply":"2024-12-17T16:51:41.444276Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# voting_rg=VotingRegressor([('rnd_model',best_rnd_model),\n#                            ('lgm_model',best_lgb_model),('xg_model',best_xg_model)],n_jobs=-1,\n#                          verbose=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.446879Z","iopub.execute_input":"2024-12-17T16:51:41.447331Z","iopub.status.idle":"2024-12-17T16:51:41.456991Z","shell.execute_reply.started":"2024-12-17T16:51:41.447253Z","shell.execute_reply":"2024-12-17T16:51:41.455855Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# voting_rg.fit(x_train,y_train)\n# pred=voting_rg.predict(x_val)\n# pred=convert(pred,threshold)\n# kappa_score(pred,y_true)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.458618Z","iopub.execute_input":"2024-12-17T16:51:41.458954Z","iopub.status.idle":"2024-12-17T16:51:41.468532Z","shell.execute_reply.started":"2024-12-17T16:51:41.458920Z","shell.execute_reply":"2024-12-17T16:51:41.467418Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# voting_rg.fit(new_train_df,y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.469882Z","iopub.execute_input":"2024-12-17T16:51:41.470954Z","iopub.status.idle":"2024-12-17T16:51:41.481390Z","shell.execute_reply.started":"2024-12-17T16:51:41.470891Z","shell.execute_reply":"2024-12-17T16:51:41.480447Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# prediction=voting_rg.predict(new_test_df)\n# pred=convert(prediction,threshold)\n# submit1=pd.DataFrame({\"id\":submit_id,\"sii\":pred})\n# submit1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.482909Z","iopub.execute_input":"2024-12-17T16:51:41.483639Z","iopub.status.idle":"2024-12-17T16:51:41.493875Z","shell.execute_reply.started":"2024-12-17T16:51:41.483582Z","shell.execute_reply":"2024-12-17T16:51:41.492849Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int('n_estimators',30,100),\n#         \"max_depth\": trial.suggest_int(\"max_depth\", 1, 10),\n#         'min_samples_split': trial.suggest_int('min_samples_split', 2, 32),\n#         'min_samples_leaf': trial.suggest_int('min_samples_leaf', 1, 32),\n#         'max_features': trial.suggest_categorical('max_features', ['sqrt', 'log2']),\n#         'criterion': trial.suggest_categorical('criterion', [\"squared_error\", \"absolute_error\", \"friedman_mse\", \"poisson\"]),\n#     }\n#     model=RandomForestRegressor(**params,n_jobs=-1)\n#     model.fit(x_train, y_train)\n#     predictions = model.predict(x_val)\n#     y_pred=convert(predictions,threshold)\n#     y_true=convert(y_val,threshold)\n#     score=kappa_score(y_pred,y_true)\n#     return score\n# study=optuna.create_study(direction='maximize')\n# study.optimize(objective,n_trials=100)\n# best_params=study.best_params\n# best_rnd_model=RandomForestRegressor(**best_params)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.495050Z","iopub.execute_input":"2024-12-17T16:51:41.495391Z","iopub.status.idle":"2024-12-17T16:51:41.508054Z","shell.execute_reply.started":"2024-12-17T16:51:41.495354Z","shell.execute_reply":"2024-12-17T16:51:41.507066Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int(\"n_Estimators\",100,1000),\n#         \"verbosity\": 0,\n#         \"learning_rate\": trial.suggest_float(\"learning_rate\", 1e-3, 0.1, log=True),\n#         \"max_depth\": trial.suggest_int(\"max_depth\", 1, 10),\n#         \"subsample\": trial.suggest_float(\"subsample\", 0.05, 1.0),\n#         \"colsample_bytree\": trial.suggest_float(\"colsample_bytree\", 0.05, 1.0),\n#         \"min_child_weight\": trial.suggest_int(\"min_child_weight\", 1, 20),\n#     }\n\n#     model = XGBRegressor(**params,verbose=False,n_jobs=-1)\n#     model.fit(x_train, y_train)\n#     pred = model.predict(x_val)\n#     pred=convert(pred,threshold)\n#     score=kappa_score(pred,y_true)\n#     return score\n# study2=optuna.create_study(direction=\"maximize\")\n# study2.optimize(objective,n_trials=100)\n# best_params=study2.best_params\n# best_xg_model=XGBRegressor(**best_params)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.509191Z","iopub.execute_input":"2024-12-17T16:51:41.509584Z","iopub.status.idle":"2024-12-17T16:51:41.525135Z","shell.execute_reply.started":"2024-12-17T16:51:41.509550Z","shell.execute_reply":"2024-12-17T16:51:41.524018Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int(\"n_estimators\",30,200),\n#         \"learning_rate\": trial.suggest_float(\"learning_rate\", 1e-3, 0.1, log=True),\n#         \"num_leaves\": trial.suggest_int(\"num_leaves\", 2, 2**10),\n#         \"subsample\": trial.suggest_float(\"subsample\", 0.05, 1.0),\n#         \"colsample_bytree\": trial.suggest_float(\"colsample_bytree\", 0.05, 1.0),\n#         \"min_data_in_leaf\": trial.suggest_int(\"min_data_in_leaf\", 1, 100),\n#     }\n\n#     model = LGBMRegressor(**params)\n#     model.fit(x_train, y_train)\n#     pred = model.predict(x_val)\n#     y_pred=convert(pred,threshold)\n#     y_true=convert(y_val,threshold)\n#     score=kappa_score(y_true,y_pred)\n#     return score\n# study3=optuna.create_study(direction='maximize')\n# study3.optimize(objective,n_trials=100)\n# best_params=study3.best_params\n# best_lgb_model_2=LGBMRegressor(**best_params,verbose=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.526531Z","iopub.execute_input":"2024-12-17T16:51:41.526875Z","iopub.status.idle":"2024-12-17T16:51:41.538392Z","shell.execute_reply.started":"2024-12-17T16:51:41.526835Z","shell.execute_reply":"2024-12-17T16:51:41.537260Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# voting_rg=VotingRegressor([('rnd_model',best_rnd_model),\n#                            ('lgm_model',best_lgb_model),('xg_model',best_xg_model)],n_jobs=-1,\n#                          verbose=False)\n# voting_rg.fit(x_train,y_train)\n# pred=voting_rg.predict(x_val)\n# pred=convert(pred,threshold)\n# kappa_score(pred,y_true)\n# voting_rg.fit(new_train_df,y)\n# prediction=voting_rg.predict(new_test_df)\n# pred=convert(prediction,threshold)\n# submit2=pd.DataFrame({\"id\":submit_id,\"sii\":pred})\n# submit2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.539731Z","iopub.execute_input":"2024-12-17T16:51:41.540141Z","iopub.status.idle":"2024-12-17T16:51:41.555917Z","shell.execute_reply.started":"2024-12-17T16:51:41.540094Z","shell.execute_reply":"2024-12-17T16:51:41.554650Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int('n_estimators',30,100),\n#         \"max_depth\": trial.suggest_int(\"max_depth\", 1, 10),\n#         'min_samples_split': trial.suggest_int('min_samples_split', 2, 32),\n#         'min_samples_leaf': trial.suggest_int('min_samples_leaf', 1, 32),\n#         'max_features': trial.suggest_categorical('max_features', ['sqrt', 'log2']),\n#         'criterion': trial.suggest_categorical('criterion', [\"squared_error\", \"absolute_error\", \"friedman_mse\", \"poisson\"]),\n#     }\n#     model=RandomForestRegressor(**params,n_jobs=-1)\n#     model.fit(x_train, y_train)\n#     predictions = model.predict(x_val)\n#     y_pred=convert(predictions,threshold)\n#     y_true=convert(y_val,threshold)\n#     score=kappa_score(y_pred,y_true)\n#     return score\n# study=optuna.create_study(direction='maximize')\n# study.optimize(objective,n_trials=100)\n# best_params=study.best_params\n# best_rnd_model=RandomForestRegressor(**best_params)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.557478Z","iopub.execute_input":"2024-12-17T16:51:41.557894Z","iopub.status.idle":"2024-12-17T16:51:41.570616Z","shell.execute_reply.started":"2024-12-17T16:51:41.557846Z","shell.execute_reply":"2024-12-17T16:51:41.569351Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int(\"n_Estimators\",100,1000),\n#         \"verbosity\": 0,\n#         \"learning_rate\": trial.suggest_float(\"learning_rate\", 1e-3, 0.1, log=True),\n#         \"max_depth\": trial.suggest_int(\"max_depth\", 1, 10),\n#         \"subsample\": trial.suggest_float(\"subsample\", 0.05, 1.0),\n#         \"colsample_bytree\": trial.suggest_float(\"colsample_bytree\", 0.05, 1.0),\n#         \"min_child_weight\": trial.suggest_int(\"min_child_weight\", 1, 20),\n#     }\n\n#     model = XGBRegressor(**params,verbose=False,n_jobs=-1)\n#     model.fit(x_train, y_train)\n#     pred = model.predict(x_val)\n#     pred=convert(pred,threshold)\n#     score=kappa_score(pred,y_true)\n#     return score\n# study2=optuna.create_study(direction=\"maximize\")\n# study2.optimize(objective,n_trials=100)\n# best_params=study2.best_params\n# best_xg_model=XGBRegressor(**best_params)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.572033Z","iopub.execute_input":"2024-12-17T16:51:41.572398Z","iopub.status.idle":"2024-12-17T16:51:41.589820Z","shell.execute_reply.started":"2024-12-17T16:51:41.572360Z","shell.execute_reply":"2024-12-17T16:51:41.588675Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def objective(trial):\n#     params = {\n#         \"n_estimators\": trial.suggest_int(\"n_estimators\",30,200),\n#         \"learning_rate\": trial.suggest_float(\"learning_rate\", 1e-3, 0.1, log=True),\n#         \"num_leaves\": trial.suggest_int(\"num_leaves\", 2, 2**10),\n#         \"subsample\": trial.suggest_float(\"subsample\", 0.05, 1.0),\n#         \"colsample_bytree\": trial.suggest_float(\"colsample_bytree\", 0.05, 1.0),\n#         \"min_data_in_leaf\": trial.suggest_int(\"min_data_in_leaf\", 1, 100),\n#     }\n\n#     model = LGBMRegressor(**params)\n#     model.fit(x_train, y_train)\n#     pred = model.predict(x_val)\n#     y_pred=convert(pred,threshold)\n#     y_true=convert(y_val,threshold)\n#     score=kappa_score(y_true,y_pred)\n#     return score\n# study3=optuna.create_study(direction='maximize')\n# study3.optimize(objective,n_trials=100)\n# best_params=study3.best_params\n# best_lgb_model_3=LGBMRegressor(**best_params,verbose=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.591242Z","iopub.execute_input":"2024-12-17T16:51:41.591629Z","iopub.status.idle":"2024-12-17T16:51:41.601442Z","shell.execute_reply.started":"2024-12-17T16:51:41.591584Z","shell.execute_reply":"2024-12-17T16:51:41.600397Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# voting_rg=VotingRegressor([('rnd_model',best_rnd_model),\n#                            ('lgm_model',best_lgb_model),('xg_model',best_xg_model)],n_jobs=-1,\n#                          verbose=False)\n# voting_rg.fit(x_train,y_train)\n# pred=voting_rg.predict(x_val)\n# pred=convert(pred,threshold)\n# kappa_score(pred,y_true)\n# voting_rg.fit(new_train_df,y)\n# prediction=voting_rg.predict(new_test_df)\n# pred=convert(prediction,threshold)\n# submit3=pd.DataFrame({\"id\":submit_id,\"sii\":pred})\n# submit3","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.602720Z","iopub.execute_input":"2024-12-17T16:51:41.603099Z","iopub.status.idle":"2024-12-17T16:51:41.634657Z","shell.execute_reply.started":"2024-12-17T16:51:41.603052Z","shell.execute_reply":"2024-12-17T16:51:41.633619Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# voting_reg=VotingRegressor([('lgb1',best_lgb_model_1),('lgb2',best_lgb_model_2),\n#                            ('lgb3',best_lgb_model_3)],verbose=False,n_jobs=-1)\n# voting_reg.fit(x_train,y_train)\n# pred=voting_reg.predict(x_val)\n# pred=convert(pred,threshold)\n# result=kappa_score(pred,y_true)\n# print(result)\n# voting_reg.fit(new_train_df,y)\n# prediction=voting_reg.predict(new_test_df)\n# prediction=convert(prediction,threshold)\n# submit=pd.DataFrame({'id':submit_id,'sii':prediction})\n# submit","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.636315Z","iopub.execute_input":"2024-12-17T16:51:41.637348Z","iopub.status.idle":"2024-12-17T16:51:41.649459Z","shell.execute_reply.started":"2024-12-17T16:51:41.637273Z","shell.execute_reply":"2024-12-17T16:51:41.648268Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# submit.to_csv(\"submission.csv\",index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:41.650844Z","iopub.execute_input":"2024-12-17T16:51:41.651200Z","iopub.status.idle":"2024-12-17T16:51:41.662747Z","shell.execute_reply.started":"2024-12-17T16:51:41.651162Z","shell.execute_reply":"2024-12-17T16:51:41.661622Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"params={'objective'       : 'l2',\n    'verbosity'       : -1,\n    'n_iter'          : 200,\n    'lambda_l1'       : 0.005116829730239727,\n    'lambda_l2'       : 0.0011520776712645852,\n    'learning_rate'   : 0.02376367323636638,\n    'max_depth'       : 5,\n    'num_leaves'      : 207,\n    'colsample_bytree': 0.7759862336963801,\n    'colsample_bynode': 0.5110355095943208,\n    'bagging_fraction': 0.5485770314992224,\n    'bagging_freq'    : 7,\n    'min_data_in_leaf': 78}\nlg_model=LGBMRegressor(**params)\nlg_model.fit(new_train_df,y)\npred=lg_model.predict(new_test_df)\npred=convert(pred,threshold)\ndf=pd.DataFrame({\"id\":submit_id,\"sii\":pred})\ndf.to_csv(\"submission.csv\",index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T16:51:48.539659Z","iopub.execute_input":"2024-12-17T16:51:48.540026Z","iopub.status.idle":"2024-12-17T16:51:48.667802Z","shell.execute_reply.started":"2024-12-17T16:51:48.539991Z","shell.execute_reply":"2024-12-17T16:51:48.666682Z"}},"outputs":[],"execution_count":null}]}