{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":59093,"databundleVersionId":7469972,"sourceType":"competition"}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"In this notebook, we will leverage H2O's AutoML functionality to tackle the classification task of identifying seizures and other patterns of harmful brain activity in critically ill patients. The objective of this competition is crucial for the timely diagnosis and treatment of patients in intensive care units.\n\nSeizures and harmful brain activity can have severe consequences for critically ill patients, necessitating prompt detection and intervention. Traditional methods of identifying these patterns often rely on manual interpretation of EEG and spectrogram data, which can be time-consuming and prone to errors. Machine learning techniques offer a promising solution by automating the classification process.","metadata":{"_uuid":"bb218f7d-e809-4fe5-ace0-593666cc6d1f","_cell_guid":"72612832-3a23-46d8-bddb-8f880d863663","trusted":true}},{"cell_type":"code","source":"# Import libraries\nimport pandas as pd \nimport numpy as np \nimport h2o\nfrom h2o.automl import H2OAutoML\nimport warnings\n\n# Remove all the warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:30:05.290753Z","iopub.execute_input":"2024-03-14T03:30:05.291219Z","iopub.status.idle":"2024-03-14T03:30:07.432988Z","shell.execute_reply.started":"2024-03-14T03:30:05.291169Z","shell.execute_reply":"2024-03-14T03:30:07.430900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load the dataset\ntrain_data = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/train.csv\")\ntest_data = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:30:07.436146Z","iopub.execute_input":"2024-03-14T03:30:07.436944Z","iopub.status.idle":"2024-03-14T03:30:07.797082Z","shell.execute_reply.started":"2024-03-14T03:30:07.436888Z","shell.execute_reply":"2024-03-14T03:30:07.795897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:30:07.798719Z","iopub.execute_input":"2024-03-14T03:30:07.800670Z","iopub.status.idle":"2024-03-14T03:30:07.836764Z","shell.execute_reply.started":"2024-03-14T03:30:07.800611Z","shell.execute_reply":"2024-03-14T03:30:07.835392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Initialize H2O\nh2o.init()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:30:07.840539Z","iopub.execute_input":"2024-03-14T03:30:07.841076Z","iopub.status.idle":"2024-03-14T03:30:18.511498Z","shell.execute_reply.started":"2024-03-14T03:30:07.841026Z","shell.execute_reply":"2024-03-14T03:30:18.509928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert DataFrame to H2O Frame\ntrain_h2o = h2o.H2OFrame(train_data)\ntest_h2o = h2o.H2OFrame(test_data)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:30:18.518205Z","iopub.execute_input":"2024-03-14T03:30:18.519763Z","iopub.status.idle":"2024-03-14T03:30:23.861676Z","shell.execute_reply.started":"2024-03-14T03:30:18.519696Z","shell.execute_reply":"2024-03-14T03:30:23.860434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Identify predictor columns and response column\nx = train_h2o.columns[:-1]  # Assuming all columns except the last one are predictors\ny = \"expert_consensus\"  # Assuming 'expert_consensus' is the target variable","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:30:23.863650Z","iopub.execute_input":"2024-03-14T03:30:23.864526Z","iopub.status.idle":"2024-03-14T03:30:23.871220Z","shell.execute_reply.started":"2024-03-14T03:30:23.864477Z","shell.execute_reply":"2024-03-14T03:30:23.869548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Split the dataset into training and testing sets\ntrain_h2o, test_h2o = train_h2o.split_frame(ratios=[0.8], seed=42)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:30:23.873687Z","iopub.execute_input":"2024-03-14T03:30:23.874173Z","iopub.status.idle":"2024-03-14T03:30:24.647838Z","shell.execute_reply.started":"2024-03-14T03:30:23.874127Z","shell.execute_reply":"2024-03-14T03:30:24.646577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Run AutoML\naml = H2OAutoML(max_runtime_secs=600)  # Set max runtime in seconds\naml.train(x=x, y=y, training_frame=train_h2o)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:30:24.650456Z","iopub.execute_input":"2024-03-14T03:30:24.651764Z","iopub.status.idle":"2024-03-14T03:40:27.570052Z","shell.execute_reply.started":"2024-03-14T03:30:24.651699Z","shell.execute_reply":"2024-03-14T03:40:27.568679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# View the AutoML leaderboard\nlb = aml.leaderboard\nprint(lb)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:40:27.571830Z","iopub.execute_input":"2024-03-14T03:40:27.574750Z","iopub.status.idle":"2024-03-14T03:40:27.593027Z","shell.execute_reply.started":"2024-03-14T03:40:27.574676Z","shell.execute_reply":"2024-03-14T03:40:27.592047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Get the best model\nbest_model = aml.leader\nprint(best_model)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:40:27.597373Z","iopub.execute_input":"2024-03-14T03:40:27.598350Z","iopub.status.idle":"2024-03-14T03:40:27.626657Z","shell.execute_reply.started":"2024-03-14T03:40:27.598279Z","shell.execute_reply":"2024-03-14T03:40:27.625416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Use the best model for predictions\npredictions = best_model.predict(test_h2o)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:40:27.628358Z","iopub.execute_input":"2024-03-14T03:40:27.628784Z","iopub.status.idle":"2024-03-14T03:40:28.329790Z","shell.execute_reply.started":"2024-03-14T03:40:27.628748Z","shell.execute_reply":"2024-03-14T03:40:28.328386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Evaluate the model\nperformance = best_model.model_performance(test_h2o)\nprint(performance)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:40:28.331475Z","iopub.execute_input":"2024-03-14T03:40:28.333517Z","iopub.status.idle":"2024-03-14T03:40:29.149207Z","shell.execute_reply.started":"2024-03-14T03:40:28.333458Z","shell.execute_reply":"2024-03-14T03:40:29.147835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Generate model explanations\nexplain_model = aml.explain(frame=test_h2o, figsize=(8, 6))","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:40:29.151754Z","iopub.execute_input":"2024-03-14T03:40:29.152637Z","iopub.status.idle":"2024-03-14T03:55:58.730115Z","shell.execute_reply.started":"2024-03-14T03:40:29.152587Z","shell.execute_reply":"2024-03-14T03:55:58.728854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"aml.explain_row(frame = test_h2o, row_index = 15, figsize = (8,6))","metadata":{"execution":{"iopub.status.busy":"2024-03-14T03:55:58.732009Z","iopub.execute_input":"2024-03-14T03:55:58.732601Z","iopub.status.idle":"2024-03-14T03:56:00.311216Z","shell.execute_reply.started":"2024-03-14T03:55:58.732562Z","shell.execute_reply":"2024-03-14T03:56:00.309785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}