-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict.py
89 lines (77 loc) · 2.03 KB
/
predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
"""project3.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/10qd_bkZqMaul3gO6C3RmHhHIYj5nK6tm
"""
#from google.colab import drive
#drive.mount('/content/drive')
import keras
import numpy as np
import pandas as pd
from keras import layers, optimizers, losses, metrics
from keras.models import load_model
import io
import sys
# count the arguments
arguments = len(sys.argv) - 1
#print ("the script is called with %i arguments" % (arguments))
#print(sys.argv[arguments])
# Define input file
if (sys.argv[arguments-1]=="-i"):
data = pd.read_csv(sys.argv[arguments])
#print("h5 ok")
else:
print("h5 file error!")
#hard coded the rest of the files
model = load_model('WindDenseNN.h5', compile=False)
labels = pd.read_csv('actual.csv')
#print(data.shape)
for col in data.columns:
del data[col]
break
#print(data.shape)
result = model.predict(data, batch_size=32)
#print(result.shape)
#print(result)
for col in labels.columns:
timestamps = labels[col].tolist()
del labels[col]
break
#print(labels.shape)
from sklearn.metrics import mean_absolute_error, mean_squared_error
#print(data.head(data.shape[0]))
list1 = []
list2 = []
list1 = list(result)
list2 = labels.values.tolist()
x = range(len(list1))
mae = 0.0
mse = 0.0
mape = 0.0
for n in x:
mae += mean_absolute_error(list2[n], list1[n])
mse += mean_squared_error(list2[n], list1[n])
At = sum(list2[n]) / len(list2[n])
y = len(list1[n])
trash = 0.0
for z in range(0, y):
trash += abs(At - list1[n][z]) / At
trash /= z
mape += trash
mae /= n
mse /= n
mape /= n
print(mae, mse, mape*100,"%")
import csv
with open('predicted.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["MAE", mae, "MAPE", mape*100, "MSE", mse])
for n in x:
y = range(len(list1[n]))
sutoringo = ''
for z in y:
sutoringo += 'list1[n][' + str(z) + '],'
sutoringo[:-1]
sutoringo = 'writer.writerow([timestamps[n],'+ sutoringo +'])'
exec(sutoringo)