-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MLGlobalHealth:main' into main
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import numpy as np\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"from sklearn.preprocessing import StandardScaler\n", | ||
"from sklearn.linear_model import RidgeCV\n", | ||
"from sklearn.pipeline import Pipeline\n", | ||
"from sklearn.metrics import mean_absolute_error\n", | ||
"\n", | ||
"# Load the data\n", | ||
"train_df = pd.read_csv('path/to/your/train.csv')\n", | ||
"test_df = pd.read_csv('path/to/your/test.csv')\n", | ||
"target = 'target' # e.g. deprived_sev\n", | ||
"\n", | ||
"# Split features and target\n", | ||
"X_train = train_df.drop(columns=[target])\n", | ||
"y_train = train_df[target]\n", | ||
"X_test = test_df.drop(columns=[target])\n", | ||
"y_test = test_df[target]\n", | ||
"\n", | ||
"# Define a wide range of alphas\n", | ||
"alphas = np.logspace(-6, 6, 13)\n", | ||
"\n", | ||
"# Create the pipeline\n", | ||
"pipeline = Pipeline([\n", | ||
" ('scaler', StandardScaler()),\n", | ||
" ('ridge', RidgeCV(alphas=alphas, store_cv_values=True))\n", | ||
"])\n", | ||
"\n", | ||
"# Fit the model\n", | ||
"pipeline.fit(X_train, y_train)\n", | ||
"\n", | ||
"# Predict\n", | ||
"predictions = pipeline.predict(X_test)\n", | ||
"\n", | ||
"# Evaluate using MAE\n", | ||
"mae = mean_absolute_error(y_test, predictions)\n", | ||
"print(f'Mean Absolute Error: {mae}')\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |