-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdemo.py
45 lines (33 loc) · 1.27 KB
/
demo.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
from model.MSVR import MSVR
from model.utility import create_dataset,rmse
from sklearn.preprocessing import MinMaxScaler
import numpy as np
import argparse
dataPath = 'data/MackeyGlass_t17.txt'
rawData = np.loadtxt(dataPath)
parser = argparse.ArgumentParser(
description='MSVR for Time Series Forecasting')
parser.add_argument('-inputDim', type=int, default=10, metavar='N',
help='steps for prediction (default: 1)')
parser.add_argument('-outputH', type=int, default=2)
if __name__ == "__main__":
opt = parser.parse_args()
dim = opt.inputDim
h = opt.outputH
ts = rawData.reshape(-1)
segmentation = int(len(ts)*2/3)
dataset = create_dataset(ts,dim,h)
scaler = MinMaxScaler(feature_range=(-1, 1))
dataset = scaler.fit_transform(dataset)
X, Y = dataset[:, :(0 - h)], dataset[:, (0-h):]
train_input = X[:segmentation, :]
train_target = Y[:segmentation].reshape(-1, h)
test_input = X[segmentation:, :]
test_target = Y[segmentation:].reshape(-1, h)
msvr = MSVR()
msvr.fit(train_input,train_target)
trainPred = msvr.predict(train_input)
testPred = msvr.predict(test_input)
trainMetric = rmse(train_target,trainPred)
testMetric = rmse(test_target,testPred)
print(trainMetric, testMetric)