Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit c83cfce1 authored by Muhammad Salman Shahid's avatar Muhammad Salman Shahid
Browse files

Modified the scripts for the file naming

parent 26426f9c
......@@ -266,44 +266,6 @@ def dataframe_with_no_tzinfo(dataframe, column_name, tz_convert):
return dataframe
########################################################################################################################
# METHOD 8: STANDARDIZING THE DATA IN TEST AND TRAIN
########################################################################################################################
def standardize_data(dataframe, split_percentage, column_name):
"""
STANDARDIZING THE DATA IN TEST AND TRAIN
:param dataframe: dataframe to be splitted in to test train and valid
:param split_percentage: List of split percentages e.g [0.6, 0.8]
:param column_name: name of value column
:return: [X_train_scaled, X_valid_scaled, X_test_scaled, y_train, y_valid, y_test]: list of dataframes
"""
# declaring global variables
global X_train, y_train, train, X_train_scaled, X_valid, y_valid, valid, X_valid_scaled, \
X_test, y_test, test, X_test_scaled
# Splitting the dataframe according to split percentages
train, valid, test = np.split(dataframe, [int(split_percentage[0] * len(dataframe)),
int(split_percentage[1] * len(dataframe))])
# making the data scaler
scaler = StandardScaler()
# List of the dataframes to be created
list_dataframes = [[X_train, y_train, train, X_train_scaled], [X_valid, y_valid, valid, X_valid_scaled],
[X_test, y_test, test, X_test_scaled]]
for df in list_dataframes:
# Splitting the X and y dataframes
df[0], df[1] = df[2].drop([column_name], axis=1), df[2][column_name]
# Transforming the dataframe according to standardscaler
df[3] = scaler.fit_transform(df[0])
# Returning the dataframes of X_train_scaled, X_valid_scaled, X_test_scaled, y_train, y_valid, y_test
return [X_train_scaled, X_valid_scaled, X_test_scaled, y_train, y_valid, y_test]
########################################################################################################################
# METHOD 9: PLOT DATAFRAME
########################################################################################################################
......@@ -381,7 +343,7 @@ def split_data(dataframe, train_volume=0.6, val_volume=0.5, validation_days=14,
return train, val, test
def plot_subplots(dict_1min, dict_10min, dict_30min, appliances, path):
def plot_subplots(dict_1min, dict_10min, dict_30min, appliances, path, validation_days, test_days):
i = 1
for appliance in appliances:
plt.figure(i)
......@@ -402,8 +364,12 @@ def plot_subplots(dict_1min, dict_10min, dict_30min, appliances, path):
dict_30min[appliance].plot(ax=axes[2], title="30 minute disaggreagation")
fig_name = "{}/{}.jpg".format(path, appliance)
plt.savefig(fig_name)
plt.xticks([])
fig_name = "{}_{}_appliance_{}_v{}_t{}".format(path.split(" ")[0].lower(),
path.split(" ")[1].lower(), appliance,
validation_days, test_days)
plt.savefig("{}/Sampling comparison/{}.jpg".format(path, fig_name))
print(fig_name, "is saved.")
plt.close()
......@@ -422,7 +388,7 @@ def dicts_n_mins(test_dataframe, prediction_dictionary, appliances):
return dict_n_min
def plot_losses(losses, min_samples_split, sampling, appliance, path_loss):
def plot_losses(losses, min_samples_split, sampling, appliance, path, validation_days, test_days):
index = np.arange(len(min_samples_split))
bar_width = 0.4
opacity = 0.35
......@@ -430,11 +396,14 @@ def plot_losses(losses, min_samples_split, sampling, appliance, path_loss):
plt.bar(index, losses, bar_width, alpha=opacity, color='b')
plt.xlabel('min_samples_split', fontsize=30)
plt.ylabel('loss', fontsize=30)
plt.title('validation losses: sampling={}, appliance:{}'.format(sampling, appliance), fontsize='25')
title = "mse_error_{}_{}_sampling_{}_appliance_{}_v{}_t{}".format(path.split(" ")[0].lower(),
path.split(" ")[1].lower(), sampling, appliance,
validation_days, test_days)
plt.title(title, fontsize='25')
plt.xticks(index + bar_width / 2, min_samples_split, fontsize=20)
plt.yticks(fontsize=20)
plt.rcParams["figure.figsize"] = [24, 16]
fig_name = "{}/MSE Loss - sampling - {}, appliance - {}.jpg".format(path_loss, sampling, appliance)
fig_name = "{}/Losses/{}.jpg".format(path, title)
plt.savefig(fig_name)
print(fig_name, "is saved.")
plt.close()
......@@ -460,3 +429,29 @@ def mae_loss(y_predict, y_test):
:return:
"""
return np.mean(np.abs(y_predict - y_test))
def error_in_the_regression(prediction_with_min_loss, test, appliances):
"""
:param prediction_with_min_loss:
:param test:
:param appliances:
:return:
"""
mse_losses = {}
mae_losses = {}
for appliance in appliances:
mean_test_value = np.mean(test[appliance].values)
mse_losses[appliance] = mse_loss(prediction_with_min_loss[appliance], test[appliance].values)
mae_losses[appliance] = mae_loss(prediction_with_min_loss[appliance], test[appliance].values)
print('Appliance: {0}::::::: mean = {1:.2f} , mse = {2:.2f} - mae = {3:.2f}'.format(appliance, mean_test_value,
mse_losses[appliance],
mae_losses[appliance]))
return mse_losses, mae_losses
......@@ -22,13 +22,16 @@ if __name__ == "__main__":
layers = [1, 256, 512, 1024, 1]
epochs = 150
min_val_loss_1min, prediction_with_min_loss_1min = prediction_using_neural_network(train_dataframe=train_1min,
val_dataframe=val_1min,
test_dataframe=test_1min,
appliances=appliances,
layers=layers,
sampling=sampling1,
model_path=model_path)
model_path=model_path,
epochs=epochs)
##########################################
......@@ -46,7 +49,8 @@ if __name__ == "__main__":
appliances=appliances,
layers=layers,
sampling=sampling1,
model_path=model_path)
model_path=model_path,
epochs=epochs)
##########################################
sampling30 = "30 minute"
......@@ -63,7 +67,8 @@ if __name__ == "__main__":
appliances=appliances,
layers=layers,
sampling=sampling1,
model_path=model_path)
model_path=model_path,
epochs=epochs)
dict_1min = dicts_n_mins(test_dataframe=test_1min, prediction_dictionary=prediction_with_min_loss_1min,
appliances=appliances)
......
......@@ -26,7 +26,7 @@ if __name__ == "__main__":
min_samples_split = np.arange(2, 500, 10)
path_loss = "Random Forest/Losses"
path = "Random Forest"
min_val_loss_1min, prediction_with_min_loss_1min = prediction_using_random_forest(train_dataframe=train_1min,
val_dataframe=val_1min,
......@@ -34,7 +34,7 @@ if __name__ == "__main__":
appliances=appliances,
min_samples_split=min_samples_split,
sampling=sampling1,
path_loss=path_loss,
path=path,
validation_days=validation_days,
test_days=test_days)
......@@ -57,7 +57,7 @@ if __name__ == "__main__":
appliances=appliances,
min_samples_split=min_samples_split,
sampling=sampling1,
path_loss=path_loss,
path=path,
validation_days=validation_days,
test_days=test_days)
......@@ -81,7 +81,7 @@ if __name__ == "__main__":
appliances=appliances,
min_samples_split=min_samples_split,
sampling=sampling1,
path_loss=path_loss,
path=path,
validation_days=validation_days,
test_days=test_days)
......@@ -98,5 +98,4 @@ if __name__ == "__main__":
dict_30min = dicts_n_mins(test_dataframe=test_30min, prediction_dictionary=prediction_with_min_loss_30min,
appliances=appliances)
path = "Random Forest/Sampling comparison"
plot_subplots(dict_1min, dict_10min, dict_30min, appliances, path)
plot_subplots(dict_1min, dict_10min, dict_30min, appliances, path, validation_days, test_days)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment