{"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        pass\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","trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:31:04.492362Z","iopub.execute_input":"2024-10-24T04:31:04.492879Z","iopub.status.idle":"2024-10-24T04:31:05.611683Z","shell.execute_reply.started":"2024-10-24T04:31:04.492830Z","shell.execute_reply":"2024-10-24T04:31:05.610408Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from concurrent.futures import ThreadPoolExecutor\nfrom tqdm import tqdm\nfrom sklearn.preprocessing import StandardScaler\nfrom keras.models import Model\nfrom keras.layers import Input, Dense\nfrom keras.optimizers import Adam\nfrom lightgbm import LGBMRegressor\nfrom sklearn.metrics import cohen_kappa_score\nfrom scipy.optimize import minimize","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:31:05.613691Z","iopub.execute_input":"2024-10-24T04:31:05.614105Z","iopub.status.idle":"2024-10-24T04:31:05.621297Z","shell.execute_reply.started":"2024-10-24T04:31:05.614060Z","shell.execute_reply":"2024-10-24T04:31:05.620008Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_parquet(\"/kaggle/input/child-mind-institute-problematic-internet-use/series_train.parquet/id=5f099188/part-0.parquet\")\n\n#df.drop('step', axis=1, inplace=True)\n#df.describe().values.reshape(-1), filename.split('=')[1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:31:05.623127Z","iopub.execute_input":"2024-10-24T04:31:05.623650Z","iopub.status.idle":"2024-10-24T04:31:05.751547Z","shell.execute_reply.started":"2024-10-24T04:31:05.623595Z","shell.execute_reply":"2024-10-24T04:31:05.750172Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.drop('step', axis=1, inplace=True)\ndf.describe().values.reshape(-1).shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:31:05.755254Z","iopub.execute_input":"2024-10-24T04:31:05.756380Z","iopub.status.idle":"2024-10-24T04:31:05.909929Z","shell.execute_reply.started":"2024-10-24T04:31:05.756316Z","shell.execute_reply":"2024-10-24T04:31:05.908682Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.describe().values.reshape(-1).shape, len(os.listdir('/kaggle/input/child-mind-institute-problematic-internet-use/series_train.parquet/'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:31:05.911562Z","iopub.execute_input":"2024-10-24T04:31:05.911976Z","iopub.status.idle":"2024-10-24T04:31:06.044291Z","shell.execute_reply.started":"2024-10-24T04:31:05.911926Z","shell.execute_reply":"2024-10-24T04:31:06.043001Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def process_file(filename, dirname):\n    df = pd.read_parquet(os.path.join(dirname, filename, 'part-0.parquet'))\n    df.drop('step', axis=1, inplace=True)\n    return df.describe().values.reshape(-1), filename.split('=')[1]\n    \ndef load_time_series(dirname) -> pd.DataFrame:\n    ids = os.listdir(dirname)\n    \n    with ThreadPoolExecutor() as executor:\n        results = list(executor.map(lambda fname: process_file(fname, dirname), ids))\n    print(len(results))\n    stats, indexes = zip(*results)\n    \n    df = pd.DataFrame(stats, columns=[f\"stat_{i}\" for i in range(len(stats[0]))])\n    df['id'] = indexes\n    return df\n\ndef build_autoencoder(input_dim, encoding_dim):\n    input_layer = Input(shape=(input_dim,))\n    encoded = Dense(encoding_dim, activation='relu')(input_layer)\n    decoded = Dense(input_dim, activation='sigmoid')(encoded)\n    autoencoder = Model(inputs=input_layer, outputs=decoded)\n    encoder = Model(inputs=input_layer, outputs=encoded)\n    autoencoder.compile(optimizer=Adam(), loss='mse')\n    \n    return autoencoder, encoder\n\ndef perform_autoencoder(df, encoding_dim=50, epochs=50, batch_size=32):\n    scaler = StandardScaler()\n    df_scaled = scaler.fit_transform(df)\n    \n    input_dim = df_scaled.shape[1]\n    autoencoder, encoder = build_autoencoder(input_dim, encoding_dim)\n    \n    autoencoder.fit(df_scaled, df_scaled, epochs=epochs, batch_size=batch_size, shuffle=True, verbose=0)\n    encoded_data = encoder.predict(df_scaled)\n    \n    df_encoded = pd.DataFrame(encoded_data, columns=[f'Enc_{i+1}' for i in range(encoded_data.shape[1])])\n    \n    return df_encoded","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:31:06.046248Z","iopub.execute_input":"2024-10-24T04:31:06.046710Z","iopub.status.idle":"2024-10-24T04:31:06.065314Z","shell.execute_reply.started":"2024-10-24T04:31:06.046658Z","shell.execute_reply":"2024-10-24T04:31:06.063873Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')\ntest = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')\nsample = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/sample_submission.csv')\n\ntrain_ts = load_time_series(\"/kaggle/input/child-mind-institute-problematic-internet-use/series_train.parquet\")\ntest_ts = load_time_series(\"/kaggle/input/child-mind-institute-problematic-internet-use/series_test.parquet\")\n\ndf_train = train_ts.drop('id', axis=1)\ndf_test = test_ts.drop('id', axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:31:06.067138Z","iopub.execute_input":"2024-10-24T04:31:06.067599Z","iopub.status.idle":"2024-10-24T04:33:45.195875Z","shell.execute_reply.started":"2024-10-24T04:31:06.067552Z","shell.execute_reply":"2024-10-24T04:33:45.194582Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape, df_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:45.197558Z","iopub.execute_input":"2024-10-24T04:33:45.198031Z","iopub.status.idle":"2024-10-24T04:33:45.206688Z","shell.execute_reply.started":"2024-10-24T04:33:45.197987Z","shell.execute_reply":"2024-10-24T04:33:45.205288Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_ts_encoded = perform_autoencoder(df_train, encoding_dim=50, epochs=10, batch_size=32)\ntest_ts_encoded = perform_autoencoder(df_test, encoding_dim=50, epochs=10, batch_size=32)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:45.208400Z","iopub.execute_input":"2024-10-24T04:33:45.208847Z","iopub.status.idle":"2024-10-24T04:33:48.382964Z","shell.execute_reply.started":"2024-10-24T04:33:45.208805Z","shell.execute_reply":"2024-10-24T04:33:48.381582Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape, train_ts.shape, df_train.shape, train_ts_encoded.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.387637Z","iopub.execute_input":"2024-10-24T04:33:48.388068Z","iopub.status.idle":"2024-10-24T04:33:48.401680Z","shell.execute_reply.started":"2024-10-24T04:33:48.388028Z","shell.execute_reply":"2024-10-24T04:33:48.400227Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#train_ts_encoded.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.403240Z","iopub.execute_input":"2024-10-24T04:33:48.403673Z","iopub.status.idle":"2024-10-24T04:33:48.409474Z","shell.execute_reply.started":"2024-10-24T04:33:48.403630Z","shell.execute_reply":"2024-10-24T04:33:48.408099Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"time_series_cols = train_ts_encoded.columns.tolist()\ntrain_ts_encoded['id'] = train_ts['id']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.411014Z","iopub.execute_input":"2024-10-24T04:33:48.411436Z","iopub.status.idle":"2024-10-24T04:33:48.423222Z","shell.execute_reply.started":"2024-10-24T04:33:48.411376Z","shell.execute_reply":"2024-10-24T04:33:48.421960Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape, train_ts.shape, df_train.shape, train_ts_encoded.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.424835Z","iopub.execute_input":"2024-10-24T04:33:48.425235Z","iopub.status.idle":"2024-10-24T04:33:48.438414Z","shell.execute_reply.started":"2024-10-24T04:33:48.425195Z","shell.execute_reply":"2024-10-24T04:33:48.437133Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.merge(train, train_ts_encoded, how=\"left\", on='id')\ntrain.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.440198Z","iopub.execute_input":"2024-10-24T04:33:48.440732Z","iopub.status.idle":"2024-10-24T04:33:48.483358Z","shell.execute_reply.started":"2024-10-24T04:33:48.440675Z","shell.execute_reply":"2024-10-24T04:33:48.481874Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = pd.merge(test, train_ts_encoded, how=\"left\", on='id')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.485070Z","iopub.execute_input":"2024-10-24T04:33:48.485473Z","iopub.status.idle":"2024-10-24T04:33:48.498360Z","shell.execute_reply.started":"2024-10-24T04:33:48.485427Z","shell.execute_reply":"2024-10-24T04:33:48.497029Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_ = pd.merge(test, test_ts, how='left', on='id')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.500138Z","iopub.execute_input":"2024-10-24T04:33:48.500584Z","iopub.status.idle":"2024-10-24T04:33:48.517214Z","shell.execute_reply.started":"2024-10-24T04:33:48.500530Z","shell.execute_reply":"2024-10-24T04:33:48.515937Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = train.drop('id', axis=1)\ntest = test.drop('id', axis=1) ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.518813Z","iopub.execute_input":"2024-10-24T04:33:48.519317Z","iopub.status.idle":"2024-10-24T04:33:48.532837Z","shell.execute_reply.started":"2024-10-24T04:33:48.519264Z","shell.execute_reply":"2024-10-24T04:33:48.531270Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape, train_ts.shape, df_train.shape, train_ts_encoded.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.534239Z","iopub.execute_input":"2024-10-24T04:33:48.534701Z","iopub.status.idle":"2024-10-24T04:33:48.545090Z","shell.execute_reply.started":"2024-10-24T04:33:48.534659Z","shell.execute_reply":"2024-10-24T04:33:48.543924Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"featuresCols = ['Basic_Demos-Enroll_Season', 'Basic_Demos-Age', 'Basic_Demos-Sex',\n                'CGAS-Season', 'CGAS-CGAS_Score', 'Physical-Season', 'Physical-BMI',\n                'Physical-Height', 'Physical-Weight', 'Physical-Waist_Circumference',\n                'Physical-Diastolic_BP', 'Physical-HeartRate', 'Physical-Systolic_BP',\n                'Fitness_Endurance-Season', 'Fitness_Endurance-Max_Stage',\n                'Fitness_Endurance-Time_Mins', 'Fitness_Endurance-Time_Sec',\n                'FGC-Season', 'FGC-FGC_CU', 'FGC-FGC_CU_Zone', 'FGC-FGC_GSND',\n                'FGC-FGC_GSND_Zone', 'FGC-FGC_GSD', 'FGC-FGC_GSD_Zone', 'FGC-FGC_PU',\n                'FGC-FGC_PU_Zone', 'FGC-FGC_SRL', 'FGC-FGC_SRL_Zone', 'FGC-FGC_SRR',\n                'FGC-FGC_SRR_Zone', 'FGC-FGC_TL', 'FGC-FGC_TL_Zone', 'BIA-Season',\n                'BIA-BIA_Activity_Level_num', 'BIA-BIA_BMC', 'BIA-BIA_BMI',\n                'BIA-BIA_BMR', 'BIA-BIA_DEE', 'BIA-BIA_ECW', 'BIA-BIA_FFM',\n                'BIA-BIA_FFMI', 'BIA-BIA_FMI', 'BIA-BIA_Fat', 'BIA-BIA_Frame_num',\n                'BIA-BIA_ICW', 'BIA-BIA_LDM', 'BIA-BIA_LST', 'BIA-BIA_SMM',\n                'BIA-BIA_TBW', 'PAQ_A-Season', 'PAQ_A-PAQ_A_Total', 'PAQ_C-Season',\n                'PAQ_C-PAQ_C_Total', 'SDS-Season', 'SDS-SDS_Total_Raw',\n                'SDS-SDS_Total_T', 'PreInt_EduHx-Season',\n                'PreInt_EduHx-computerinternet_hoursday', 'sii']\n\ncat_c = ['Basic_Demos-Enroll_Season', 'CGAS-Season', 'Physical-Season', \n          'Fitness_Endurance-Season', 'FGC-Season', 'BIA-Season', \n          'PAQ_A-Season', 'PAQ_C-Season', 'SDS-Season', 'PreInt_EduHx-Season']\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.546662Z","iopub.execute_input":"2024-10-24T04:33:48.547160Z","iopub.status.idle":"2024-10-24T04:33:48.560357Z","shell.execute_reply.started":"2024-10-24T04:33:48.547112Z","shell.execute_reply":"2024-10-24T04:33:48.558958Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"featuresCols += time_series_cols\n\ntrain = train[featuresCols]\ntrain = train.dropna(subset='sii')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.562461Z","iopub.execute_input":"2024-10-24T04:33:48.563037Z","iopub.status.idle":"2024-10-24T04:33:48.586489Z","shell.execute_reply.started":"2024-10-24T04:33:48.562980Z","shell.execute_reply":"2024-10-24T04:33:48.585240Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def update(df):\n    global cat_c\n    for c in cat_c: \n        df[c] = df[c].fillna('Missing')\n        df[c] = df[c].astype('category')\n    return df\n        \ntrain = update(train)\ntest = update(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.587992Z","iopub.execute_input":"2024-10-24T04:33:48.588559Z","iopub.status.idle":"2024-10-24T04:33:48.625971Z","shell.execute_reply.started":"2024-10-24T04:33:48.588470Z","shell.execute_reply":"2024-10-24T04:33:48.624931Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n#{value: idx for idx, value in enumerate(train['Physical-Season'].unique())}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.627309Z","iopub.execute_input":"2024-10-24T04:33:48.627695Z","iopub.status.idle":"2024-10-24T04:33:48.632908Z","shell.execute_reply.started":"2024-10-24T04:33:48.627656Z","shell.execute_reply":"2024-10-24T04:33:48.631681Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def create_mapping(column, dataset):\n    unique_values = dataset[column].unique()\n    return {value: idx for idx, value in enumerate(unique_values)}\n\nfor col in cat_c:\n    mapping = create_mapping(col, train)\n    mappingTe = create_mapping(col, test)\n    \n    train[col] = train[col].replace(mapping).astype(int)\n    test[col] = test[col].replace(mappingTe).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.634704Z","iopub.execute_input":"2024-10-24T04:33:48.635126Z","iopub.status.idle":"2024-10-24T04:33:48.701270Z","shell.execute_reply.started":"2024-10-24T04:33:48.635069Z","shell.execute_reply":"2024-10-24T04:33:48.699829Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape, test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.702981Z","iopub.execute_input":"2024-10-24T04:33:48.703384Z","iopub.status.idle":"2024-10-24T04:33:48.711400Z","shell.execute_reply.started":"2024-10-24T04:33:48.703342Z","shell.execute_reply":"2024-10-24T04:33:48.710098Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.groupby('sii').count()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.713428Z","iopub.execute_input":"2024-10-24T04:33:48.714041Z","iopub.status.idle":"2024-10-24T04:33:48.744601Z","shell.execute_reply.started":"2024-10-24T04:33:48.713992Z","shell.execute_reply":"2024-10-24T04:33:48.743164Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"SEED = 42\nn_splits = 5\n\nParams = {\n    'learning_rate': 0.046,\n    'max_depth': 12,\n    'num_leaves': 478,\n    'min_data_in_leaf': 13,\n    'feature_fraction': 0.893,\n    'bagging_fraction': 0.784,\n    'bagging_freq': 4,\n    'lambda_l1': 10,  # Increased from 6.59\n    'lambda_l2': 0.01  # Increased from 2.68e-06\n}\n\nmodel  = Light = LGBMRegressor(**Params, random_state=SEED, verbose=-1, n_estimators=300)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.746198Z","iopub.execute_input":"2024-10-24T04:33:48.746615Z","iopub.status.idle":"2024-10-24T04:33:48.754529Z","shell.execute_reply.started":"2024-10-24T04:33:48.746574Z","shell.execute_reply":"2024-10-24T04:33:48.753238Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX = train.drop(['sii'], axis=1)\ny = train['sii']\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:48.756387Z","iopub.execute_input":"2024-10-24T04:33:48.756921Z","iopub.status.idle":"2024-10-24T04:33:48.774446Z","shell.execute_reply.started":"2024-10-24T04:33:48.756864Z","shell.execute_reply":"2024-10-24T04:33:48.772939Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:47:31.041197Z","iopub.execute_input":"2024-10-24T04:47:31.041761Z","iopub.status.idle":"2024-10-24T04:47:33.707043Z","shell.execute_reply.started":"2024-10-24T04:47:31.041710Z","shell.execute_reply":"2024-10-24T04:47:33.705775Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.score(X_test,y_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.400731Z","iopub.execute_input":"2024-10-24T04:33:50.401231Z","iopub.status.idle":"2024-10-24T04:33:50.445164Z","shell.execute_reply.started":"2024-10-24T04:33:50.401175Z","shell.execute_reply":"2024-10-24T04:33:50.443808Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def quadratic_weighted_kappa(y_true, y_pred):\n    return cohen_kappa_score(y_true, y_pred, weights='quadratic')\n\ndef threshold_Rounder(oof_non_rounded, thresholds):\n    return np.where(oof_non_rounded < thresholds[0], 0,\n                    np.where(oof_non_rounded < thresholds[1], 1,\n                             np.where(oof_non_rounded < thresholds[2], 2, 3)))\n\ndef evaluate_predictions(thresholds, y_true, oof_non_rounded):\n    rounded_p = threshold_Rounder(oof_non_rounded, thresholds)\n    return -quadratic_weighted_kappa(y_true, rounded_p)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.447121Z","iopub.execute_input":"2024-10-24T04:33:50.447576Z","iopub.status.idle":"2024-10-24T04:33:50.456078Z","shell.execute_reply.started":"2024-10-24T04:33:50.447489Z","shell.execute_reply":"2024-10-24T04:33:50.454593Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train_pred = model.predict(X_train)\ny_test_pred = model.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.457576Z","iopub.execute_input":"2024-10-24T04:33:50.457961Z","iopub.status.idle":"2024-10-24T04:33:50.562644Z","shell.execute_reply.started":"2024-10-24T04:33:50.457920Z","shell.execute_reply":"2024-10-24T04:33:50.561386Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_kappa = quadratic_weighted_kappa(y_train, y_train_pred.round(0).astype(int))\ntest_kappa = quadratic_weighted_kappa(y_test, y_test_pred.round(0).astype(int))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.564477Z","iopub.execute_input":"2024-10-24T04:33:50.565007Z","iopub.status.idle":"2024-10-24T04:33:50.581972Z","shell.execute_reply.started":"2024-10-24T04:33:50.564948Z","shell.execute_reply":"2024-10-24T04:33:50.580514Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_kappa","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.583901Z","iopub.execute_input":"2024-10-24T04:33:50.584431Z","iopub.status.idle":"2024-10-24T04:33:50.598984Z","shell.execute_reply.started":"2024-10-24T04:33:50.584362Z","shell.execute_reply":"2024-10-24T04:33:50.597423Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y.shape, y_train_pred.shape, X_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.600798Z","iopub.execute_input":"2024-10-24T04:33:50.601275Z","iopub.status.idle":"2024-10-24T04:33:50.611102Z","shell.execute_reply.started":"2024-10-24T04:33:50.601228Z","shell.execute_reply":"2024-10-24T04:33:50.609582Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"KappaOPtimizer = minimize(evaluate_predictions,\n                              x0=[0.5, 1.5, 2.5], args=(y_train, y_train_pred), \n                              method='Nelder-Mead')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.613004Z","iopub.execute_input":"2024-10-24T04:33:50.613560Z","iopub.status.idle":"2024-10-24T04:33:50.950459Z","shell.execute_reply.started":"2024-10-24T04:33:50.613478Z","shell.execute_reply":"2024-10-24T04:33:50.949272Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"KappaOPtimizer.x","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.952277Z","iopub.execute_input":"2024-10-24T04:33:50.952697Z","iopub.status.idle":"2024-10-24T04:33:50.961350Z","shell.execute_reply.started":"2024-10-24T04:33:50.952652Z","shell.execute_reply":"2024-10-24T04:33:50.960000Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train_predictions = threshold_Rounder(y_train_pred, KappaOPtimizer.x)\n    \nquadratic_weighted_kappa(y_train, y_train_predictions)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.963402Z","iopub.execute_input":"2024-10-24T04:33:50.964302Z","iopub.status.idle":"2024-10-24T04:33:50.981158Z","shell.execute_reply.started":"2024-10-24T04:33:50.964240Z","shell.execute_reply":"2024-10-24T04:33:50.979605Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_test_predictions = threshold_Rounder(y_test_pred, KappaOPtimizer.x)\n    \nquadratic_weighted_kappa(y_test, y_test_predictions)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:50.982916Z","iopub.execute_input":"2024-10-24T04:33:50.983307Z","iopub.status.idle":"2024-10-24T04:33:50.995858Z","shell.execute_reply.started":"2024-10-24T04:33:50.983268Z","shell.execute_reply":"2024-10-24T04:33:50.994417Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X, y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:48:28.627483Z","iopub.execute_input":"2024-10-24T04:48:28.627992Z","iopub.status.idle":"2024-10-24T04:48:31.520350Z","shell.execute_reply.started":"2024-10-24T04:48:28.627947Z","shell.execute_reply":"2024-10-24T04:48:31.519212Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_pred = model.predict(X)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:51:26.849139Z","iopub.execute_input":"2024-10-24T04:51:26.849672Z","iopub.status.idle":"2024-10-24T04:51:26.960163Z","shell.execute_reply.started":"2024-10-24T04:51:26.849626Z","shell.execute_reply":"2024-10-24T04:51:26.958863Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"KappaOPtimizer = minimize(evaluate_predictions,\n                              x0=[0.5, 1.5, 2.5], args=(y, train_pred), \n                              method='Nelder-Mead')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:51:29.021993Z","iopub.execute_input":"2024-10-24T04:51:29.022432Z","iopub.status.idle":"2024-10-24T04:51:29.469538Z","shell.execute_reply.started":"2024-10-24T04:51:29.022394Z","shell.execute_reply":"2024-10-24T04:51:29.468201Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_pred = model.predict(test)\ntest_predictions = threshold_Rounder(test_pred, KappaOPtimizer.x)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:51:44.280217Z","iopub.execute_input":"2024-10-24T04:51:44.280709Z","iopub.status.idle":"2024-10-24T04:51:44.291566Z","shell.execute_reply.started":"2024-10-24T04:51:44.280665Z","shell.execute_reply":"2024-10-24T04:51:44.290219Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#test_predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:33:51.012568Z","iopub.execute_input":"2024-10-24T04:33:51.013152Z","iopub.status.idle":"2024-10-24T04:33:51.021950Z","shell.execute_reply.started":"2024-10-24T04:33:51.013091Z","shell.execute_reply":"2024-10-24T04:33:51.020741Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({\n        'id': sample['id'],\n        'sii': test_predictions\n    })","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:51:51.795270Z","iopub.execute_input":"2024-10-24T04:51:51.795747Z","iopub.status.idle":"2024-10-24T04:51:51.802847Z","shell.execute_reply.started":"2024-10-24T04:51:51.795700Z","shell.execute_reply":"2024-10-24T04:51:51.801156Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:51:55.184751Z","iopub.execute_input":"2024-10-24T04:51:55.185268Z","iopub.status.idle":"2024-10-24T04:51:55.201756Z","shell.execute_reply.started":"2024-10-24T04:51:55.185222Z","shell.execute_reply":"2024-10-24T04:51:55.200305Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-10-24T04:52:01.668424Z","iopub.execute_input":"2024-10-24T04:52:01.668942Z","iopub.status.idle":"2024-10-24T04:52:01.676581Z","shell.execute_reply.started":"2024-10-24T04:52:01.668898Z","shell.execute_reply":"2024-10-24T04:52:01.675011Z"}},"outputs":[],"execution_count":null}]}