{
"cells": [
{
"cell_type": "code",
"execution_count": 33,
"id": "ae07aeb9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"best params:- {'lasso__alpha': 0.1}\n",
"R2 Score: 45%\n",
"best params:- {'xgbregressor__learning_rate': 0.1}\n",
"R2 Score: 56%\n",
"best params:- {'ridge__alpha': 10.0}\n",
"R2 Score: 56%\n",
"best params:- {'elasticnet__alpha': 0.021544346900318832}\n",
"R2 Score: 55%\n",
"best params:- {'lasso__alpha': 0.1}\n",
"R2 Score: 45%\n",
"best params:- {'xgbregressor__learning_rate': 0.1}\n",
"R2 Score: 56%\n",
"best params:- {'ridge__alpha': 10.0}\n",
"R2 Score: 56%\n",
"best params:- {'elasticnet__alpha': 0.021544346900318832}\n",
"R2 Score: 55%\n",
"best params:- {'lasso__alpha': 0.1}\n",
"R2 Score: 47%\n",
"best params:- {'xgbregressor__learning_rate': 0.9}\n",
"R2 Score: 57%\n",
"best params:- {'ridge__alpha': 10.0}\n",
"R2 Score: 57%\n",
"best params:- {'elasticnet__alpha': 0.021544346900318832}\n",
"R2 Score: 57%\n",
"best params:- {'lasso__alpha': 0.1}\n",
"R2 Score: 47%\n",
"best params:- {'xgbregressor__learning_rate': 0.5}\n",
"R2 Score: 57%\n",
"best params:- {'ridge__alpha': 10.0}\n",
"R2 Score: 57%\n",
"best params:- {'elasticnet__alpha': 0.021544346900318832}\n",
"R2 Score: 57%\n",
"best params:- {'lasso__alpha': 0.1}\n",
"R2 Score: 47%\n",
"best params:- {'xgbregressor__learning_rate': 0.1}\n",
"R2 Score: 59%\n",
"best params:- {'ridge__alpha': 10.0}\n",
"R2 Score: 59%\n",
"best params:- {'elasticnet__alpha': 0.021544346900318832}\n",
"R2 Score: 59%\n",
"best params:- {'lasso__alpha': 0.1}\n",
"R2 Score: 47%\n",
"best params:- {'xgbregressor__learning_rate': 0.1}\n",
"R2 Score: 59%\n",
"best params:- {'ridge__alpha': 10.0}\n",
"R2 Score: 59%\n",
"best params:- {'elasticnet__alpha': 0.021544346900318832}\n",
"R2 Score: 59%\n"
]
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from sklearn.pipeline import make_pipeline\n",
"from sklearn.preprocessing import StandardScaler\n",
"from sklearn.impute import SimpleImputer\n",
"from sklearn.tree import DecisionTreeRegressor, plot_tree\n",
"from sklearn.ensemble import RandomForestRegressor\n",
"from sklearn.model_selection import GridSearchCV, RandomizedSearchCV, train_test_split # Hyperparameter tuning\n",
"from category_encoders import OneHotEncoder\n",
"from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score\n",
"from sklearn.linear_model import LinearRegression, Lasso,Ridge,ElasticNet\n",
"from sklearn.tree import DecisionTreeRegressor\n",
"from xgboost import XGBRegressor\n",
"from sklearn.ensemble import GradientBoostingRegressor\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"data = pd.read_csv('C:/Subrat Documents/Honeywell Project Work/1- Multiple Model Performance/sample_load_weather_data.csv')\n",
"#data = pd.read_csv('C:/Users/H511496/advertising.csv')\n",
"data1=data.columns\n",
"#Dropping not relevant fields\n",
"dropped_data = data.drop([\"date\", \"wkday\", \"year\"] , axis = 1, inplace=False)\n",
"\n",
" \n",
" \n",
"from sklearn.preprocessing import LabelEncoder\n",
"\n",
"#Auto encodes any dataframe column of type category or object.\n",
"def dummyEncode(data):\n",
" columnsToEncode = list(data.select_dtypes(include=['category','object']))\n",
" le = LabelEncoder()\n",
" for feature in columnsToEncode:\n",
" try:\n",
" data[feature] = le.fit_transform(data[feature])\n",
" except:\n",
" print('Error encoding '+feature)\n",
" return data\n",
" \n",
"def final(data): \n",
" new_data=dummyEncode(data[['daycode', 'month', 'holidays', 'season', 'weather_type',\n",
" 'temp', 'hr_weather_type', 'cdd', 'hdd']])\n",
" \n",
" new_data['PowerConsumed']=data.PowerConsumed\n",
" #new_data['Model']=df1.Model\n",
" \n",
" \n",
" \n",
" \n",
" #X = new_data.drop(['PowerConsumed'],axis=1)\n",
" # y = new_data['PowerConsumed']\n",
" X = np.array(new_data.drop(['PowerConsumed'],1))\n",
" y = np.array(new_data['PowerConsumed'])\n",
" \n",
" # skale X – normalized -1 to 1\n",
" from sklearn import preprocessing\n",
" X = preprocessing.scale(X)\n",
" \n",
" # redefine X \n",
" new_data.dropna(inplace=True)\n",
" y = np.array(new_data['PowerConsumed'])\n",
" X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.30,random_state=48)\n",
" \n",
" \n",
" \n",
" # Linear Regression Model\n",
" model_lr = make_pipeline(\n",
" LinearRegression()\n",
" \n",
" )\n",
" model_lr.fit(X_train,y_train)\n",
" \n",
" \n",
" # Lasso Model\n",
" model_l = make_pipeline(\n",
" \n",
" Lasso(alpha=1)\n",
" )\n",
" model_l.fit(X_train,y_train)\n",
" \n",
" \n",
" #XGB Regressor Model\n",
" model_xgb = make_pipeline(\n",
" \n",
" XGBRegressor(booster='gblinear') # learning_rate=0.1, 0.01, 02\n",
" )\n",
" \n",
" model_xgb.fit(X_train,y_train)\n",
" \n",
" # Ridge Model\n",
" model_R = make_pipeline(Ridge()\n",
" \n",
" )\n",
" model_R.fit(X_train,y_train)\n",
" \n",
" # Elastic-net Model\n",
" model_Er = make_pipeline(\n",
" \n",
" ElasticNet()\n",
" )\n",
" model_Er.fit(X_train,y_train)\n",
" \n",
"# Function for calculating metrics and outputting into a dataframe\n",
"# models must already be fit to data\n",
" def evaluate_models(model_list, model_nams):\n",
" col_nams = ['model','Accuracy','RMSE','Intercept']\n",
" data_list=[] \n",
" \n",
" \n",
" #Loop through models in model_list and obtain metrics and add to data_list\n",
" for i, model_i in enumerate(model_list):\n",
" row_list = [model_nams[i]]\n",
" row_list.extend([\n",
" \n",
" str(round(r2_score(y_train,model_i.predict(X_train))*100)) + '%',\n",
" mean_squared_error(y_train,model_i.predict(X_train))**0.5,\n",
" model_i._final_estimator.intercept_\n",
" \n",
" \n",
" \n",
" ]);\n",
" data_list.append(row_list)\n",
" df_evals1 = pd.DataFrame(data_list, columns=col_nams)\n",
" \n",
" return df_evals1\n",
" \n",
" \n",
" # Base Model Scores\n",
" models = [model_lr, model_l, model_xgb,model_R,model_Er]\n",
" modelnams = ['linear_regression','lasso', 'xgb_boost_regression','Ridge regression','Elastic net']\n",
" df_evals1 = evaluate_models(models,modelnams)\n",
" df_evals1\n",
" \n",
"\n",
" def hyper():\n",
" #Lasso Tuning\n",
" param_grid = {'lasso__alpha': [0.1, 0.3, 0.5, 0.7, 0.9, 1, 1.5, 2, 2.5]}\n",
" # Lasso Model\n",
" model_l_t = GridSearchCV(\n",
" model_l,\n",
" param_grid = param_grid,\n",
" n_jobs=-1,\n",
" cv=5,\n",
" verbose=0\n",
" )\n",
" model_l_t.fit(X_train,np.ravel(y_train))\n",
" model_l_t_params = model_l_t.best_params_\n",
" print('best params:- ',model_l_t_params) \n",
" print('R2 Score:', str(round(r2_score(y_train,model_l_t.predict(X_train))*100)) + '%')\n",
"\n",
"\n",
" #XGB Boost tuning\n",
" param_grid = {\n",
" 'xgbregressor__learning_rate':[0.1, 0.3, 0.5, 0.7, 0.9, 1, 1]\n",
" }\n",
" # Boost Model\n",
" model_xgb_t = GridSearchCV(\n",
" model_xgb,\n",
" param_grid = param_grid,\n",
" n_jobs=-1,\n",
" cv=5,\n",
" verbose=0,\n",
" \n",
" )\n",
" model_xgb_t.fit(X_train,np.ravel(y_train))\n",
" model_xgb_t_params = model_xgb_t.best_params_\n",
" print('best params:- ',model_xgb_t_params)\n",
" print('R2 Score:', str(round(r2_score(y_train,model_xgb_t.predict(X_train))*100)) + '%')\n",
" \n",
" \n",
" #Ridge Tuning\n",
" param_grid = {'ridge__alpha': np.logspace(-3,3,10)}\n",
" # Ridge Model\n",
" model_R_t = GridSearchCV(\n",
" estimator=model_R,\n",
" param_grid = param_grid,\n",
" \n",
" cv=5 \n",
" )\n",
" model_R_t.fit(X_train,y_train)\n",
" model_R_t_params = model_R_t.best_params_\n",
" print('best params:- ',model_R_t_params)\n",
" \n",
" print('R2 Score:', str(round(r2_score(y_train,model_R_t.predict(X_train))*100)) + '%')\n",
" \n",
" \n",
" #Elastic net Tuning\n",
" param_grid = {'elasticnet__alpha': np.logspace(-3,3,10)}\n",
" # Ridge Model\n",
" model_E_t = GridSearchCV(\n",
" estimator=model_Er,\n",
" param_grid = param_grid,\n",
" \n",
" cv=5\n",
" \n",
" )\n",
" model_E_t.fit(X_train,y_train)\n",
" model_E_t_params = model_E_t.best_params_\n",
" print('best params:- ',model_E_t_params)\n",
" \n",
" print('R2 Score:', str(round(r2_score(y_train,model_E_t.predict(X_train))*100)) + '%')\n",
" \n",
" # Function for calculating metrics and outputting into a dataframe\n",
" # models must already be fit to data\n",
" def evaluate_models(model_list, model_nams):\n",
" col_nams = ['model','Accuracy','RMSE']\n",
" data_list=[] \n",
" #Loop through models in model_list and obtain metrics and add to data_list\n",
" for i, model_i in enumerate(model_list):\n",
" row_list = [model_nams[i]]\n",
" row_list.extend([\n",
" \n",
" str(round(r2_score(y_train,model_i.predict(X_train))*100)) + '%',\n",
" mean_squared_error(y_train,model_i.predict(X_train))**0.5,\n",
" \n",
" \n",
" \n",
" ]);\n",
" data_list.append(row_list)\n",
" df_evals = pd.DataFrame(data_list, columns=col_nams)\n",
" \n",
" return df_evals\n",
" \n",
" \n",
" # Base Model Scores\n",
" models = [model_R,model_l_t, model_xgb_t, model_R_t,model_E_t]\n",
" modelnams = ['linear_regression','lasso', 'xgb_boost_regression','Ridge regression','Elastic net']\n",
" df_evals = evaluate_models(models,modelnams)\n",
" return df_evals\n",
" \n",
" df2=hyper()\n",
" #return df2\n",
" \n",
" \n",
" #data frame of before and after model tunning\n",
" df_evals1.columns = ['model', 'Accuracy_before', 'RMSE_before','Intercept']\n",
" \n",
" df2.columns = ['model', 'Accuracy_after', 'RMSE_after']\n",
" result = pd.merge(df_evals1,df2).sort_values(by=['Accuracy_before','Accuracy_after'],ascending=False)\n",
" \n",
" \n",
" \n",
" \n",
" coef1=model_lr._final_estimator.coef_\n",
" coef2=model_l._final_estimator.coef_\n",
" coef3=model_xgb._final_estimator.coef_\n",
" coef4=model_R._final_estimator.coef_\n",
" coef5=model_Er._final_estimator.coef_\n",
" \n",
" model1=[('linear_regression',coef1[0],coef1[1],coef1[2],coef1[3],coef1[4],coef1[5],coef1[6],coef1[7],coef1[8]),\n",
" ('lasso',coef2[0],coef2[1],coef2[2],coef2[3],coef2[4],coef2[5],coef2[6],coef2[7],coef2[8]),\n",
" ('xgb_boost_regression',coef3[0],coef3[1],coef3[2],coef3[3],coef3[4],coef3[5],coef3[6],coef3[7],coef3[8]),\n",
" ('Ridge regression',coef4[0],coef4[1],coef4[2],coef4[3],coef4[4],coef4[5],coef4[6],coef4[7],coef4[8]),\n",
" ('Elastic net',coef5[0],coef5[1],coef5[2],coef5[3],coef5[4],coef5[5],coef5[6],coef5[7],coef5[8])]\n",
" \n",
" df3=pd.DataFrame(model1,columns=['model','daycode', 'month', 'holidays', 'season', 'weather_type', 'temp',\n",
" 'hr_weather_type', 'cdd', 'hdd'])\n",
" \n",
" \n",
" final_df=pd.merge(result,df3)\n",
" final_df=final_df[['model','Intercept',\n",
" 'daycode', 'month', 'holidays',\n",
" 'season', 'weather_type', 'temp', 'hr_weather_type', 'cdd', 'hdd','Accuracy_before','Accuracy_after','RMSE_before','RMSE_after']]\n",
" return final_df\n",
"\n",
"\n",
"dropped_data.Model.unique()\n",
"\n",
"meter_list = []\n",
"\n",
"meter_dict = {}\n",
"\n",
"model_coeff = pd.DataFrame()\n",
"\n",
"frames = []\n",
"\n",
"for i in dropped_data.Model.unique():\n",
" \n",
" df1=dropped_data[dropped_data['Model']==i]\n",
" \n",
" df1=df1.reset_index(drop=True)\n",
" \n",
" meter_list.append(final(df1))\n",
" \n",
" exec('{} = final(df1)'.format('Final_'+i))\n",
"\n",
"# Inserting New Meter Columns In All The Meter Coefficient Dataset\n",
"for i,j in zip(dropped_data.Model.unique(),meter_list):\n",
" meter_dict[i] = j\n",
" meter_dict[i].insert(loc=0, column=\"Meter\", value=i)\n",
"\n",
"# Creating A Final Table Containing All the Meters Coefficient values of efficent model.\n",
"for i in dropped_data.Model.unique():\n",
" frames.append(meter_dict[i].iloc[:1])\n",
" model_coeff = pd.concat(frames,ignore_index=True)\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "09fc88b0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Meter</th>\n",
" <th>model</th>\n",
" <th>Intercept</th>\n",
" <th>daycode</th>\n",
" <th>month</th>\n",
" <th>holidays</th>\n",
" <th>season</th>\n",
" <th>weather_type</th>\n",
" <th>temp</th>\n",
" <th>hr_weather_type</th>\n",
" <th>cdd</th>\n",
" <th>hdd</th>\n",
" <th>Accuracy_before</th>\n",
" <th>Accuracy_after</th>\n",
" <th>RMSE_before</th>\n",
" <th>RMSE_after</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Meter1</td>\n",
" <td>linear_regression</td>\n",
" <td>1.730499</td>\n",
" <td>-0.012415</td>\n",
" <td>0.181984</td>\n",
" <td>-0.004220</td>\n",
" <td>0.116442</td>\n",
" <td>-0.046420</td>\n",
" <td>0.019165</td>\n",
" <td>0.127320</td>\n",
" <td>0.191427</td>\n",
" <td>-0.022323</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Meter1</td>\n",
" <td>xgb_boost_regression</td>\n",
" <td>[1.2305]</td>\n",
" <td>-0.012415</td>\n",
" <td>0.181987</td>\n",
" <td>-0.004220</td>\n",
" <td>0.116444</td>\n",
" <td>-0.046424</td>\n",
" <td>0.019183</td>\n",
" <td>0.127308</td>\n",
" <td>0.191420</td>\n",
" <td>-0.022321</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Meter1</td>\n",
" <td>Ridge regression</td>\n",
" <td>1.730496</td>\n",
" <td>-0.012307</td>\n",
" <td>0.181441</td>\n",
" <td>-0.004244</td>\n",
" <td>0.115984</td>\n",
" <td>-0.046518</td>\n",
" <td>0.020056</td>\n",
" <td>0.126969</td>\n",
" <td>0.190621</td>\n",
" <td>-0.022158</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350085</td>\n",
" <td>0.350186</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Meter1</td>\n",
" <td>Elastic net</td>\n",
" <td>1.7258</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0%</td>\n",
" <td>55%</td>\n",
" <td>0.526563</td>\n",
" <td>0.351572</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Meter1</td>\n",
" <td>lasso</td>\n",
" <td>1.7258</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0%</td>\n",
" <td>45%</td>\n",
" <td>0.526563</td>\n",
" <td>0.391089</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Meter model Intercept daycode month holidays \\\n",
"0 Meter1 linear_regression 1.730499 -0.012415 0.181984 -0.004220 \n",
"1 Meter1 xgb_boost_regression [1.2305] -0.012415 0.181987 -0.004220 \n",
"2 Meter1 Ridge regression 1.730496 -0.012307 0.181441 -0.004244 \n",
"3 Meter1 Elastic net 1.7258 0.000000 0.000000 -0.000000 \n",
"4 Meter1 lasso 1.7258 0.000000 0.000000 -0.000000 \n",
"\n",
" season weather_type temp hr_weather_type cdd hdd \\\n",
"0 0.116442 -0.046420 0.019165 0.127320 0.191427 -0.022323 \n",
"1 0.116444 -0.046424 0.019183 0.127308 0.191420 -0.022321 \n",
"2 0.115984 -0.046518 0.020056 0.126969 0.190621 -0.022158 \n",
"3 0.000000 -0.000000 0.000000 0.000000 0.000000 -0.000000 \n",
"4 0.000000 -0.000000 0.000000 0.000000 0.000000 -0.000000 \n",
"\n",
" Accuracy_before Accuracy_after RMSE_before RMSE_after \n",
"0 56% 56% 0.350084 0.350085 \n",
"1 56% 56% 0.350084 0.350110 \n",
"2 56% 56% 0.350085 0.350186 \n",
"3 0% 55% 0.526563 0.351572 \n",
"4 0% 45% 0.526563 0.391089 "
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"meter_dict['Meter1']"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "81335d3a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Meter</th>\n",
" <th>model</th>\n",
" <th>Intercept</th>\n",
" <th>daycode</th>\n",
" <th>month</th>\n",
" <th>holidays</th>\n",
" <th>season</th>\n",
" <th>weather_type</th>\n",
" <th>temp</th>\n",
" <th>hr_weather_type</th>\n",
" <th>cdd</th>\n",
" <th>hdd</th>\n",
" <th>Accuracy_before</th>\n",
" <th>Accuracy_after</th>\n",
" <th>RMSE_before</th>\n",
" <th>RMSE_after</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Meter2</td>\n",
" <td>linear_regression</td>\n",
" <td>1.718099</td>\n",
" <td>-0.014981</td>\n",
" <td>0.156421</td>\n",
" <td>-0.020823</td>\n",
" <td>0.075555</td>\n",
" <td>-0.020818</td>\n",
" <td>-0.037825</td>\n",
" <td>0.110043</td>\n",
" <td>0.237415</td>\n",
" <td>0.009163</td>\n",
" <td>57%</td>\n",
" <td>57%</td>\n",
" <td>0.324048</td>\n",
" <td>0.324050</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Meter2</td>\n",
" <td>xgb_boost_regression</td>\n",
" <td>[1.2181]</td>\n",
" <td>-0.014982</td>\n",
" <td>0.156429</td>\n",
" <td>-0.020826</td>\n",
" <td>0.075563</td>\n",
" <td>-0.020828</td>\n",
" <td>-0.037752</td>\n",
" <td>0.109998</td>\n",
" <td>0.237386</td>\n",
" <td>0.009180</td>\n",
" <td>57%</td>\n",
" <td>57%</td>\n",
" <td>0.324048</td>\n",
" <td>0.324048</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Meter2</td>\n",
" <td>Ridge regression</td>\n",
" <td>1.718056</td>\n",
" <td>-0.015048</td>\n",
" <td>0.156048</td>\n",
" <td>-0.020857</td>\n",
" <td>0.075272</td>\n",
" <td>-0.021206</td>\n",
" <td>-0.035672</td>\n",
" <td>0.109410</td>\n",
" <td>0.235651</td>\n",
" <td>0.009515</td>\n",
" <td>57%</td>\n",
" <td>57%</td>\n",
" <td>0.324050</td>\n",
" <td>0.324252</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Meter2</td>\n",
" <td>Elastic net</td>\n",
" <td>1.70045</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0%</td>\n",
" <td>57%</td>\n",
" <td>0.495042</td>\n",
" <td>0.325808</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Meter2</td>\n",
" <td>lasso</td>\n",
" <td>1.70045</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0%</td>\n",
" <td>47%</td>\n",
" <td>0.495042</td>\n",
" <td>0.360155</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Meter model Intercept daycode month holidays \\\n",
"0 Meter2 linear_regression 1.718099 -0.014981 0.156421 -0.020823 \n",
"1 Meter2 xgb_boost_regression [1.2181] -0.014982 0.156429 -0.020826 \n",
"2 Meter2 Ridge regression 1.718056 -0.015048 0.156048 -0.020857 \n",
"3 Meter2 Elastic net 1.70045 -0.000000 0.000000 -0.000000 \n",
"4 Meter2 lasso 1.70045 -0.000000 0.000000 -0.000000 \n",
"\n",
" season weather_type temp hr_weather_type cdd hdd \\\n",
"0 0.075555 -0.020818 -0.037825 0.110043 0.237415 0.009163 \n",
"1 0.075563 -0.020828 -0.037752 0.109998 0.237386 0.009180 \n",
"2 0.075272 -0.021206 -0.035672 0.109410 0.235651 0.009515 \n",
"3 -0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"4 -0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"\n",
" Accuracy_before Accuracy_after RMSE_before RMSE_after \n",
"0 57% 57% 0.324048 0.324050 \n",
"1 57% 57% 0.324048 0.324048 \n",
"2 57% 57% 0.324050 0.324252 \n",
"3 0% 57% 0.495042 0.325808 \n",
"4 0% 47% 0.495042 0.360155 "
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"meter_dict['Meter2']"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "5c9aadcb",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Meter</th>\n",
" <th>model</th>\n",
" <th>Intercept</th>\n",
" <th>daycode</th>\n",
" <th>month</th>\n",
" <th>holidays</th>\n",
" <th>season</th>\n",
" <th>weather_type</th>\n",
" <th>temp</th>\n",
" <th>hr_weather_type</th>\n",
" <th>cdd</th>\n",
" <th>hdd</th>\n",
" <th>Accuracy_before</th>\n",
" <th>Accuracy_after</th>\n",
" <th>RMSE_before</th>\n",
" <th>RMSE_after</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Meter3</td>\n",
" <td>linear_regression</td>\n",
" <td>1.744876</td>\n",
" <td>0.002742</td>\n",
" <td>0.252802</td>\n",
" <td>-0.022835</td>\n",
" <td>0.131996</td>\n",
" <td>0.005065</td>\n",
" <td>0.104033</td>\n",
" <td>-0.004032</td>\n",
" <td>0.171509</td>\n",
" <td>0.019156</td>\n",
" <td>59%</td>\n",
" <td>59%</td>\n",
" <td>0.321816</td>\n",
" <td>0.321822</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Meter3</td>\n",
" <td>xgb_boost_regression</td>\n",
" <td>[1.24488]</td>\n",
" <td>0.002742</td>\n",
" <td>0.252800</td>\n",
" <td>-0.022834</td>\n",
" <td>0.131994</td>\n",
" <td>0.005066</td>\n",
" <td>0.104023</td>\n",
" <td>-0.004026</td>\n",
" <td>0.171512</td>\n",
" <td>0.019155</td>\n",
" <td>59%</td>\n",
" <td>59%</td>\n",
" <td>0.321816</td>\n",
" <td>0.321876</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Meter3</td>\n",
" <td>Ridge regression</td>\n",
" <td>1.744766</td>\n",
" <td>0.002799</td>\n",
" <td>0.250952</td>\n",
" <td>-0.022651</td>\n",
" <td>0.130578</td>\n",
" <td>0.004734</td>\n",
" <td>0.102856</td>\n",
" <td>-0.002193</td>\n",
" <td>0.170858</td>\n",
" <td>0.019244</td>\n",
" <td>59%</td>\n",
" <td>59%</td>\n",
" <td>0.321822</td>\n",
" <td>0.322272</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Meter3</td>\n",
" <td>Elastic net</td>\n",
" <td>1.721199</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0%</td>\n",
" <td>59%</td>\n",
" <td>0.504184</td>\n",
" <td>0.323379</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Meter3</td>\n",
" <td>lasso</td>\n",
" <td>1.721199</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0%</td>\n",
" <td>47%</td>\n",
" <td>0.504184</td>\n",
" <td>0.366958</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Meter model Intercept daycode month holidays \\\n",
"0 Meter3 linear_regression 1.744876 0.002742 0.252802 -0.022835 \n",
"1 Meter3 xgb_boost_regression [1.24488] 0.002742 0.252800 -0.022834 \n",
"2 Meter3 Ridge regression 1.744766 0.002799 0.250952 -0.022651 \n",
"3 Meter3 Elastic net 1.721199 0.000000 0.000000 0.000000 \n",
"4 Meter3 lasso 1.721199 0.000000 0.000000 0.000000 \n",
"\n",
" season weather_type temp hr_weather_type cdd hdd \\\n",
"0 0.131996 0.005065 0.104033 -0.004032 0.171509 0.019156 \n",
"1 0.131994 0.005066 0.104023 -0.004026 0.171512 0.019155 \n",
"2 0.130578 0.004734 0.102856 -0.002193 0.170858 0.019244 \n",
"3 0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"4 0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"\n",
" Accuracy_before Accuracy_after RMSE_before RMSE_after \n",
"0 59% 59% 0.321816 0.321822 \n",
"1 59% 59% 0.321816 0.321876 \n",
"2 59% 59% 0.321822 0.322272 \n",
"3 0% 59% 0.504184 0.323379 \n",
"4 0% 47% 0.504184 0.366958 "
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"meter_dict['Meter3']"
]
},
{
"cell_type": "markdown",
"id": "827fe7e7",
"metadata": {},
"source": [
"### Meter Coefficients"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "3aedb337",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Meter</th>\n",
" <th>model</th>\n",
" <th>Intercept</th>\n",
" <th>daycode</th>\n",
" <th>month</th>\n",
" <th>holidays</th>\n",
" <th>season</th>\n",
" <th>weather_type</th>\n",
" <th>temp</th>\n",
" <th>hr_weather_type</th>\n",
" <th>cdd</th>\n",
" <th>hdd</th>\n",
" <th>Accuracy_before</th>\n",
" <th>Accuracy_after</th>\n",
" <th>RMSE_before</th>\n",
" <th>RMSE_after</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Meter1</td>\n",
" <td>linear_regression</td>\n",
" <td>1.730499</td>\n",
" <td>-0.012415</td>\n",
" <td>0.181984</td>\n",
" <td>-0.004220</td>\n",
" <td>0.116442</td>\n",
" <td>-0.046420</td>\n",
" <td>0.019165</td>\n",
" <td>0.127320</td>\n",
" <td>0.191427</td>\n",
" <td>-0.022323</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Meter2</td>\n",
" <td>linear_regression</td>\n",
" <td>1.718099</td>\n",
" <td>-0.014981</td>\n",
" <td>0.156421</td>\n",
" <td>-0.020823</td>\n",
" <td>0.075555</td>\n",
" <td>-0.020818</td>\n",
" <td>-0.037825</td>\n",
" <td>0.110043</td>\n",
" <td>0.237415</td>\n",
" <td>0.009163</td>\n",
" <td>57%</td>\n",
" <td>57%</td>\n",
" <td>0.324048</td>\n",
" <td>0.324050</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Meter3</td>\n",
" <td>linear_regression</td>\n",
" <td>1.744876</td>\n",
" <td>0.002742</td>\n",
" <td>0.252802</td>\n",
" <td>-0.022835</td>\n",
" <td>0.131996</td>\n",
" <td>0.005065</td>\n",
" <td>0.104033</td>\n",
" <td>-0.004032</td>\n",
" <td>0.171509</td>\n",
" <td>0.019156</td>\n",
" <td>59%</td>\n",
" <td>59%</td>\n",
" <td>0.321816</td>\n",
" <td>0.321822</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Meter model Intercept daycode month holidays \\\n",
"0 Meter1 linear_regression 1.730499 -0.012415 0.181984 -0.004220 \n",
"1 Meter2 linear_regression 1.718099 -0.014981 0.156421 -0.020823 \n",
"2 Meter3 linear_regression 1.744876 0.002742 0.252802 -0.022835 \n",
"\n",
" season weather_type temp hr_weather_type cdd hdd \\\n",
"0 0.116442 -0.046420 0.019165 0.127320 0.191427 -0.022323 \n",
"1 0.075555 -0.020818 -0.037825 0.110043 0.237415 0.009163 \n",
"2 0.131996 0.005065 0.104033 -0.004032 0.171509 0.019156 \n",
"\n",
" Accuracy_before Accuracy_after RMSE_before RMSE_after \n",
"0 56% 56% 0.350084 0.350085 \n",
"1 57% 57% 0.324048 0.324050 \n",
"2 59% 59% 0.321816 0.321822 "
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model_coeff"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "b140e9fc",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"meter_data = {}\n",
"for i in dropped_data.Model.unique():\n",
" meter_data[i] = data[data['Model']== i]\n",
" meter_data[i]['Pred_PowerConsumed'] = model_coeff.loc[0,'Intercept'] + model_coeff.loc[0,'daycode']*meter_data[i]['daycode'] + model_coeff.loc[0,'month']*meter_data[i]['month'] + model_coeff.loc[0,'holidays']*meter_data[i]['holidays'] + model_coeff.loc[0,'season'] + model_coeff.loc[0,'weather_type'] + model_coeff.loc[0,'temp']*meter_data[i]['temp'] + model_coeff.loc[0,'hr_weather_type'] + model_coeff.loc[0,'cdd']*meter_data[i]['cdd'] + model_coeff.loc[0,'hdd']*meter_data[i]['hdd']\n",
" meter_data[i]['Error_Difference'] = meter_data[i]['PowerConsumed'] - meter_data[i]['Pred_PowerConsumed']\n",
" meter_data[i].insert(loc=13, column='Algorithm', value=model_coeff.loc[0,'model'])\n",
" meter_data[i].insert(loc=14, column='Accuracy_before', value=model_coeff.loc[0,'Accuracy_before'])\n",
" meter_data[i].insert(loc=15, column='Accuracy_after', value=model_coeff.loc[0,'Accuracy_after'])\n",
" meter_data[i].insert(loc=16, column='RMSE_before', value=model_coeff.loc[0,'RMSE_before'])\n",
" meter_data[i].insert(loc=17, column='RMSE_after', value=model_coeff.loc[0,'RMSE_after'])\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "a326bf60",
"metadata": {},
"outputs": [],
"source": [
"final_frames = []\n",
"final_table = pd.DataFrame()\n",
"for i in dropped_data.Model.unique():\n",
" final_frames.append(meter_data[i])\n",
"\n",
"final_table = pd.concat(final_frames,ignore_index=True)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "51e9371d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>date</th>\n",
" <th>Model</th>\n",
" <th>wkday</th>\n",
" <th>year</th>\n",
" <th>daycode</th>\n",
" <th>month</th>\n",
" <th>holidays</th>\n",
" <th>season</th>\n",
" <th>weather_type</th>\n",
" <th>temp</th>\n",
" <th>...</th>\n",
" <th>cdd</th>\n",
" <th>hdd</th>\n",
" <th>Algorithm</th>\n",
" <th>Accuracy_before</th>\n",
" <th>Accuracy_after</th>\n",
" <th>RMSE_before</th>\n",
" <th>RMSE_after</th>\n",
" <th>PowerConsumed</th>\n",
" <th>Pred_PowerConsumed</th>\n",
" <th>Error_Difference</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1/1/2017</td>\n",
" <td>Meter1</td>\n",
" <td>sun</td>\n",
" <td>2017</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>W</td>\n",
" <td>mild</td>\n",
" <td>70</td>\n",
" <td>...</td>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>1.108011</td>\n",
" <td>4.404267</td>\n",
" <td>-3.296256</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1/4/2017</td>\n",
" <td>Meter1</td>\n",
" <td>twt</td>\n",
" <td>2017</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>W</td>\n",
" <td>cold</td>\n",
" <td>52</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>8</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>1.328308</td>\n",
" <td>2.886340</td>\n",
" <td>-1.558032</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1/5/2017</td>\n",
" <td>Meter1</td>\n",
" <td>twt</td>\n",
" <td>2017</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>W</td>\n",
" <td>cold</td>\n",
" <td>56</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>1.222549</td>\n",
" <td>3.039877</td>\n",
" <td>-1.817327</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1/7/2017</td>\n",
" <td>Meter1</td>\n",
" <td>sat</td>\n",
" <td>2017</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>W</td>\n",
" <td>cold</td>\n",
" <td>38</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>22</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>1.928590</td>\n",
" <td>2.268267</td>\n",
" <td>-0.339677</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1/10/2017</td>\n",
" <td>Meter1</td>\n",
" <td>twt</td>\n",
" <td>2017</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>W</td>\n",
" <td>mild</td>\n",
" <td>72</td>\n",
" <td>...</td>\n",
" <td>7</td>\n",
" <td>0</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>1.033708</td>\n",
" <td>4.800620</td>\n",
" <td>-3.766913</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1494</th>\n",
" <td>1/31/2021</td>\n",
" <td>Meter3</td>\n",
" <td>mon</td>\n",
" <td>2017</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>1</td>\n",
" <td>Sp</td>\n",
" <td>hot</td>\n",
" <td>84</td>\n",
" <td>...</td>\n",
" <td>19</td>\n",
" <td>0</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>1.951701</td>\n",
" <td>8.614017</td>\n",
" <td>-6.662316</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1495</th>\n",
" <td>2/5/2021</td>\n",
" <td>Meter3</td>\n",
" <td>sat</td>\n",
" <td>2017</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" <td>1</td>\n",
" <td>Sp</td>\n",
" <td>hot</td>\n",
" <td>93</td>\n",
" <td>...</td>\n",
" <td>28</td>\n",
" <td>0</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>2.255808</td>\n",
" <td>10.447265</td>\n",
" <td>-8.191457</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1496</th>\n",
" <td>2/11/2021</td>\n",
" <td>Meter3</td>\n",
" <td>fri</td>\n",
" <td>2017</td>\n",
" <td>5</td>\n",
" <td>8</td>\n",
" <td>1</td>\n",
" <td>Sp</td>\n",
" <td>hot</td>\n",
" <td>93</td>\n",
" <td>...</td>\n",
" <td>28</td>\n",
" <td>0</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>2.446538</td>\n",
" <td>10.459680</td>\n",
" <td>-8.013143</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1497</th>\n",
" <td>2/14/2021</td>\n",
" <td>Meter3</td>\n",
" <td>twt</td>\n",
" <td>2017</td>\n",
" <td>4</td>\n",
" <td>8</td>\n",
" <td>1</td>\n",
" <td>Sp</td>\n",
" <td>hot</td>\n",
" <td>91</td>\n",
" <td>...</td>\n",
" <td>26</td>\n",
" <td>0</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>2.450885</td>\n",
" <td>10.050912</td>\n",
" <td>-7.600027</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1498</th>\n",
" <td>2/17/2021</td>\n",
" <td>Meter3</td>\n",
" <td>sun</td>\n",
" <td>2017</td>\n",
" <td>0</td>\n",
" <td>9</td>\n",
" <td>1</td>\n",
" <td>Sp</td>\n",
" <td>hot</td>\n",
" <td>87</td>\n",
" <td>...</td>\n",
" <td>22</td>\n",
" <td>0</td>\n",
" <td>linear_regression</td>\n",
" <td>56%</td>\n",
" <td>56%</td>\n",
" <td>0.350084</td>\n",
" <td>0.350085</td>\n",
" <td>1.977030</td>\n",
" <td>9.440189</td>\n",
" <td>-7.463160</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1499 rows × 21 columns</p>\n",
"</div>"
],
"text/plain": [
" date Model wkday year daycode month holidays season \\\n",
"0 1/1/2017 Meter1 sun 2017 0 1 1 W \n",
"1 1/4/2017 Meter1 twt 2017 3 1 1 W \n",
"2 1/5/2017 Meter1 twt 2017 4 1 1 W \n",
"3 1/7/2017 Meter1 sat 2017 6 1 1 W \n",
"4 1/10/2017 Meter1 twt 2017 2 1 1 W \n",
"... ... ... ... ... ... ... ... ... \n",
"1494 1/31/2021 Meter3 mon 2017 1 8 1 Sp \n",
"1495 2/5/2021 Meter3 sat 2017 6 8 1 Sp \n",
"1496 2/11/2021 Meter3 fri 2017 5 8 1 Sp \n",
"1497 2/14/2021 Meter3 twt 2017 4 8 1 Sp \n",
"1498 2/17/2021 Meter3 sun 2017 0 9 1 Sp \n",
"\n",
" weather_type temp ... cdd hdd Algorithm Accuracy_before \\\n",
"0 mild 70 ... 5 0 linear_regression 56% \n",
"1 cold 52 ... 0 8 linear_regression 56% \n",
"2 cold 56 ... 0 4 linear_regression 56% \n",
"3 cold 38 ... 0 22 linear_regression 56% \n",
"4 mild 72 ... 7 0 linear_regression 56% \n",
"... ... ... ... .. ... ... ... \n",
"1494 hot 84 ... 19 0 linear_regression 56% \n",
"1495 hot 93 ... 28 0 linear_regression 56% \n",
"1496 hot 93 ... 28 0 linear_regression 56% \n",
"1497 hot 91 ... 26 0 linear_regression 56% \n",
"1498 hot 87 ... 22 0 linear_regression 56% \n",
"\n",
" Accuracy_after RMSE_before RMSE_after PowerConsumed \\\n",
"0 56% 0.350084 0.350085 1.108011 \n",
"1 56% 0.350084 0.350085 1.328308 \n",
"2 56% 0.350084 0.350085 1.222549 \n",
"3 56% 0.350084 0.350085 1.928590 \n",
"4 56% 0.350084 0.350085 1.033708 \n",
"... ... ... ... ... \n",
"1494 56% 0.350084 0.350085 1.951701 \n",
"1495 56% 0.350084 0.350085 2.255808 \n",
"1496 56% 0.350084 0.350085 2.446538 \n",
"1497 56% 0.350084 0.350085 2.450885 \n",
"1498 56% 0.350084 0.350085 1.977030 \n",
"\n",
" Pred_PowerConsumed Error_Difference \n",
"0 4.404267 -3.296256 \n",
"1 2.886340 -1.558032 \n",
"2 3.039877 -1.817327 \n",
"3 2.268267 -0.339677 \n",
"4 4.800620 -3.766913 \n",
"... ... ... \n",
"1494 8.614017 -6.662316 \n",
"1495 10.447265 -8.191457 \n",
"1496 10.459680 -8.013143 \n",
"1497 10.050912 -7.600027 \n",
"1498 9.440189 -7.463160 \n",
"\n",
"[1499 rows x 21 columns]"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"final_table"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "7686901e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1499, 21)"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"final_table.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5957e7a1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc49ba82",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "04e2535c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "de28fbe4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a245c86",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b89970f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}