Skip to content

Commit

Permalink
commi commi commi commi commi commition
Browse files Browse the repository at this point in the history
  • Loading branch information
madsh0402 committed Nov 6, 2023
1 parent ae8e265 commit 8bf8c11
Show file tree
Hide file tree
Showing 15 changed files with 12,107 additions and 173 deletions.
133 changes: 129 additions & 4 deletions multivariate Timerseries/.ipynb_checkpoints/Template-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,144 @@
"cells": [
{
"cell_type": "markdown",
"id": "7cd872e9",
"id": "f248adc5",
"metadata": {},
"source": [
"# Template"
]
},
{
"cell_type": "markdown",
"id": "67ffcf07",
"id": "1a956727",
"metadata": {},
"source": [
"### "
"### Default libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "59d3e244",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score\n",
"\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "markdown",
"id": "0e03b267",
"metadata": {},
"source": [
"### Default Functions"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a9f3e954",
"metadata": {},
"outputs": [],
"source": [
"# Custom prediction function\n",
"def custom_predict(X, model):\n",
" \"\"\"\n",
" Custom prediction function that overrides model predictions based on a 'flagged' column in the input data.\n",
" \n",
" Parameters:\n",
" - X (DataFrame): Input data with features including a 'flagged' column.\n",
" - model (model object): Trained model object that has a predict method.\n",
" \n",
" Returns:\n",
" - y_custom_pred (array): Array of predictions with overridden values based on 'flagged' column.\n",
" \"\"\"\n",
" y_pred = model.predict(X)\n",
" \n",
" # Apply the flagged logic\n",
" y_custom_pred = np.where(X['flagged'] == 1, 0, y_pred)\n",
" \n",
" return y_custom_pred\n",
"\n",
"def metrics(y_test, y_pred):\n",
" \"\"\"\n",
" Computes and prints several evaluation metrics for regression models.\n",
" \n",
" Parameters:\n",
" - y_test (array): True target values.\n",
" - y_pred (array): Predicted target values from the model.\n",
" \n",
" Prints:\n",
" - MSE, RMSE, MAE, R^2, and MAPE values.\n",
" \"\"\"\n",
" # Previous metrics\n",
" mse = mean_squared_error(y_test, y_pred)\n",
" rmse = mean_squared_error(y_test, y_pred, squared=False)\n",
" mae = mean_absolute_error(y_test, y_pred)\n",
" r2 = r2_score(y_test, y_pred)\n",
" mape = 100 * (sum(abs((y_test - y_pred) / y_test)) / len(y_test))\n",
" \n",
" print(f\" MSE = {mse}\\nRMSE = {rmse}\\n MAE = {mae}\\n %//R^2% = {r2}\\n MAPE = {mape}%\")"
]
},
{
"cell_type": "markdown",
"id": "61c478bb",
"metadata": {},
"source": [
"### load data temp"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5cc43084",
"metadata": {},
"outputs": [],
"source": [
"# Load the electricity consumption dataset\n",
"filepath = 'C:/Users/madsh/OneDrive/Dokumenter/kandidat/Fællesmappe/Speciale/Forecasting-energy-consumption-in-Denmark/Data/Combined data/'\n",
"data_flagged = pd.read_csv(filepath + 'combined_daily_flagged.csv')\n",
"\n",
"# Put HourDK as DataFrame index\n",
"data_flagged.set_index('HourDK', inplace=True)"
]
},
{
"cell_type": "markdown",
"id": "48efce61",
"metadata": {},
"source": [
"### Deualt test and training split"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e5e87d9c",
"metadata": {},
"outputs": [],
"source": [
"# Re-split the data into training and test sets based on the criteria\n",
"SplitDate = '2022-06-30'\n",
"training_set = data_flagged.loc[data_flagged.index <= SplitDate]\n",
"test_set = data_flagged.loc[data_flagged.index > SplitDate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "903bbff8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -33,7 +158,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 8bf8c11

Please sign in to comment.