{"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":true,"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-11-06T04:18:25.077854Z","iopub.execute_input":"2024-11-06T04:18:25.078295Z","iopub.status.idle":"2024-11-06T04:18:29.005915Z","shell.execute_reply.started":"2024-11-06T04:18:25.07824Z","shell.execute_reply":"2024-11-06T04:18:29.00447Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.gridspec as gridspec\nimport seaborn as sns\nimport warnings\nwarnings.filterwarnings('ignore', category=FutureWarning)\n\nsns.set(style=\"whitegrid\")\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2024-11-05T04:57:21.677339Z","iopub.execute_input":"2024-11-05T04:57:21.678107Z","iopub.status.idle":"2024-11-05T04:57:24.06025Z","shell.execute_reply.started":"2024-11-05T04:57:21.678046Z","shell.execute_reply":"2024-11-05T04:57:24.058603Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Final submission: Contain the id and associated Sii index in .csv file\n- id       sii\n- 000046df,  0\n- 000089ff,  1\n- 00012558,  2\n- 00017ccd,  3\n...\n","metadata":{}},{"cell_type":"markdown","source":"- What is the Sii index here ? \n\nSeverity Impairment Index (SII), which is a measure of problematic internet use. The SII is derived from the Parent-Child Internet Addiction Test (PCIAT) and is classified into four levels:\n\n- 0: None\n- 1: Mild\n- 2: Moderate\n- 3: Severe\n- This index represents different levels of internet usage impairment, with higher values indicating more severe problematic behavior related to internet use. The goal is to build a model that can accurately predict the SII based on the given physical activity and internet usage data, among other measures, in the Healthy Brain Network (HBN) dataset.","metadata":{}},{"cell_type":"markdown","source":"Data available to use","metadata":{}},{"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')\ndata_dict = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/data_dictionary.csv')","metadata":{"execution":{"iopub.status.busy":"2024-11-05T04:57:28.356051Z","iopub.execute_input":"2024-11-05T04:57:28.356688Z","iopub.status.idle":"2024-11-05T04:57:28.464052Z","shell.execute_reply.started":"2024-11-05T04:57:28.356639Z","shell.execute_reply":"2024-11-05T04:57:28.462897Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"- series_train.parquet: This file has time-series accelerometer data for each participant, capturing physical activity levels in detail over time. we can use this data to extract additional features like activity levels, movement patterns, and sleep quality.\n- am not using this now","metadata":{}},{"cell_type":"markdown","source":"Format for submission","metadata":{}},{"cell_type":"code","source":"sample_sub=pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/sample_submission.csv')\nsample_sub.head()","metadata":{"execution":{"iopub.status.busy":"2024-11-05T04:57:30.865023Z","iopub.execute_input":"2024-11-05T04:57:30.865507Z","iopub.status.idle":"2024-11-05T04:57:30.900687Z","shell.execute_reply.started":"2024-11-05T04:57:30.865463Z","shell.execute_reply":"2024-11-05T04:57:30.899369Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2024-11-05T04:57:33.360631Z","iopub.execute_input":"2024-11-05T04:57:33.361105Z","iopub.status.idle":"2024-11-05T04:57:33.411181Z","shell.execute_reply.started":"2024-11-05T04:57:33.36106Z","shell.execute_reply":"2024-11-05T04:57:33.409651Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"##### Modeling approach : multi class classification problem\n\nfor this Evaluation Strategy\n-  \"Quadratic Weighted Kappa\": \"sensitive to class imbalances\", therefore we need to cross validate to generelize well","metadata":{"execution":{"iopub.status.busy":"2024-10-16T03:08:04.530203Z","iopub.execute_input":"2024-10-16T03:08:04.530884Z","iopub.status.idle":"2024-10-16T03:08:04.546223Z","shell.execute_reply.started":"2024-10-16T03:08:04.530843Z","shell.execute_reply":"2024-10-16T03:08:04.545219Z"}}},{"cell_type":"markdown","source":"### EDA","metadata":{}},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2024-11-05T04:57:34.715413Z","iopub.execute_input":"2024-11-05T04:57:34.715824Z","iopub.status.idle":"2024-11-05T04:57:34.724463Z","shell.execute_reply.started":"2024-11-05T04:57:34.715786Z","shell.execute_reply":"2024-11-05T04:57:34.723048Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:35.203387Z","iopub.execute_input":"2024-11-05T04:57:35.203946Z","iopub.status.idle":"2024-11-05T04:57:35.212876Z","shell.execute_reply.started":"2024-11-05T04:57:35.203894Z","shell.execute_reply":"2024-11-05T04:57:35.211207Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"##### Test has lesser features than train , how to deal with it: \n- Identify the common features\n- use only those to train the model\n- use feature engineer to make similar features that are taken out to mimic them from the ones which are left out\n- this make sure there are not data leakage and robust and training and evaluation strategy","metadata":{}},{"cell_type":"markdown","source":"COls in train that are not in test are ...","metadata":{}},{"cell_type":"code","source":"train_cols = set(train.columns)\ntest_cols = set(test.columns)\ncolumns_not_in_test = sorted(list(train_cols - test_cols))\ncolumns_not_in_test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:35.891593Z","iopub.execute_input":"2024-11-05T04:57:35.892094Z","iopub.status.idle":"2024-11-05T04:57:35.902071Z","shell.execute_reply.started":"2024-11-05T04:57:35.892048Z","shell.execute_reply":"2024-11-05T04:57:35.90021Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data_dict[data_dict['Field'].isin(columns_not_in_test)]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:36.207302Z","iopub.execute_input":"2024-11-05T04:57:36.207764Z","iopub.status.idle":"2024-11-05T04:57:36.239538Z","shell.execute_reply.started":"2024-11-05T04:57:36.207718Z","shell.execute_reply":"2024-11-05T04:57:36.238328Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"so 'PCIAT-PCIAT_01' to 'PCIAT-PCIAT_20' are missing + 'PCIAT-PCIAT_Total', 'PCIAT-Season \n- we'll drop them for now and think about them later'","metadata":{}},{"cell_type":"code","source":"# Drop columns not in the test set from the train DataFrame\ncolumns_not_in_test = [col for col in columns_not_in_test if col != 'sii']\ntrain = train.drop(columns=columns_not_in_test)\ntrain.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:36.601348Z","iopub.execute_input":"2024-11-05T04:57:36.601816Z","iopub.status.idle":"2024-11-05T04:57:36.614923Z","shell.execute_reply.started":"2024-11-05T04:57:36.601771Z","shell.execute_reply":"2024-11-05T04:57:36.613293Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:36.906305Z","iopub.execute_input":"2024-11-05T04:57:36.90674Z","iopub.status.idle":"2024-11-05T04:57:36.94049Z","shell.execute_reply.started":"2024-11-05T04:57:36.906697Z","shell.execute_reply":"2024-11-05T04:57:36.939166Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Data Preparation and Cleaning\n- Handle Missing Values: Many features have missing values, so decide on a strategy:\n1. Imputation: Use mean, median, or a more complex imputation method (like KNN or MICE) to fill in missing values.\n2. Remove Columns/Rows: If some columns have excessive missing values (e.g., more than 70% missing), consider dropping them.\n3. duplicates\n","metadata":{}},{"cell_type":"code","source":"###missing values % \n# Calculate the percentage of missing values (NaN and empty spaces) in each column\nmissing_percentage = train.apply(lambda x: (x.isna() | (x == '')).mean() * 100)\n\n# Filter to show only columns with missing values\nmissing_percentage = missing_percentage[missing_percentage > 0]\n\n# Display columns with missing values and their missing percentage\nprint(missing_percentage)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:37.282299Z","iopub.execute_input":"2024-11-05T04:57:37.283533Z","iopub.status.idle":"2024-11-05T04:57:37.332292Z","shell.execute_reply.started":"2024-11-05T04:57:37.283464Z","shell.execute_reply":"2024-11-05T04:57:37.331003Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"dropping anything more thatn 70% ","metadata":{}},{"cell_type":"code","source":"# Identify columns with missing percentage greater than 70%\ncolumns_to_drop = missing_percentage[missing_percentage > 70].index\n\n# Drop these columns from the DataFrame\ntrain = train.drop(columns=columns_to_drop)\n\n# Display the shape of the updated DataFrame\ntrain.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:37.738054Z","iopub.execute_input":"2024-11-05T04:57:37.738469Z","iopub.status.idle":"2024-11-05T04:57:37.749584Z","shell.execute_reply.started":"2024-11-05T04:57:37.738428Z","shell.execute_reply":"2024-11-05T04:57:37.748011Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = test[train.columns.drop('sii')]\ntest.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:38.006798Z","iopub.execute_input":"2024-11-05T04:57:38.007289Z","iopub.status.idle":"2024-11-05T04:57:38.017187Z","shell.execute_reply.started":"2024-11-05T04:57:38.007244Z","shell.execute_reply":"2024-11-05T04:57:38.015696Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Filter to show only columns with missing values\nmissing_percentage = missing_percentage[missing_percentage > 0]\n\n# Display columns with missing values and their missing percentage\nprint(missing_percentage)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:38.207479Z","iopub.execute_input":"2024-11-05T04:57:38.208909Z","iopub.status.idle":"2024-11-05T04:57:38.218187Z","shell.execute_reply.started":"2024-11-05T04:57:38.208854Z","shell.execute_reply":"2024-11-05T04:57:38.216611Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"i want to identify patterns in \"missingness\"","metadata":{}},{"cell_type":"code","source":"missing_percentage = train.apply(lambda x: (x.isna() | (x == '')).mean() * 100)\nmissing_percentage = missing_percentage[missing_percentage > 0]\ngrouped_missing = {}\nfor pct, cols in missing_percentage.groupby(missing_percentage):\n    grouped_missing[pct] = list(cols.index)\ngrouped_missing","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:38.739533Z","iopub.execute_input":"2024-11-05T04:57:38.740008Z","iopub.status.idle":"2024-11-05T04:57:38.79864Z","shell.execute_reply.started":"2024-11-05T04:57:38.739952Z","shell.execute_reply":"2024-11-05T04:57:38.796667Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"clearly features ['BIA-BIA_Activity_Level_num',\r\n  'BIA-BIA_BMC',\r\n  'BIA-BIA_BMI',\r\n  'BIA-BIA_BMR',\r\n  'BIA-BIA_DEE',\r\n  'BIA-BIA_ECW',\r\n  'BIA-BIA_FFM',\r\n  'BIA-BIA_FFMI',\r\n  'BIA-BIA_FMI',\r\n  'BIA-BIA_Fat',\r\n  'BIA-BIA_Frame_num',\r\n  'BIA-BIA_ICW',\r\n  'BIA-BIA_LDM',\r\n  'BIA-BIA_LST',\r\n  'BIA-BIA_SMM',\r\n  \n  \n  - are all missing together everywhere 'BIA-BIA_TBW']","metadata":{}},{"cell_type":"markdown","source":"### Imputation strategy: KNN (for now) - for numerical features ","metadata":{}},{"cell_type":"code","source":"from sklearn.impute import KNNImputer","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:39.824431Z","iopub.execute_input":"2024-11-05T04:57:39.825013Z","iopub.status.idle":"2024-11-05T04:57:40.475781Z","shell.execute_reply.started":"2024-11-05T04:57:39.824962Z","shell.execute_reply":"2024-11-05T04:57:40.474511Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"for numerical cols ","metadata":{}},{"cell_type":"markdown","source":"numerical imputaion for train","metadata":{}},{"cell_type":"code","source":"# Drop the 'sii' column temporarily from the numerical columns with missing values\nnumerical_missing_percentage = missing_percentage[train[missing_percentage.index].select_dtypes(include=['float64', 'int64']).columns]\nnumerical_missing_percentage = numerical_missing_percentage.drop('sii', errors='ignore')\n\n# Select only the numerical columns in train with missing values, excluding 'sii'\ntrain_numerical_missing = train[numerical_missing_percentage.index]\n\n# Initialize the KNN imputer\nknn_imputer = KNNImputer(n_neighbors=5)\n\n# Perform KNN imputation on the selected numerical columns with missing values\ntrain_imputed_numerical = knn_imputer.fit_transform(train_numerical_missing)\n\n# Update the train DataFrame with the imputed values for the selected columns\ntrain[numerical_missing_percentage.index] = train_imputed_numerical","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-05T04:57:40.566389Z","iopub.execute_input":"2024-11-05T04:57:40.566856Z","iopub.status.idle":"2024-11-05T04:57:45.604436Z","shell.execute_reply.started":"2024-11-05T04:57:40.566813Z","shell.execute_reply":"2024-11-05T04:57:45.603195Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"for test","metadata":{}},{"cell_type":"code","source":"# Drop the 'sii' column temporarily from the numerical columns with missing values\nnumerical_missing_percentage = missing_percentage[test[missing_percentage.index].select_dtypes(include=['float64', 'int64']).columns]\n\n# Select only the numerical columns in train with missing values, excluding 'sii'\ntest_numerical_missing = test[numerical_missing_percentage.index]\n\n# Initialize the KNN imputer\nknn_imputer = KNNImputer(n_neighbors=5)\n\n# Perform KNN imputation on the selected numerical columns with missing values\ntest_imputed_numerical = knn_imputer.fit_transform(test_numerical_missing)\n\n# Update the train DataFrame with the imputed values for the selected columns\ntest[numerical_missing_percentage.index] = test_imputed_numerical","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T21:34:32.402255Z","iopub.execute_input":"2024-11-02T21:34:32.403307Z","iopub.status.idle":"2024-11-02T21:34:32.702149Z","shell.execute_reply.started":"2024-11-02T21:34:32.403258Z","shell.execute_reply":"2024-11-02T21:34:32.699874Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['sii'] = train['sii'].astype('object')\ncategorical_missing_percentage = missing_percentage[train[missing_percentage.index].select_dtypes(include=['object', 'category']).columns]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:46:32.749945Z","iopub.execute_input":"2024-11-02T20:46:32.750779Z","iopub.status.idle":"2024-11-02T20:46:32.763304Z","shell.execute_reply.started":"2024-11-02T20:46:32.750736Z","shell.execute_reply":"2024-11-02T20:46:32.762308Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from scipy.stats import mode  # Ensure this import is included\n\n# Get the categorical columns with missing values\ncategorical_missing_cols = categorical_missing_percentage.index\n\n# Define a custom function for approximate KNN imputation on categorical data\ndef knn_impute_categorical(df, categorical_columns, k=5):\n    for col in categorical_columns:\n        # Get indices of missing values in the current column\n        missing_indices = df[df[col].isnull()].index\n\n        # Impute each missing value based on mode of random k neighbors\n        for idx in missing_indices:\n            # Define \"neighbors\" by sampling from other rows as a proxy for KNN\n            neighbors = df.drop(index=idx).sample(n=k, replace=True)\n\n            # Impute the missing value with the mode of the neighbors for this column\n            if not neighbors[col].dropna().empty:\n                df.loc[idx, col] = neighbors[col].dropna().mode()[0]  # Using pandas mode for categorical data\n            else:\n                df.loc[idx, col] = 'Unknown'  # Fallback if no valid neighbors\n    \n    return df\n\n# Apply the custom KNN imputation function only on the extracted categorical columns with missing values\ntrain = knn_impute_categorical(train, categorical_missing_cols, k=5)\n\n# Display the updated DataFrame\ntrain.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:46:34.333753Z","iopub.execute_input":"2024-11-02T20:46:34.334219Z","iopub.status.idle":"2024-11-02T20:47:31.006476Z","shell.execute_reply.started":"2024-11-02T20:46:34.334178Z","shell.execute_reply":"2024-11-02T20:47:31.005403Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['sii'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:47:31.008097Z","iopub.execute_input":"2024-11-02T20:47:31.008421Z","iopub.status.idle":"2024-11-02T20:47:31.017327Z","shell.execute_reply.started":"2024-11-02T20:47:31.008387Z","shell.execute_reply":"2024-11-02T20:47:31.016201Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Calculate the percentage of missing values (NaN and empty spaces) in each column\nmissing_percentage = train.apply(lambda x: (x.isna() | (x == '')).mean() * 100)\n\n# Filter to show only columns with missing values\nmissing_percentage = missing_percentage[missing_percentage > 0]\n\n# Display columns with missing values and their missing percentage\nprint(missing_percentage)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:18.965447Z","iopub.execute_input":"2024-11-02T20:52:18.966066Z","iopub.status.idle":"2024-11-02T20:52:19.007112Z","shell.execute_reply.started":"2024-11-02T20:52:18.966022Z","shell.execute_reply":"2024-11-02T20:52:19.006067Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"no more missing values","metadata":{}},{"cell_type":"code","source":"#duplicates\nduplicates = train[train.duplicated()]\nprint(f\"Number of duplicate rows: {len(duplicates)}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:21.8896Z","iopub.execute_input":"2024-11-02T20:52:21.890053Z","iopub.status.idle":"2024-11-02T20:52:21.916703Z","shell.execute_reply.started":"2024-11-02T20:52:21.890011Z","shell.execute_reply":"2024-11-02T20:52:21.9156Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Modelling ","metadata":{}},{"cell_type":"markdown","source":"### LGBM ","metadata":{}},{"cell_type":"code","source":"import lightgbm as lgb\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:25.022912Z","iopub.execute_input":"2024-11-02T20:52:25.023339Z","iopub.status.idle":"2024-11-02T20:52:26.365788Z","shell.execute_reply.started":"2024-11-02T20:52:25.023301Z","shell.execute_reply":"2024-11-02T20:52:26.364716Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Step 1: Identify categorical columns with missing values\ncategorical_cols = train.select_dtypes(include=['object', 'category']).columns\n# Convert these columns to 'category' dtype in pandas\ntrain[categorical_cols] = train[categorical_cols].astype('category')\nprint(len(categorical_cols))\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:26.743934Z","iopub.execute_input":"2024-11-02T20:52:26.744639Z","iopub.status.idle":"2024-11-02T20:52:26.77668Z","shell.execute_reply.started":"2024-11-02T20:52:26.744595Z","shell.execute_reply":"2024-11-02T20:52:26.775344Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical_cols = train.select_dtypes(include=['number']).columns\nnum_numerical_cols = len(numerical_cols)\nprint(f\"Number of numerical columns: {num_numerical_cols}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:32.770275Z","iopub.execute_input":"2024-11-02T20:52:32.770703Z","iopub.status.idle":"2024-11-02T20:52:32.782631Z","shell.execute_reply.started":"2024-11-02T20:52:32.770664Z","shell.execute_reply":"2024-11-02T20:52:32.781312Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[categorical_cols] ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:35.076054Z","iopub.execute_input":"2024-11-02T20:52:35.07648Z","iopub.status.idle":"2024-11-02T20:52:35.103334Z","shell.execute_reply.started":"2024-11-02T20:52:35.076438Z","shell.execute_reply":"2024-11-02T20:52:35.102244Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:39.383518Z","iopub.execute_input":"2024-11-02T20:52:39.384476Z","iopub.status.idle":"2024-11-02T20:52:39.390808Z","shell.execute_reply.started":"2024-11-02T20:52:39.384431Z","shell.execute_reply":"2024-11-02T20:52:39.389736Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Step 2: Prepare data for training\n# Assuming 'sii' is the target variable\nX = train.drop(columns=['sii','id'])\ny = train['sii']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:40.57722Z","iopub.execute_input":"2024-11-02T20:52:40.577595Z","iopub.status.idle":"2024-11-02T20:52:40.587053Z","shell.execute_reply.started":"2024-11-02T20:52:40.577559Z","shell.execute_reply":"2024-11-02T20:52:40.585808Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:53:33.938877Z","iopub.execute_input":"2024-11-02T20:53:33.939783Z","iopub.status.idle":"2024-11-02T20:53:33.979061Z","shell.execute_reply.started":"2024-11-02T20:53:33.939736Z","shell.execute_reply":"2024-11-02T20:53:33.977895Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:52:48.525592Z","iopub.execute_input":"2024-11-02T20:52:48.526283Z","iopub.status.idle":"2024-11-02T20:52:48.562867Z","shell.execute_reply.started":"2024-11-02T20:52:48.526242Z","shell.execute_reply":"2024-11-02T20:52:48.561862Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T20:36:52.057616Z","iopub.execute_input":"2024-11-02T20:36:52.058401Z","iopub.status.idle":"2024-11-02T20:36:52.067353Z","shell.execute_reply.started":"2024-11-02T20:36:52.058358Z","shell.execute_reply":"2024-11-02T20:36:52.066338Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### We try Auto ml tools to get baseline model","metadata":{}},{"cell_type":"markdown","source":"####  1. H2O","metadata":{}},{"cell_type":"code","source":"pip install h2o","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T21:04:33.978615Z","iopub.execute_input":"2024-11-02T21:04:33.97911Z","iopub.status.idle":"2024-11-02T21:04:48.425212Z","shell.execute_reply.started":"2024-11-02T21:04:33.979065Z","shell.execute_reply":"2024-11-02T21:04:48.423935Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import h2o\nfrom h2o.automl import H2OAutoML\n\n# Start the H2O server\nh2o.init()\ntrain_h2o = h2o.H2OFrame(train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T21:06:07.902987Z","iopub.execute_input":"2024-11-02T21:06:07.90347Z","iopub.status.idle":"2024-11-02T21:06:20.290384Z","shell.execute_reply.started":"2024-11-02T21:06:07.903428Z","shell.execute_reply":"2024-11-02T21:06:20.288531Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"target = 'sii'  # Target variable\nfeatures = train.columns.drop(['sii', 'id']).tolist()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T21:06:37.448331Z","iopub.execute_input":"2024-11-02T21:06:37.449005Z","iopub.status.idle":"2024-11-02T21:06:37.457882Z","shell.execute_reply.started":"2024-11-02T21:06:37.448953Z","shell.execute_reply":"2024-11-02T21:06:37.455889Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Initialize AutoML\naml = H2OAutoML(max_models=20, seed=1, balance_classes=True)\n\n# Train AutoML\naml.train(x=features, y=target, training_frame=train_h2o)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T21:06:49.944369Z","iopub.execute_input":"2024-11-02T21:06:49.945429Z","iopub.status.idle":"2024-11-02T21:09:42.524872Z","shell.execute_reply.started":"2024-11-02T21:06:49.945384Z","shell.execute_reply":"2024-11-02T21:09:42.523625Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-02T21:16:09.715329Z","iopub.execute_input":"2024-11-02T21:16:09.715839Z","iopub.status.idle":"2024-11-02T21:16:09.766773Z","shell.execute_reply.started":"2024-11-02T21:16:09.71578Z","shell.execute_reply":"2024-11-02T21:16:09.765714Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}