{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":58266,"databundleVersionId":6641124,"sourceType":"competition"}],"dockerImageVersionId":30616,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nfrom tqdm import tqdm\ntqdm.pandas()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-12-13T21:43:51.671207Z","iopub.execute_input":"2023-12-13T21:43:51.671671Z","iopub.status.idle":"2023-12-13T21:43:52.077183Z","shell.execute_reply.started":"2023-12-13T21:43:51.671633Z","shell.execute_reply":"2023-12-13T21:43:52.075847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Just featurize each config with its 1) config-level features and 2) average all node features and assign to the config\n#Output is simple dataframe with one config per row, its runtime, and features\nclass TileDataExtractor:\n    def __init__(self, directory, split):\n        self.directory = os.path.join(directory, split)\n        self.data = []\n\n    def load_data(self):\n        for filename in tqdm(os.listdir(self.directory)):\n            filepath = os.path.join(self.directory, filename)\n            self.process_file(filepath, filename)\n\n    def process_file(self, filepath, filename):\n        data = np.load(filepath)\n        config_feat = data['config_feat']\n        node_feat = data['node_feat']\n        node_feat_avg = np.mean(node_feat, axis=0)\n        runtime = data['config_runtime']\n        runtime_norm = data['config_runtime_normalizers']\n        \n        for i in range(len(config_feat)):\n            row = {\n                'config_id': f\"{filename}\",\n                'config_feat': config_feat[i],\n                'node_feat_avg': node_feat_avg,\n                'runtime': runtime[i],\n                'runtime_norm': runtime_norm[i]\n            }\n            self.data.append(row)\n\n    def get_dataframe(self):\n        return pd.DataFrame(self.data)","metadata":{"execution":{"iopub.status.busy":"2023-12-13T21:43:52.885476Z","iopub.execute_input":"2023-12-13T21:43:52.886154Z","iopub.status.idle":"2023-12-13T21:43:52.898960Z","shell.execute_reply.started":"2023-12-13T21:43:52.886103Z","shell.execute_reply":"2023-12-13T21:43:52.897454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#extractor = TileDataExtractor('/kaggle/input/predict-ai-model-runtime/npz_all/npz/tile/xla', 'train')\n#extractor.load_data()\n#df_train = extractor.get_dataframe()","metadata":{"execution":{"iopub.status.busy":"2023-12-13T19:49:47.586431Z","iopub.execute_input":"2023-12-13T19:49:47.586731Z","iopub.status.idle":"2023-12-13T19:49:47.591146Z","shell.execute_reply.started":"2023-12-13T19:49:47.586706Z","shell.execute_reply":"2023-12-13T19:49:47.589851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Unpack 'config_feat'\n#config_feat_df = df_train['config_feat'].apply(pd.Series)\n#config_feat_df.columns = [f'config_feat_{i}' for i in range(config_feat_df.shape[1])]\n\n# Unpack 'node_feat_avg'\n#node_feat_avg_df = df_train['node_feat_avg'].apply(pd.Series)\n#node_feat_avg_df.columns = [f'node_feat_avg_{i}' for i in range(node_feat_avg_df.shape[1])]\n\n# Concatenate with the original DataFrame\n#df_train = pd.concat([df_train.drop(['config_feat', 'node_feat_avg'], axis=1), config_feat_df, node_feat_avg_df], axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-12-13T19:49:47.797199Z","iopub.execute_input":"2023-12-13T19:49:47.797718Z","iopub.status.idle":"2023-12-13T19:49:47.800862Z","shell.execute_reply.started":"2023-12-13T19:49:47.797696Z","shell.execute_reply":"2023-12-13T19:49:47.800338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We only use the \"validation\" dataset for this project, due to environment and resource constraints.","metadata":{}},{"cell_type":"code","source":"extractor = TileDataExtractor('/kaggle/input/predict-ai-model-runtime/npz_all/npz/tile/xla', 'valid')\nextractor.load_data()\ndf_valid = extractor.get_dataframe()","metadata":{"execution":{"iopub.status.busy":"2023-12-13T19:49:49.394931Z","iopub.execute_input":"2023-12-13T19:49:49.395195Z","iopub.status.idle":"2023-12-13T19:50:01.158296Z","shell.execute_reply.started":"2023-12-13T19:49:49.395175Z","shell.execute_reply":"2023-12-13T19:50:01.157362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del extractor","metadata":{"execution":{"iopub.status.busy":"2023-12-13T19:50:01.159912Z","iopub.execute_input":"2023-12-13T19:50:01.160255Z","iopub.status.idle":"2023-12-13T19:50:01.231740Z","shell.execute_reply.started":"2023-12-13T19:50:01.160213Z","shell.execute_reply":"2023-12-13T19:50:01.230809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Unpack features into columns of dataframe","metadata":{}},{"cell_type":"code","source":"df_valid.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-13T21:43:44.455422Z","iopub.execute_input":"2023-12-13T21:43:44.455917Z","iopub.status.idle":"2023-12-13T21:43:45.023370Z","shell.execute_reply.started":"2023-12-13T21:43:44.455866Z","shell.execute_reply":"2023-12-13T21:43:45.021736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Unpack 'config_feat'\nconfig_feat_df = df_valid['config_feat'].apply(pd.Series)\nconfig_feat_df.columns = [f'config_feat_{i}' for i in range(config_feat_df.shape[1])]\n\n# Unpack 'node_feat_avg'\nnode_feat_avg_df = df_valid['node_feat_avg'].apply(pd.Series)\nnode_feat_avg_df.columns = [f'node_feat_avg_{i}' for i in range(node_feat_avg_df.shape[1])]\n\n# Concatenate with the original DataFrame\ndf_valid = pd.concat([df_valid.drop(['config_feat', 'node_feat_avg'], axis=1), config_feat_df, node_feat_avg_df], axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-12-13T19:52:22.699341Z","iopub.execute_input":"2023-12-13T19:52:22.699643Z","iopub.status.idle":"2023-12-13T19:55:55.661406Z","shell.execute_reply.started":"2023-12-13T19:52:22.699621Z","shell.execute_reply":"2023-12-13T19:55:55.660711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#extractor = TileDataExtractor('/kaggle/input/predict-ai-model-runtime/npz_all/npz/tile/xla', 'test')\n#extractor.load_data()\n#df_test = extractor.get_dataframe()","metadata":{"execution":{"iopub.status.busy":"2023-12-11T10:33:05.173918Z","iopub.execute_input":"2023-12-11T10:33:05.174231Z","iopub.status.idle":"2023-12-11T10:33:26.368970Z","shell.execute_reply.started":"2023-12-11T10:33:05.174204Z","shell.execute_reply":"2023-12-11T10:33:26.368111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Unpack 'config_feat'\n#config_feat_df = df_test['config_feat'].apply(pd.Series)\n#config_feat_df.columns = [f'config_feat_{i}' for i in range(config_feat_df.shape[1])]\n\n# Unpack 'node_feat_avg'\n#node_feat_avg_df = df_test['node_feat_avg'].apply(pd.Series)\n#node_feat_avg_df.columns = [f'node_feat_avg_{i}' for i in range(node_feat_avg_df.shape[1])]\n\n# Concatenate with the original DataFrame\n#df_test = pd.concat([df_test.drop(['config_feat', 'node_feat_avg'], axis=1), config_feat_df, node_feat_avg_df], axis=1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del config_feat_df\ndel node_feat_avg_df","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:07:15.437352Z","iopub.execute_input":"2023-12-13T20:07:15.437680Z","iopub.status.idle":"2023-12-13T20:07:15.442191Z","shell.execute_reply.started":"2023-12-13T20:07:15.437659Z","shell.execute_reply":"2023-12-13T20:07:15.441251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df_train['target'] = df_train['runtime'] / df_train['runtime_norm']\n#df_train = df_train.drop(columns=['runtime', 'runtime_norm'])","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:07:16.636596Z","iopub.execute_input":"2023-12-13T20:07:16.636878Z","iopub.status.idle":"2023-12-13T20:07:16.640524Z","shell.execute_reply.started":"2023-12-13T20:07:16.636857Z","shell.execute_reply":"2023-12-13T20:07:16.639677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Normalize the runtime/target column","metadata":{}},{"cell_type":"code","source":"df_valid['target'] = df_valid['runtime'] / df_valid['runtime_norm']","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:07:16.960679Z","iopub.execute_input":"2023-12-13T20:07:16.960969Z","iopub.status.idle":"2023-12-13T20:07:16.985375Z","shell.execute_reply.started":"2023-12-13T20:07:16.960948Z","shell.execute_reply":"2023-12-13T20:07:16.984503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df_test['target'] = df_test['runtime'] / df_test['runtime_norm']\n#df_test = df_test.drop(columns=['runtime', 'runtime_norm'])","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Minmax scale the target, grouped by config ID. We only care about the relative ordering.","metadata":{}},{"cell_type":"code","source":"%%capture --no-stderr\n\nfrom sklearn.preprocessing import MinMaxScaler\n\nscaler = MinMaxScaler()\n\n# Iterate over each config_id and scale the target column within each group\nfor config_id in df_valid['config_id'].unique():\n    # Selecting the rows corresponding to the current config_id\n    idx = df_valid['config_id'] == config_id\n    \n    # Scaling the target column for the current group\n    df_valid.loc[idx, 'target'] = scaler.fit_transform(df_valid.loc[idx, ['target']])","metadata":{"scrolled":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-12-13T20:07:37.572390Z","iopub.execute_input":"2023-12-13T20:07:37.573074Z","iopub.status.idle":"2023-12-13T20:08:20.554512Z","shell.execute_reply.started":"2023-12-13T20:07:37.573050Z","shell.execute_reply":"2023-12-13T20:08:20.553536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Save preprocessed data\ndf_valid.to_csv(\"processed_data.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:32:36.904097Z","iopub.execute_input":"2023-12-13T20:32:36.904424Z","iopub.status.idle":"2023-12-13T20:33:52.927344Z","shell.execute_reply.started":"2023-12-13T20:32:36.904401Z","shell.execute_reply":"2023-12-13T20:33:52.926624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Start from here with preprocessed data loaded.","metadata":{}},{"cell_type":"code","source":"df_valid = pd.read_csv(\"processed_data.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:13:47.393924Z","iopub.execute_input":"2023-12-13T20:13:47.394240Z","iopub.status.idle":"2023-12-13T20:13:57.996907Z","shell.execute_reply.started":"2023-12-13T20:13:47.394203Z","shell.execute_reply":"2023-12-13T20:13:57.996024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression, Lasso, Ridge\nfrom sklearn.metrics import r2_score\nfrom sklearn.model_selection import GridSearchCV","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:14:01.276416Z","iopub.execute_input":"2023-12-13T20:14:01.276730Z","iopub.status.idle":"2023-12-13T20:14:01.418132Z","shell.execute_reply.started":"2023-12-13T20:14:01.276707Z","shell.execute_reply":"2023-12-13T20:14:01.417514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Train test split, ensuring that configurations of the same model are not in different splits","metadata":{}},{"cell_type":"code","source":"unique_config_ids = df_valid['config_id'].unique()\ntrain_config_ids, test_config_ids = train_test_split(unique_config_ids, test_size=0.2, random_state=42)\n\n# Creating train and test dataframes based on config_id\ntrain_df = df_valid[df_valid['config_id'].isin(train_config_ids)]\ntest_df = df_valid[df_valid['config_id'].isin(test_config_ids)]\n\n# Separating features and target variable\nX_train = train_df.drop(['target', 'config_id', 'runtime', 'runtime_norm'], axis=1)\ny_train = train_df['target']\nX_test = test_df.drop(['target', 'config_id', 'runtime', 'runtime_norm'], axis=1)\ny_test = test_df['target']","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:18:22.214091Z","iopub.execute_input":"2023-12-13T20:18:22.214452Z","iopub.status.idle":"2023-12-13T20:18:22.785631Z","shell.execute_reply.started":"2023-12-13T20:18:22.214427Z","shell.execute_reply":"2023-12-13T20:18:22.784742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install LightGBM\nfrom lightgbm import LGBMRegressor","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:14:04.408503Z","iopub.execute_input":"2023-12-13T20:14:04.409040Z","iopub.status.idle":"2023-12-13T20:14:14.997999Z","shell.execute_reply.started":"2023-12-13T20:14:04.409006Z","shell.execute_reply":"2023-12-13T20:14:14.997100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#obtained from gridsearchcv\nlasso_alpha = 0.01\nridge_alpha = 0.001\n\nlr = LinearRegression()\nlasso = Lasso(alpha = lasso_alpha)\nridge = Ridge(alpha = ridge_alpha)\nlgbm = LGBMRegressor(colsample_bytree= 0.9029527732718773,\n learning_rate= 0.05,\n min_child_samples= 465,\n min_child_weight= 0.02476027076966974,\n n_estimators= 1500,\n num_leaves= 26,\n reg_alpha= 10,\n reg_lambda= 0.1,\n subsample= 0.9672960197116944)\n\nmodels = [lr, lasso, ridge, lgbm]\nfor model in tqdm(models):\n    model.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:18:25.607754Z","iopub.execute_input":"2023-12-13T20:18:25.608031Z","iopub.status.idle":"2023-12-13T20:22:04.023042Z","shell.execute_reply.started":"2023-12-13T20:18:25.608010Z","shell.execute_reply":"2023-12-13T20:22:04.022210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Making predictions\ntrain_preds_lr = lr.predict(X_train)\ntrain_preds_lasso = lasso.predict(X_train)\ntrain_preds_ridge = ridge.predict(X_train)\ntrain_preds_lgbm = lgbm.predict(X_train)\n\ntest_preds_lr = lr.predict(X_test)\ntest_preds_lasso = lasso.predict(X_test)\ntest_preds_ridge = ridge.predict(X_test)\ntest_preds_lgbm = lgbm.predict(X_test)\n\n# Calculating R² scores\ntest_r2_lr = r2_score(y_test, test_preds_lr)\ntest_r2_lasso = r2_score(y_test, test_preds_lasso)\ntest_r2_ridge = r2_score(y_test, test_preds_ridge)\ntest_r2_lgbm = r2_score(y_test, test_preds_lgbm)\n\ntrain_r2_lr= r2_score(y_train, train_preds_lr)\ntrain_r2_lasso = r2_score(y_train, train_preds_lasso)\ntrain_r2_ridge = r2_score(y_train, train_preds_ridge)\ntrain_r2_lgbm = r2_score(y_train, train_preds_lgbm)\n\nprint(\"R² Scores Train:\")\nprint(f\"Linear Regression: {train_r2_lr}\")\nprint(f\"Lasso Regression: {train_r2_lasso}\")\nprint(f\"Ridge Regression: {train_r2_ridge}\")\nprint(f\"LGBM Regression: {train_r2_lgbm}\")\n\nprint(\"R² Scores Test:\")\nprint(f\"Linear Regression: {test_r2_lr}\")\nprint(f\"Lasso Regression: {test_r2_lasso}\")\nprint(f\"Ridge Regression: {test_r2_ridge}\")\nprint(f\"LGBM Regression: {test_r2_lgbm}\")","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:22:18.309344Z","iopub.execute_input":"2023-12-13T20:22:18.309796Z","iopub.status.idle":"2023-12-13T20:22:45.794884Z","shell.execute_reply.started":"2023-12-13T20:22:18.309766Z","shell.execute_reply":"2023-12-13T20:22:45.794020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The following code calculates the top K=5 slowdown for predictions.","metadata":{}},{"cell_type":"code","source":"def rank_configurations(predictions, full_df):\n    ranked_configurations = []\n\n    # Create a mapping of DataFrame indices to the range of indices in predictions\n    index_mapping = {idx: i for i, idx in enumerate(full_df.index)}\n\n    # Group data by 'config_id' and process each group\n    for config_id, group in full_df.groupby('config_id'):\n        # Get the corresponding prediction indices for the current group\n        prediction_indices = [index_mapping[idx] for idx in group.index]\n\n        # Rank configurations by predicted runtime\n        ranked_indices = group.index[np.argsort(predictions[prediction_indices])]\n\n        # Store the original indices of the ranked configurations\n        ranked_configurations.append(list(ranked_indices))\n\n    return ranked_configurations\n","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:24:03.995982Z","iopub.execute_input":"2023-12-13T20:24:03.996295Z","iopub.status.idle":"2023-12-13T20:24:04.001947Z","shell.execute_reply.started":"2023-12-13T20:24:03.996272Z","shell.execute_reply":"2023-12-13T20:24:04.001015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ranked_train_lr = rank_configurations(train_preds_lr, train_df)\nranked_test_lr = rank_configurations(test_preds_lr, test_df)\n\nranked_train_lasso = rank_configurations(train_preds_lasso, train_df)\nranked_test_lasso = rank_configurations(test_preds_lasso, test_df)\n\nranked_train_ridge = rank_configurations(train_preds_ridge, train_df)\nranked_test_ridge = rank_configurations(test_preds_ridge, test_df)\n\nranked_train_lgbm = rank_configurations(train_preds_lgbm, train_df)\nranked_test_lgbm = rank_configurations(test_preds_lgbm, test_df)\n\ntrue_ranked_train = rank_configurations(y_train.to_numpy(), train_df)\ntrue_ranked_test = rank_configurations(y_test.to_numpy(), test_df)","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:24:06.372209Z","iopub.execute_input":"2023-12-13T20:24:06.372540Z","iopub.status.idle":"2023-12-13T20:24:11.446246Z","shell.execute_reply.started":"2023-12-13T20:24:06.372518Z","shell.execute_reply":"2023-12-13T20:24:11.445466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def calculate_top_k_slowdown(predicted_rankings, full_df, runtime_column='runtime', k=5):\n    total_slowdown = 0\n    num_models = len(predicted_rankings)\n\n    for predicted in tqdm(predicted_rankings):\n        # Extract the top-k predicted configurations\n        top_k_predicted = predicted[:k]\n\n        # Best runtime among top-k predicted configurations\n        best_runtime_top_k = full_df.loc[top_k_predicted, runtime_column].min()\n\n        # Best runtime among all configurations in the model group\n        config_id = full_df.loc[top_k_predicted[0], 'config_id']\n        best_runtime_all = full_df[full_df['config_id'] == config_id][runtime_column].min()\n\n        # Calculate slowdown for this model\n        slowdown = 1 - ((best_runtime_top_k / best_runtime_all) - 1)\n        total_slowdown += slowdown\n\n    # Average slowdown across all models\n    average_slowdown = total_slowdown / num_models\n    return average_slowdown\n\n# Example usage\naverage_slowdown_lr = calculate_top_k_slowdown(ranked_train_lr, train_df)\naverage_slowdown_lasso = calculate_top_k_slowdown(ranked_train_lasso, train_df)\naverage_slowdown_ridge = calculate_top_k_slowdown(ranked_train_ridge, train_df)\naverage_slowdown_lgbm = calculate_top_k_slowdown(ranked_train_lgbm, train_df)\n\n# Print average slowdowns\nprint(\"Average Top-k Slowdown (LR, Train):\", average_slowdown_lr)\nprint(\"Average Top-k Slowdown (Lasso, Train):\", average_slowdown_lasso)\nprint(\"Average Top-k Slowdown (Ridge, Train):\", average_slowdown_ridge)\nprint(\"Average Top-k Slowdown (LGBM, Train):\", average_slowdown_lgbm)\n","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:24:16.890051Z","iopub.execute_input":"2023-12-13T20:24:16.890363Z","iopub.status.idle":"2023-12-13T20:25:57.003215Z","shell.execute_reply.started":"2023-12-13T20:24:16.890340Z","shell.execute_reply":"2023-12-13T20:25:57.002400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Calculate average top-k slowdown for the test predictions\naverage_slowdown_lr_test = calculate_top_k_slowdown(ranked_test_lr, test_df)\naverage_slowdown_lasso_test = calculate_top_k_slowdown(ranked_test_lasso, test_df)\naverage_slowdown_ridge_test = calculate_top_k_slowdown(ranked_test_ridge, test_df)\naverage_slowdown_lgbm_test = calculate_top_k_slowdown(ranked_test_lgbm, test_df)\n\n# Print average slowdowns for test predictions\nprint(\"Average Top-k Slowdown (LR, Test):\", average_slowdown_lr_test)\nprint(\"Average Top-k Slowdown (Lasso, Test):\", average_slowdown_lasso_test)\nprint(\"Average Top-k Slowdown (Ridge, Test):\", average_slowdown_ridge_test)\nprint(\"Average Top-k Slowdown (LGBM, Test):\", average_slowdown_lgbm_test)","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:26:40.049732Z","iopub.execute_input":"2023-12-13T20:26:40.050056Z","iopub.status.idle":"2023-12-13T20:26:46.233400Z","shell.execute_reply.started":"2023-12-13T20:26:40.050033Z","shell.execute_reply":"2023-12-13T20:26:46.232368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"config_feature_names = [\n            \"kernel_bounds_0\", \"kernel_bounds_1\", \"kernel_bounds_2\", \"kernel_bounds_3\", \n            \"kernel_bounds_4\", \"kernel_bounds_5\", \"kernel_bounds_sum\", \"kernel_bounds_product\",\n            \"output_bounds_0\", \"output_bounds_1\", \"output_bounds_2\", \"output_bounds_3\", \n            \"output_bounds_4\", \"output_bounds_5\", \"output_bounds_sum\", \"output_bounds_product\",\n            \"input_bounds_0\", \"input_bounds_1\", \"input_bounds_2\", \"input_bounds_3\", \n            \"input_bounds_4\", \"input_bounds_5\", \"input_bounds_sum\", \"input_bounds_product\"\n]\n\nnode_feature_names = [\n            \"is_root\", \"element_size_in_bits\", \"shape_element_type_is_invalid_type\", \n            \"shape_element_type_is_pred\", \"shape_element_type_is_s8\", \"shape_element_type_is_s16\", \n            \"shape_element_type_is_s32\", \"shape_element_type_is_s64\", \"shape_element_type_is_u8\", \n            \"shape_element_type_is_u16\", \"shape_element_type_is_u32\", \"shape_element_type_is_u64\", \n            \"shape_element_type_is_f16\", \"shape_element_type_is_f32\", \"shape_element_type_is_f64\", \n            \"shape_element_type_is_bf16\", \"shape_element_type_is_c64\", \"shape_element_type_is_c128\", \n            \"shape_element_type_is_tuple\", \"shape_element_type_is_opaque_type\", \"shape_element_type_is_token\", \n            \"shape_dimensions_0\", \"shape_dimensions_1\", \"shape_dimensions_2\", \"shape_dimensions_3\", \n            \"shape_dimensions_4\", \"shape_dimensions_5\", \"shape_dimensions_sum\", \"shape_dimensions_product\",\n            \"shape_tuple_shapes_size\", \"parameter_number\", \"dimensions_0\", \"dimensions_1\", \n            \"dimensions_2\", \"dimensions_3\", \"dimensions_4\", \"dimensions_5\", \"window_size_0\", \n            \"window_size_1\", \"window_size_2\", \"window_size_3\", \"window_size_4\", \"window_size_5\", \n            \"window_size_sum\", \"window_size_product\", \"window_stride_0\", \"window_stride_1\", \n            \"window_stride_2\", \"window_stride_3\", \"window_stride_4\", \"window_stride_5\", \n            \"window_stride_sum\", \"window_stride_product\", \"window_padding_low_0\", \"window_padding_low_1\", \n            \"window_padding_low_2\", \"window_padding_low_3\", \"window_padding_low_4\", \"window_padding_low_5\", \n            \"window_padding_low_sum\", \"window_padding_low_product\", \"window_padding_high_0\", \n            \"window_padding_high_1\", \"window_padding_high_2\", \"window_padding_high_3\", \n            \"window_padding_high_4\", \"window_padding_high_5\", \"window_padding_high_sum\", \n            \"window_padding_high_product\", \"window_window_dilation_0\", \"window_window_dilation_1\", \n            \"window_window_dilation_2\", \"window_window_dilation_3\", \"window_window_dilation_4\", \n            \"window_window_dilation_5\", \"window_window_dilation_sum\", \"window_window_dilation_product\", \n            \"window_base_dilation_0\", \"window_base_dilation_1\", \"window_base_dilation_2\", \n            \"window_base_dilation_3\", \"window_base_dilation_4\", \"window_base_dilation_5\", \n            \"window_base_dilation_sum\", \"window_base_dilation_product\", \"window_window_reversal_0\", \n            \"window_window_reversal_1\", \"window_window_reversal_2\", \"window_window_reversal_3\", \n            \"window_window_reversal_4\", \"window_window_reversal_5\", \"window_window_reversal_true_count\", \n            \"window_window_reversal_false_count\", \"convolution_dim_numbers_input_batch_dim\", \n            \"convolution_dim_numbers_input_feature_dim\", \"convolution_dim_numbers_input_spatial_dims_0\", \n            \"convolution_dim_numbers_input_spatial_dims_1\", \"convolution_dim_numbers_input_spatial_dims_2\", \n            \"convolution_dim_numbers_input_spatial_dims_3\", \"convolution_dim_numbers_kernel_input_feature_dim\", \n            \"convolution_dim_numbers_kernel_output_feature_dim\", \"convolution_dim_numbers_kernel_spatial_dims_0\", \n            \"convolution_dim_numbers_kernel_spatial_dims_1\", \"convolution_dim_numbers_kernel_spatial_dims_2\", \n            \"convolution_dim_numbers_kernel_spatial_dims_3\", \"convolution_dim_numbers_output_batch_dim\", \n            \"convolution_dim_numbers_output_feature_dim\", \"feature_group_count\", \"batch_group_count\", \n            \"slice_dims_start_0\", \"slice_dims_start_1\", \"slice_dims_start_sum\", \"slice_dims_start_product\", \n            \"slice_dims_stride_0\", \"slice_dims_stride_1\", \"slice_dims_stride_sum\", \"slice_dims_stride_product\", \n            \"slice_dims_limit_0\", \"slice_dims_limit_1\", \"slice_dims_limit_sum\", \"slice_dims_limit_product\", \n            \"dynamic_slice_sizes_0\", \"dynamic_slice_sizes_1\", \"dynamic_slice_sizes_sum\", \n            \"dynamic_slice_sizes_product\", \"padding_config_edge_padding_low_0\", \n            \"padding_config_edge_padding_low_1\", \"padding_config_edge_padding_low_sum\", \n            \"padding_config_edge_padding_low_product\", \"padding_config_edge_padding_high_0\", \n            \"padding_config_edge_padding_high_1\", \"padding_config_edge_padding_high_sum\", \n            \"padding_config_edge_padding_high_product\", \"is_stable\", \"layout_minor_to_major_0\", \n            \"layout_minor_to_major_1\", \"layout_minor_to_major_2\", \"layout_minor_to_major_3\", \n            \"layout_minor_to_major_4\", \"layout_minor_to_major_5\"\n]","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:27:07.537581Z","iopub.execute_input":"2023-12-13T20:27:07.537892Z","iopub.status.idle":"2023-12-13T20:27:07.546815Z","shell.execute_reply.started":"2023-12-13T20:27:07.537868Z","shell.execute_reply":"2023-12-13T20:27:07.546267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfeature_importances = (lgbm.feature_importances_ / sum(model.feature_importances_)) * 100\nfeature_names = X_train.columns\n\ndef map_feature_names(feature_names, config_feature_names, node_feature_names):\n    mapped_names = []\n\n    for name in feature_names:\n        if name.startswith('config'):\n            # Extract the index from the name (assuming the format 'config_feat_X')\n            index = int(name.split('_')[-1])\n            mapped_names.append(config_feature_names[index])\n        elif name.startswith('node'):\n            # Extract the index from the name (assuming the format 'node_feat_avg_X')\n            index = int(name.split('_')[-1])\n            mapped_names.append(node_feature_names[index])\n        else:\n            # If the feature name doesn't match the expected pattern, keep it as is\n            mapped_names.append(name)\n\n    return mapped_names\n\n# Assuming 'feature_names' contains the names of features from your model\nfeature_names = map_feature_names(feature_names, config_feature_names, node_feature_names)\n\nresults = pd.DataFrame({'Features': feature_names,\n                        'Importances': feature_importances})\nresults.sort_values(by='Importances', inplace=True)\n\nax = plt.barh(results['Features'][-25:], results['Importances'][-25:])\nplt.xlabel('Importance Percentage')\nplt.ylabel('Feature')\nplt.title('LightGBM Tile Gain Feature Importances (Top 25)')\nplt.gca().xaxis.set_major_formatter(plt.FuncFormatter(lambda x, _: f'{x:.0f}%'))  # Format x-axis as percentage\nplt.savefig('lgbfeat')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:27:23.451775Z","iopub.execute_input":"2023-12-13T20:27:23.452093Z","iopub.status.idle":"2023-12-13T20:27:23.954361Z","shell.execute_reply.started":"2023-12-13T20:27:23.452068Z","shell.execute_reply":"2023-12-13T20:27:23.953530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nimport matplotlib.colors as mcolors\nimport random","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:27:27.585671Z","iopub.execute_input":"2023-12-13T20:27:27.586119Z","iopub.status.idle":"2023-12-13T20:27:27.609306Z","shell.execute_reply.started":"2023-12-13T20:27:27.586096Z","shell.execute_reply":"2023-12-13T20:27:27.608729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=3)\nprincipalComponents = pca.fit_transform(df_valid.drop(columns=['target', 'config_id', 'runtime', 'runtime_norm']))\npca_df = pd.DataFrame(data = principalComponents, columns = ['PC1', 'PC2', 'PC3'])\npca_df['config_id'] = df_valid['config_id']  # Add the config_id back for coloring\n\n# Plotting the 3D PCA plot with a sample\nfig = plt.figure(figsize=(10, 8))\nax = fig.add_subplot(111, projection='3d')\n\nscatter = ax.scatter(pca_df['PC1'],\n                     pca_df['PC2'],\n                     pca_df['PC3'],\n                     c=pd.factorize(pca_df['config_id'])[0],  # color by config_id\n                     cmap='hsv',\n                     s = 50)\n\nax.set_xlabel('Principal Component 1')\nax.set_ylabel('Principal Component 2')\nax.set_zlabel('Principal Component 3')\nax.set_title('3D PCA Plot - Tile')\n\n# Creating a colorbar with config_id labels\ncbar = plt.colorbar(scatter, ax=ax)\ncbar.set_label('Config ID')\nplt.savefig('allpca')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:27:27.755499Z","iopub.execute_input":"2023-12-13T20:27:27.755993Z","iopub.status.idle":"2023-12-13T20:28:23.341294Z","shell.execute_reply.started":"2023-12-13T20:27:27.755964Z","shell.execute_reply":"2023-12-13T20:28:23.340527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Assuming df_valid and pca_df are already defined and contain the necessary data\nselected_config_ids = [\n    'bert_pretraining.4x4.fp16_-18321ad156c55c0b.npz',\n    'inception_v3_batch_128_train_-1098e0f697435732.npz',\n    'mlperf_bert_batch_24_2x2_-132dd84b121a1252.npz',\n    'resnet50.4x4.fp16_-1481da01546b909a.npz',\n    'resnet_v1_50_official_batch_128_bf16_-11eca1b246accbac.npz',\n    'tf2_bert_pretrain_dynamic_batch_size_-1972c148bcabec74.npz',\n    'unet_3d.4x4.bf16_-18d13e5b20bf0cba.npz',\n    'unet_3d.4x4.bf16_2c26a09dea860431.npz'\n]\n\ndf_valid['PC1'], df_valid['PC2'], df_valid['PC3'] = pca_df['PC1'], pca_df['PC2'], pca_df['PC3']","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:32:23.666162Z","iopub.execute_input":"2023-12-13T20:32:23.666522Z","iopub.status.idle":"2023-12-13T20:32:23.687151Z","shell.execute_reply.started":"2023-12-13T20:32:23.666498Z","shell.execute_reply":"2023-12-13T20:32:23.686278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(25, 15))  # Adjusted figure size for better display\n\nfor i, config_id in enumerate(selected_config_ids, 1):\n    ax = fig.add_subplot(2, 4, i, projection='3d')  # Adjust for 2x4 layout\n    subset = df_valid[df_valid['config_id'] == config_id]\n\n    ax.scatter(subset['PC1'], subset['PC2'], subset['PC3'], s=50)\n    title = f'3D Tiling PCA Plot for {config_id.split(\".npz\")[0]}'\n    ax.set_title(title, fontsize=15, rotation=3)  # Rotate title and adjust font size\n    ax.set_xlabel('Principal Component 1')\n    ax.set_ylabel('Principal Component 2')\n    ax.set_zlabel('Principal Component 3')\n\nplt.tight_layout()\nplt.savefig('configpca')\nplt.title(\"3D Tiling PCA Plots for Selected Model Configurations\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-13T20:32:23.822698Z","iopub.execute_input":"2023-12-13T20:32:23.823020Z","iopub.status.idle":"2023-12-13T20:32:27.935924Z","shell.execute_reply.started":"2023-12-13T20:32:23.822997Z","shell.execute_reply":"2023-12-13T20:32:27.935241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Code below is old, used for hyperparameter search + LGBM GPU acceleration.","metadata":{}},{"cell_type":"code","source":"unique_config_ids = df_valid['config_id'].unique()\ntrain_config_ids, test_config_ids = train_test_split(unique_config_ids, test_size=0.2, random_state=42)\n\n# Creating train and test dataframes based on config_id\ntrain_df = df_valid[df_valid['config_id'].isin(train_config_ids)]\ntest_df = df_valid[df_valid['config_id'].isin(test_config_ids)]\n\n# Separating features and target variable\nX_train = train_df.drop(['target', 'config_id'], axis=1)\ny_train = train_df['target']\nX_test = test_df.drop(['target', 'config_id'], axis=1)\ny_test = test_df['target']\n\ndel train_df\ndel test_df\ndel train_config_ids\ndel test_config_ids\ndel unique_config_ids\n\n# Training models\nlin_reg = LinearRegression().fit(X_train, y_train)\n\nalpha_grid = {'alpha': [0.001, 0.01, 0.1, 1, 10, 100]}\n\n# Setting up GridSearchCV for Lasso Regression\nlasso = Lasso()\ngrid_search_lasso = GridSearchCV(estimator=lasso, param_grid=alpha_grid, cv=3, scoring='neg_mean_squared_error',verbose=4)\ngrid_search_lasso.fit(X_train, y_train)\nlasso_reg = grid_search_lasso.best_estimator_\nprint(\"Lasso Alpha\")\nprint(grid_search_lasso.best_params_['alpha'])\n\nridge = Ridge()\ngrid_search_ridge = GridSearchCV(estimator=ridge, param_grid=alpha_grid, cv=3, scoring='neg_mean_squared_error',verbose=4)\ngrid_search_ridge.fit(X_train, y_train)\nridge_reg = grid_search_ridge.best_estimator_\nprint(\"Ridge Alpha\")\nprint(grid_search_ridge.best_params_['alpha'])\n\n# Making predictions\ntrain_predictions_lin = lin_reg.predict(X_train)\ntrain_predictions_lasso = lasso_reg.predict(X_train)\ntrain_predictions_ridge = ridge_reg.predict(X_train)\n\npredictions_lin = lin_reg.predict(X_test)\npredictions_lasso = lasso_reg.predict(X_test)\npredictions_ridge = ridge_reg.predict(X_test)\n\n# Calculating R² scores\nr2_lin = r2_score(y_test, predictions_lin)\nr2_lasso = r2_score(y_test, predictions_lasso)\nr2_ridge = r2_score(y_test, predictions_ridge)\n\nr2_train_lin = r2_score(y_train, train_predictions_lin)\nr2_train_lasso = r2_score(y_train, train_predictions_lasso)\nr2_train_ridge = r2_score(y_train, train_predictions_ridge)\n\nprint(\"R² Scores Train:\")\nprint(f\"Linear Regression: {r2_train_lin}\")\nprint(f\"Lasso Regression: {r2_train_lasso}\")\nprint(f\"Ridge Regression: {r2_train_ridge}\")\n\nprint(\"R² Scores Test:\")\nprint(f\"Linear Regression: {r2_lin}\")\nprint(f\"Lasso Regression: {r2_lasso}\")\nprint(f\"Ridge Regression: {r2_ridge}\")","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-11T11:38:24.156332Z","iopub.execute_input":"2023-12-11T11:38:24.157100Z","iopub.status.idle":"2023-12-11T11:50:08.991187Z","shell.execute_reply.started":"2023-12-11T11:38:24.157066Z","shell.execute_reply":"2023-12-11T11:50:08.990176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -r /opt/conda/lib/python3.6/site-packages/lightgbm\n!git clone --recursive https://github.com/Microsoft/LightGBM\n!apt-get install -y -qq libboost-all-dev","metadata":{"execution":{"iopub.status.busy":"2023-12-11T11:50:58.040921Z","iopub.execute_input":"2023-12-11T11:50:58.041614Z","iopub.status.idle":"2023-12-11T11:52:01.796750Z","shell.execute_reply.started":"2023-12-11T11:50:58.041584Z","shell.execute_reply":"2023-12-11T11:52:01.795582Z"},"scrolled":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%bash\ncd LightGBM\nrm -r build\nmkdir build\ncd build\ncmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..\nmake -j$(nproc)","metadata":{"execution":{"iopub.status.busy":"2023-12-11T11:52:07.620403Z","iopub.execute_input":"2023-12-11T11:52:07.620810Z","iopub.status.idle":"2023-12-11T11:54:35.705391Z","shell.execute_reply.started":"2023-12-11T11:52:07.620771Z","shell.execute_reply":"2023-12-11T11:54:35.704423Z"},"scrolled":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#!cd LightGBM/python-package/;python3 setup.py install --precompile","metadata":{"execution":{"iopub.status.busy":"2023-12-11T11:54:41.360369Z","iopub.execute_input":"2023-12-11T11:54:41.361112Z","iopub.status.idle":"2023-12-11T11:54:42.422280Z","shell.execute_reply.started":"2023-12-11T11:54:41.361076Z","shell.execute_reply":"2023-12-11T11:54:42.421036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p /etc/OpenCL/vendors && echo \"libnvidia-opencl.so.1\" > /etc/OpenCL/vendors/nvidia.icd\n!rm -r LightGBM","metadata":{"execution":{"iopub.status.busy":"2023-12-11T11:54:51.502524Z","iopub.execute_input":"2023-12-11T11:54:51.502953Z","iopub.status.idle":"2023-12-11T11:54:53.591018Z","shell.execute_reply.started":"2023-12-11T11:54:51.502916Z","shell.execute_reply":"2023-12-11T11:54:53.589717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!nvidia-smi","metadata":{"execution":{"iopub.status.busy":"2023-12-11T11:54:56.762406Z","iopub.execute_input":"2023-12-11T11:54:56.763274Z","iopub.status.idle":"2023-12-11T11:54:57.747341Z","shell.execute_reply.started":"2023-12-11T11:54:56.763236Z","shell.execute_reply":"2023-12-11T11:54:57.746179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from lightgbm import LGBMRegressor","metadata":{"execution":{"iopub.status.busy":"2023-12-11T16:03:21.537337Z","iopub.execute_input":"2023-12-11T16:03:21.537669Z","iopub.status.idle":"2023-12-11T16:03:22.620953Z","shell.execute_reply.started":"2023-12-11T16:03:21.537640Z","shell.execute_reply":"2023-12-11T16:03:22.619890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import RandomizedSearchCV\nfrom scipy.stats import randint as sp_randint\nfrom scipy.stats import uniform as sp_uniform","metadata":{"execution":{"iopub.status.busy":"2023-12-11T16:03:22.629002Z","iopub.execute_input":"2023-12-11T16:03:22.629465Z","iopub.status.idle":"2023-12-11T16:03:22.638349Z","shell.execute_reply.started":"2023-12-11T16:03:22.629426Z","shell.execute_reply":"2023-12-11T16:03:22.637389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"param_dist = {\n    'num_leaves': sp_randint(3, 50), \n    'min_child_samples': sp_randint(5, 500), \n    'min_child_weight': sp_uniform(0.01, 0.1),\n    'subsample': sp_uniform(0.8, 0.2),\n    'colsample_bytree': sp_uniform(0.8, 0.2),\n    'reg_alpha': [0, 1e-1, 1, 2, 5, 7, 10],\n    'reg_lambda': [0, 1e-1, 1, 5, 10, 20, 50],\n    'learning_rate': [0.001, 0.005, 0.01, 0.05, 0.1, 0.2],\n    'n_estimators': [100, 250, 500, 1000, 1500]\n}","metadata":{"execution":{"iopub.status.busy":"2023-12-11T11:55:57.117413Z","iopub.execute_input":"2023-12-11T11:55:57.118157Z","iopub.status.idle":"2023-12-11T11:55:57.129067Z","shell.execute_reply.started":"2023-12-11T11:55:57.118119Z","shell.execute_reply":"2023-12-11T11:55:57.128073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random_search = RandomizedSearchCV(lgbm, param_distributions=param_dist, n_iter=25, cv=4, scoring='neg_mean_squared_error', verbose=4)\nrandom_search.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-12-11T11:56:18.401823Z","iopub.execute_input":"2023-12-11T11:56:18.402218Z","iopub.status.idle":"2023-12-11T12:39:55.738724Z","shell.execute_reply.started":"2023-12-11T11:56:18.402186Z","shell.execute_reply":"2023-12-11T12:39:55.737796Z"},"scrolled":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_lgbm = random_search.best_estimator_","metadata":{"execution":{"iopub.status.busy":"2023-12-11T12:44:28.988748Z","iopub.execute_input":"2023-12-11T12:44:28.989975Z","iopub.status.idle":"2023-12-11T12:44:28.994995Z","shell.execute_reply.started":"2023-12-11T12:44:28.989927Z","shell.execute_reply":"2023-12-11T12:44:28.993901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random_search.best_params_","metadata":{"execution":{"iopub.status.busy":"2023-12-11T12:44:43.877714Z","iopub.execute_input":"2023-12-11T12:44:43.878128Z","iopub.status.idle":"2023-12-11T12:44:43.884891Z","shell.execute_reply.started":"2023-12-11T12:44:43.878091Z","shell.execute_reply":"2023-12-11T12:44:43.883709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_preds_lgb = best_lgbm.predict(X_train)\n\npreds_lgb = best_lgbm.predict(X_test)\n\n# Calculating R² scores\nr2_lgb = r2_score(y_test, preds_lgb)\n\nr2_train_lgb=r2_score(y_train, train_preds_lgb)\n\nprint(\"R² Scores Train:\")\nprint(f\"LGBM: {r2_train_lgb}\")\n\nprint(\"R² Scores Test:\")\nprint(f\"LGBM: {r2_lgb}\")","metadata":{"execution":{"iopub.status.busy":"2023-12-11T12:47:39.863673Z","iopub.execute_input":"2023-12-11T12:47:39.864093Z","iopub.status.idle":"2023-12-11T12:48:36.514181Z","shell.execute_reply.started":"2023-12-11T12:47:39.864058Z","shell.execute_reply":"2023-12-11T12:48:36.512531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extractor = TileDataExtractor('/kaggle/input/predict-ai-model-runtime/npz_all/npz/tile/xla', 'test')\nextractor.load_data()\ndf_test = extractor.get_dataframe()","metadata":{"execution":{"iopub.status.busy":"2023-12-11T13:20:00.329009Z","iopub.execute_input":"2023-12-11T13:20:00.329746Z","iopub.status.idle":"2023-12-11T13:20:27.213499Z","shell.execute_reply.started":"2023-12-11T13:20:00.329711Z","shell.execute_reply":"2023-12-11T13:20:27.212653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Unpack 'config_feat'\nconfig_feat_df = df_test['config_feat'].apply(pd.Series)\nconfig_feat_df.columns = [f'config_feat_{i}' for i in range(config_feat_df.shape[1])]\n\n# Unpack 'node_feat_avg'\nnode_feat_avg_df = df_test['node_feat_avg'].apply(pd.Series)\nnode_feat_avg_df.columns = [f'node_feat_avg_{i}' for i in range(node_feat_avg_df.shape[1])]\n\n# Concatenate with the original DataFrame\ndf_test = pd.concat([df_test.drop(['config_feat', 'node_feat_avg'], axis=1), config_feat_df, node_feat_avg_df], axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-12-11T13:20:36.057294Z","iopub.execute_input":"2023-12-11T13:20:36.058126Z","iopub.status.idle":"2023-12-11T13:25:24.000956Z","shell.execute_reply.started":"2023-12-11T13:20:36.058087Z","shell.execute_reply":"2023-12-11T13:25:23.999735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = df_test.drop","metadata":{"execution":{"iopub.status.busy":"2023-12-11T13:26:31.781501Z","iopub.execute_input":"2023-12-11T13:26:31.782030Z","iopub.status.idle":"2023-12-11T13:26:31.981349Z","shell.execute_reply.started":"2023-12-11T13:26:31.781993Z","shell.execute_reply":"2023-12-11T13:26:31.980131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgbm_tile_preds = best_lgbm.predict()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}