{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":96164,"databundleVersionId":11418275,"sourceType":"competition"}],"dockerImageVersionId":31040,"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","trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:14.229654Z","iopub.execute_input":"2025-07-07T04:12:14.229990Z","iopub.status.idle":"2025-07-07T04:12:14.617147Z","shell.execute_reply.started":"2025-07-07T04:12:14.229963Z","shell.execute_reply":"2025-07-07T04:12:14.616361Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Importing Required Libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt \nimport seaborn as sns\n%matplotlib inline ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:14.618602Z","iopub.execute_input":"2025-07-07T04:12:14.618985Z","iopub.status.idle":"2025-07-07T04:12:15.278665Z","shell.execute_reply.started":"2025-07-07T04:12:14.618963Z","shell.execute_reply":"2025-07-07T04:12:15.277903Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Read Data","metadata":{}},{"cell_type":"code","source":"train = pd.read_parquet(\"/kaggle/input/drw-crypto-market-prediction/train.parquet\")\ntest = pd.read_parquet(\"/kaggle/input/drw-crypto-market-prediction/test.parquet\")\nsample_submission = pd.read_csv(\"/kaggle/input/drw-crypto-market-prediction/sample_submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:15.279512Z","iopub.execute_input":"2025-07-07T04:12:15.279883Z","iopub.status.idle":"2025-07-07T04:12:27.945883Z","shell.execute_reply.started":"2025-07-07T04:12:15.279857Z","shell.execute_reply":"2025-07-07T04:12:27.945016Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"##top 5 rows in train df\ntrain.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:27.946809Z","iopub.execute_input":"2025-07-07T04:12:27.947112Z","iopub.status.idle":"2025-07-07T04:12:27.972030Z","shell.execute_reply.started":"2025-07-07T04:12:27.947079Z","shell.execute_reply":"2025-07-07T04:12:27.971108Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:27.974460Z","iopub.execute_input":"2025-07-07T04:12:27.974996Z","iopub.status.idle":"2025-07-07T04:12:28.000450Z","shell.execute_reply.started":"2025-07-07T04:12:27.974971Z","shell.execute_reply":"2025-07-07T04:12:27.999389Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_submission","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:28.001584Z","iopub.execute_input":"2025-07-07T04:12:28.001926Z","iopub.status.idle":"2025-07-07T04:12:28.025617Z","shell.execute_reply.started":"2025-07-07T04:12:28.001894Z","shell.execute_reply":"2025-07-07T04:12:28.024590Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## EDA","metadata":{}},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:28.026577Z","iopub.execute_input":"2025-07-07T04:12:28.026909Z","iopub.status.idle":"2025-07-07T04:12:29.653086Z","shell.execute_reply.started":"2025-07-07T04:12:28.026882Z","shell.execute_reply":"2025-07-07T04:12:29.652201Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:29.654021Z","iopub.execute_input":"2025-07-07T04:12:29.654338Z","iopub.status.idle":"2025-07-07T04:12:31.295152Z","shell.execute_reply.started":"2025-07-07T04:12:29.654309Z","shell.execute_reply":"2025-07-07T04:12:31.294287Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical_features = [feature for feature in train.columns if train[feature].dtype!='O']\ncategorical_features = [feature for feature in train.columns if train[feature].dtype=='O']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.296128Z","iopub.execute_input":"2025-07-07T04:12:31.296440Z","iopub.status.idle":"2025-07-07T04:12:31.325060Z","shell.execute_reply.started":"2025-07-07T04:12:31.296414Z","shell.execute_reply":"2025-07-07T04:12:31.324207Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical_features","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.325990Z","iopub.execute_input":"2025-07-07T04:12:31.326343Z","iopub.status.idle":"2025-07-07T04:12:31.348943Z","shell.execute_reply.started":"2025-07-07T04:12:31.326316Z","shell.execute_reply":"2025-07-07T04:12:31.347768Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Total Numerical Features:\",len(numerical_features))\nprint(\"Total Categorical Features:\",len(categorical_features))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.349963Z","iopub.execute_input":"2025-07-07T04:12:31.350255Z","iopub.status.idle":"2025-07-07T04:12:31.362824Z","shell.execute_reply.started":"2025-07-07T04:12:31.350235Z","shell.execute_reply":"2025-07-07T04:12:31.361838Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"categorical_features","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.363869Z","iopub.execute_input":"2025-07-07T04:12:31.364202Z","iopub.status.idle":"2025-07-07T04:12:31.383017Z","shell.execute_reply.started":"2025-07-07T04:12:31.364172Z","shell.execute_reply":"2025-07-07T04:12:31.382200Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### Observation:\n- There is no even a single categorical feature ","metadata":{}},{"cell_type":"code","source":"# # with the following function we can select highly correlated features\n# # it will remove the first feature that is correlated with anything other feature\n\n# def correlation(dataset, threshold):\n#     col_corr = set()  # Set of all the names of correlated columns\n#     corr_matrix = dataset.corr()\n#     for i in range(len(corr_matrix.columns)):\n#         for j in range(i):\n#             if(corr_matrix.iloc[i, j]) > threshold: # we are interested in absolute coeff value\n#                 colname = corr_matrix.columns[i]  # getting the name of column\n#                 col_corr.add(colname)\n#     return col_corr","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.384025Z","iopub.execute_input":"2025-07-07T04:12:31.384308Z","iopub.status.idle":"2025-07-07T04:12:31.397090Z","shell.execute_reply.started":"2025-07-07T04:12:31.384288Z","shell.execute_reply":"2025-07-07T04:12:31.396097Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# highly_correlated_feature = correlation(train,0.9)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.400145Z","iopub.execute_input":"2025-07-07T04:12:31.400506Z","iopub.status.idle":"2025-07-07T04:12:31.412517Z","shell.execute_reply.started":"2025-07-07T04:12:31.400485Z","shell.execute_reply":"2025-07-07T04:12:31.411616Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.413518Z","iopub.execute_input":"2025-07-07T04:12:31.413873Z","iopub.status.idle":"2025-07-07T04:12:31.443086Z","shell.execute_reply.started":"2025-07-07T04:12:31.413844Z","shell.execute_reply":"2025-07-07T04:12:31.442253Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Shape of train:\",train.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.443945Z","iopub.execute_input":"2025-07-07T04:12:31.444241Z","iopub.status.idle":"2025-07-07T04:12:31.456136Z","shell.execute_reply.started":"2025-07-07T04:12:31.444213Z","shell.execute_reply":"2025-07-07T04:12:31.455264Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### Observation: There exist some values with are either infinity or out of range of float64 so for this let's replace those values with np.nan then drop all nan values","metadata":{}},{"cell_type":"code","source":"train.replace([np.inf, -np.inf], np.nan, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:31.457010Z","iopub.execute_input":"2025-07-07T04:12:31.457266Z","iopub.status.idle":"2025-07-07T04:12:34.829340Z","shell.execute_reply.started":"2025-07-07T04:12:31.457246Z","shell.execute_reply":"2025-07-07T04:12:34.828572Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isnull().sum().sort_values(ascending=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:34.830160Z","iopub.execute_input":"2025-07-07T04:12:34.830428Z","iopub.status.idle":"2025-07-07T04:12:36.420613Z","shell.execute_reply.started":"2025-07-07T04:12:34.830409Z","shell.execute_reply":"2025-07-07T04:12:36.419485Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isnull().sum().sort_values(ascending=False)[lambda x: x > 0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:36.421551Z","iopub.execute_input":"2025-07-07T04:12:36.421883Z","iopub.status.idle":"2025-07-07T04:12:38.036026Z","shell.execute_reply.started":"2025-07-07T04:12:36.421854Z","shell.execute_reply":"2025-07-07T04:12:38.035317Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cols_to_drop = train.isnull().sum().sort_values(ascending=False)[lambda x: x > 0].index","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:38.036748Z","iopub.execute_input":"2025-07-07T04:12:38.036955Z","iopub.status.idle":"2025-07-07T04:12:39.632257Z","shell.execute_reply.started":"2025-07-07T04:12:38.036938Z","shell.execute_reply":"2025-07-07T04:12:39.631513Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cols_to_drop","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:39.633043Z","iopub.execute_input":"2025-07-07T04:12:39.633265Z","iopub.status.idle":"2025-07-07T04:12:39.640051Z","shell.execute_reply.started":"2025-07-07T04:12:39.633248Z","shell.execute_reply":"2025-07-07T04:12:39.639370Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.drop(columns=cols_to_drop, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:39.640980Z","iopub.execute_input":"2025-07-07T04:12:39.641302Z","iopub.status.idle":"2025-07-07T04:12:40.840761Z","shell.execute_reply.started":"2025-07-07T04:12:39.641275Z","shell.execute_reply":"2025-07-07T04:12:40.839853Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:40.841766Z","iopub.execute_input":"2025-07-07T04:12:40.842061Z","iopub.status.idle":"2025-07-07T04:12:40.847583Z","shell.execute_reply.started":"2025-07-07T04:12:40.842034Z","shell.execute_reply":"2025-07-07T04:12:40.846443Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Independent and Target Fearure","metadata":{}},{"cell_type":"code","source":"X = train.drop(columns=['label']) ## Independent features\ny = train['label']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:40.848489Z","iopub.execute_input":"2025-07-07T04:12:40.848833Z","iopub.status.idle":"2025-07-07T04:12:42.170351Z","shell.execute_reply.started":"2025-07-07T04:12:40.848808Z","shell.execute_reply":"2025-07-07T04:12:42.169460Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.feature_selection import SelectKBest, f_regression\n\nselector = SelectKBest(score_func=f_regression, k=30)  # choose top 30\nX_selected = selector.fit_transform(X, y)\n\nmask = selector.get_support()\n\n# Get names of selected features\nselected_features = X.columns[mask]\nprint(selected_features)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:46.254506Z","iopub.execute_input":"2025-07-07T04:12:46.254847Z","iopub.status.idle":"2025-07-07T04:12:48.963738Z","shell.execute_reply.started":"2025-07-07T04:12:46.254824Z","shell.execute_reply":"2025-07-07T04:12:48.962897Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"## Previous Selected Features\n# cols_to_keep = ['bid_qty','ask_qty','buy_qty','sell_qty','volume',\n#         'X18', 'X19', 'X20', 'X21', 'X22', 'X23', 'X26', 'X27', 'X28', 'X29',\n#        'X30', 'X175', 'X181', 'X217', 'X218', 'X219', 'X225', 'X226', 'X281',\n#        'X283', 'X285', 'X286', 'X287', 'X288', 'X289', 'X290', 'X291', 'X292',\n#        'X293', 'X294', 'X295', 'X296', 'X297', 'X298', 'X299', 'X300', 'X301',\n#        'X302', 'X303', 'X465', 'X466', 'X524', 'X531', 'X598', 'X856', 'X857',\n#        'X858', 'X860', 'X861', 'X863'] ## keeping only these features for training \n\n# cols_to_keep = ['bid_qty','ask_qty','buy_qty','sell_qty','volume',\n#         'X19', 'X20', 'X21', 'X22', 'X27', 'X28', 'X29', 'X218', 'X219', 'X287',\n#        'X289', 'X291', 'X293', 'X295', 'X531', 'X598', 'X857', 'X858', 'X860',\n#        'X863'] ## keeping only these features for training \n\n# cols_to_keep = ['X19', 'X20', 'X21', 'X22', 'X27', 'X28', 'X29', 'X218', 'X219', 'X287',\n#        'X289', 'X291', 'X293', 'X295', 'X531', 'X598', 'X857', 'X858', 'X860',\n#        'X863'] ## keeping only these features for training \n\n## keeping top \nX = X[selected_features]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:52.766820Z","iopub.execute_input":"2025-07-07T04:12:52.767154Z","iopub.status.idle":"2025-07-07T04:12:52.832497Z","shell.execute_reply.started":"2025-07-07T04:12:52.767115Z","shell.execute_reply":"2025-07-07T04:12:52.831601Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:55.082537Z","iopub.execute_input":"2025-07-07T04:12:55.082895Z","iopub.status.idle":"2025-07-07T04:12:55.103510Z","shell.execute_reply.started":"2025-07-07T04:12:55.082870Z","shell.execute_reply":"2025-07-07T04:12:55.102445Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:12:55.297173Z","iopub.execute_input":"2025-07-07T04:12:55.297536Z","iopub.status.idle":"2025-07-07T04:12:55.305036Z","shell.execute_reply.started":"2025-07-07T04:12:55.297501Z","shell.execute_reply":"2025-07-07T04:12:55.304204Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Train Test Split","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:00.338333Z","iopub.execute_input":"2025-07-07T04:13:00.338635Z","iopub.status.idle":"2025-07-07T04:13:00.525712Z","shell.execute_reply.started":"2025-07-07T04:13:00.338613Z","shell.execute_reply":"2025-07-07T04:13:00.524598Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Shape of X_train:\",X_train.shape)\nprint(\"Shape of X_test:\",X_test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:00.527022Z","iopub.execute_input":"2025-07-07T04:13:00.527381Z","iopub.status.idle":"2025-07-07T04:13:00.532489Z","shell.execute_reply.started":"2025-07-07T04:13:00.527353Z","shell.execute_reply":"2025-07-07T04:13:00.531754Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Shape of y_train:\",y_train.shape)\nprint(\"Shape of y_test:\",y_test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:00.694343Z","iopub.execute_input":"2025-07-07T04:13:00.694672Z","iopub.status.idle":"2025-07-07T04:13:00.700185Z","shell.execute_reply.started":"2025-07-07T04:13:00.694646Z","shell.execute_reply":"2025-07-07T04:13:00.699260Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Scalling the features","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:04.948370Z","iopub.execute_input":"2025-07-07T04:13:04.948981Z","iopub.status.idle":"2025-07-07T04:13:04.953097Z","shell.execute_reply.started":"2025-07-07T04:13:04.948957Z","shell.execute_reply":"2025-07-07T04:13:04.952184Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.compose import ColumnTransformer","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:05.110127Z","iopub.execute_input":"2025-07-07T04:13:05.110442Z","iopub.status.idle":"2025-07-07T04:13:05.123192Z","shell.execute_reply.started":"2025-07-07T04:13:05.110417Z","shell.execute_reply":"2025-07-07T04:13:05.122452Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"scaler = StandardScaler()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:05.288654Z","iopub.execute_input":"2025-07-07T04:13:05.289204Z","iopub.status.idle":"2025-07-07T04:13:05.293240Z","shell.execute_reply.started":"2025-07-07T04:13:05.289179Z","shell.execute_reply":"2025-07-07T04:13:05.292278Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical_features_list = [feature for feature in X.columns if X[feature].dtype!='O']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:07.393908Z","iopub.execute_input":"2025-07-07T04:13:07.394811Z","iopub.status.idle":"2025-07-07T04:13:07.400019Z","shell.execute_reply.started":"2025-07-07T04:13:07.394780Z","shell.execute_reply":"2025-07-07T04:13:07.399061Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"transformer = ColumnTransformer(transformers=[\n    ('standard_scalling', scaler, numerical_features_list),\n], remainder='passthrough')  # Keeps other columns as they are","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:07.724689Z","iopub.execute_input":"2025-07-07T04:13:07.725341Z","iopub.status.idle":"2025-07-07T04:13:07.729294Z","shell.execute_reply.started":"2025-07-07T04:13:07.725313Z","shell.execute_reply":"2025-07-07T04:13:07.728427Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_trf = transformer.fit_transform(X_train)\nX_test_trf = transformer.transform(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:08.180917Z","iopub.execute_input":"2025-07-07T04:13:08.181658Z","iopub.status.idle":"2025-07-07T04:13:08.529541Z","shell.execute_reply.started":"2025-07-07T04:13:08.181628Z","shell.execute_reply":"2025-07-07T04:13:08.528651Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Model Training and Evaluation","metadata":{}},{"cell_type":"code","source":"## Model Training and Model Selection\nfrom sklearn.metrics import r2_score,mean_squared_error,mean_absolute_error,mean_squared_log_error","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:10.925395Z","iopub.execute_input":"2025-07-07T04:13:10.925857Z","iopub.status.idle":"2025-07-07T04:13:10.930160Z","shell.execute_reply.started":"2025-07-07T04:13:10.925823Z","shell.execute_reply":"2025-07-07T04:13:10.929317Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"## Creating a function to evaluat model\ndef evaluate_model(true, predicted):\n    mae=mean_absolute_error(true,predicted)\n    mse=mean_squared_error(true,predicted)\n    rmse=np.sqrt(mse)\n    r2=r2_score(true,predicted)\n\n    r = np.corrcoef(true, predicted)[0, 1]\n    print()\n    print(f\"Pearson Correlation Coefficient: {r}\")\n    print(\"R2 Score:{:.4f}\".format(r2))\n    print(\"MAE:{:.4f}\".format(mae))\n    print(\"MSE:{:.4f}\".format(mse))\n    print(\"RMSE:{:.4f}\".format(rmse))\n    \n    # ---------\n    return 0","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:12.395659Z","iopub.execute_input":"2025-07-07T04:13:12.396344Z","iopub.status.idle":"2025-07-07T04:13:12.401901Z","shell.execute_reply.started":"2025-07-07T04:13:12.396317Z","shell.execute_reply":"2025-07-07T04:13:12.400901Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"##### Doing same preprocessing on test data ","metadata":{}},{"cell_type":"code","source":"test=test.drop(columns=['label']) ## dropping target feature from test dataframe\ntest = test[selected_features]\ntest_trf = transformer.transform(test) ## scalling","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:35.159915Z","iopub.execute_input":"2025-07-07T04:13:35.160530Z","iopub.status.idle":"2025-07-07T04:13:35.421729Z","shell.execute_reply.started":"2025-07-07T04:13:35.160503Z","shell.execute_reply":"2025-07-07T04:13:35.420720Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_submission","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:40.363234Z","iopub.execute_input":"2025-07-07T04:13:40.363875Z","iopub.status.idle":"2025-07-07T04:13:40.372744Z","shell.execute_reply.started":"2025-07-07T04:13:40.363846Z","shell.execute_reply":"2025-07-07T04:13:40.371870Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_trf.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:40.616819Z","iopub.execute_input":"2025-07-07T04:13:40.617153Z","iopub.status.idle":"2025-07-07T04:13:40.622810Z","shell.execute_reply.started":"2025-07-07T04:13:40.617131Z","shell.execute_reply":"2025-07-07T04:13:40.621952Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Building ANN","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:13:44.297047Z","iopub.execute_input":"2025-07-07T04:13:44.297930Z","iopub.status.idle":"2025-07-07T04:14:00.150042Z","shell.execute_reply.started":"2025-07-07T04:13:44.297897Z","shell.execute_reply":"2025-07-07T04:14:00.149071Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = Sequential()\nmodel.add(Dense(32, input_dim=30, activation=\"relu\"))\nmodel.add(Dense(128, activation=\"relu\"))\nmodel.add(Dense(1, activation=\"linear\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:14:10.663767Z","iopub.execute_input":"2025-07-07T04:14:10.664110Z","iopub.status.idle":"2025-07-07T04:14:10.699124Z","shell.execute_reply.started":"2025-07-07T04:14:10.664084Z","shell.execute_reply":"2025-07-07T04:14:10.698104Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.compile(loss='mse', optimizer='adam', metrics=['mse'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:14:11.570546Z","iopub.execute_input":"2025-07-07T04:14:11.571228Z","iopub.status.idle":"2025-07-07T04:14:11.580094Z","shell.execute_reply.started":"2025-07-07T04:14:11.571200Z","shell.execute_reply":"2025-07-07T04:14:11.579268Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"history = model.fit(X_train_trf, y_train, epochs=50,\n                    validation_data = (X_test_trf, y_test),\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:14:12.490366Z","iopub.execute_input":"2025-07-07T04:14:12.490689Z","iopub.status.idle":"2025-07-07T04:34:29.999313Z","shell.execute_reply.started":"2025-07-07T04:14:12.490665Z","shell.execute_reply":"2025-07-07T04:34:29.998012Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train_pred.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T04:58:53.032837Z","iopub.execute_input":"2025-07-07T04:58:53.033148Z","iopub.status.idle":"2025-07-07T04:58:53.038654Z","shell.execute_reply.started":"2025-07-07T04:58:53.033124Z","shell.execute_reply":"2025-07-07T04:58:53.037926Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"type(y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:05:04.716116Z","iopub.execute_input":"2025-07-07T05:05:04.716439Z","iopub.status.idle":"2025-07-07T05:05:04.722627Z","shell.execute_reply.started":"2025-07-07T05:05:04.716414Z","shell.execute_reply":"2025-07-07T05:05:04.721888Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"type(y_train_pred)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:05:11.690630Z","iopub.execute_input":"2025-07-07T05:05:11.691535Z","iopub.status.idle":"2025-07-07T05:05:11.696720Z","shell.execute_reply.started":"2025-07-07T05:05:11.691508Z","shell.execute_reply":"2025-07-07T05:05:11.695896Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(f\"Evaluating Model on training data\")\ny_train_pred = model.predict(X_train_trf)\n\ny_train_pred = np.reshape(y_train_pred,y_train.shape)\nevaluate_model(y_train,y_train_pred)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:08:58.710430Z","iopub.execute_input":"2025-07-07T05:08:58.710883Z","iopub.status.idle":"2025-07-07T05:09:16.045424Z","shell.execute_reply.started":"2025-07-07T05:08:58.710855Z","shell.execute_reply":"2025-07-07T05:09:16.044620Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(f\"Evaluating Model on test(validation) data\")\ny_test_pred = model.predict(X_test_trf)\ny_test_pred = np.reshape(y_test_pred,y_test.shape)\nevaluate_model(y_test,y_test_pred)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:10:30.744367Z","iopub.execute_input":"2025-07-07T05:10:30.744724Z","iopub.status.idle":"2025-07-07T05:10:35.442464Z","shell.execute_reply.started":"2025-07-07T05:10:30.744684Z","shell.execute_reply":"2025-07-07T05:10:35.441517Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:10:44.587900Z","iopub.execute_input":"2025-07-07T05:10:44.588255Z","iopub.status.idle":"2025-07-07T05:10:44.592741Z","shell.execute_reply.started":"2025-07-07T05:10:44.588228Z","shell.execute_reply":"2025-07-07T05:10:44.591736Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(history.history['loss'],color='green',label='train')\nplt.plot(history.history['val_loss'],color='black',label='validation')\nplt.title(\"Loss vs Validation Loss\")\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:10:44.954506Z","iopub.execute_input":"2025-07-07T05:10:44.954864Z","iopub.status.idle":"2025-07-07T05:10:45.344480Z","shell.execute_reply.started":"2025-07-07T05:10:44.954836Z","shell.execute_reply":"2025-07-07T05:10:45.343606Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(history.history['mse'],color='green',label='train')\nplt.plot(history.history['val_mse'],color='black',label='validation')\nplt.title(\"mse vs val mse\")\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:10:48.383243Z","iopub.execute_input":"2025-07-07T05:10:48.384318Z","iopub.status.idle":"2025-07-07T05:10:48.565396Z","shell.execute_reply.started":"2025-07-07T05:10:48.384285Z","shell.execute_reply":"2025-07-07T05:10:48.564461Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Prediction","metadata":{}},{"cell_type":"code","source":"model.predict(test_trf)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:10:53.307388Z","iopub.execute_input":"2025-07-07T05:10:53.308251Z","iopub.status.idle":"2025-07-07T05:11:17.975834Z","shell.execute_reply.started":"2025-07-07T05:10:53.308221Z","shell.execute_reply":"2025-07-07T05:11:17.974741Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"prediction = model.predict(test_trf)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:11:17.977724Z","iopub.execute_input":"2025-07-07T05:11:17.978386Z","iopub.status.idle":"2025-07-07T05:11:40.061562Z","shell.execute_reply.started":"2025-07-07T05:11:17.978362Z","shell.execute_reply":"2025-07-07T05:11:40.060604Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_submission['prediction'] = prediction\nsample_submission.to_csv('submission.csv',index=False)\ndisplay(sample_submission.head())\nprint(f\"File saved as submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T05:11:40.063216Z","iopub.execute_input":"2025-07-07T05:11:40.063568Z","iopub.status.idle":"2025-07-07T05:11:41.008618Z","shell.execute_reply.started":"2025-07-07T05:11:40.063546Z","shell.execute_reply":"2025-07-07T05:11:41.007628Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}