-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
125 lines (101 loc) · 5.81 KB
/
test.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- coding:utf-8 -*-
__author__ = 'HeYongxing'
from util.getData import *
from regression.standRegression import *
# 十号线路
getData = getData()
# 0 1 2 3 4 5 6 7 8
# :return: data [星期, 天气, 最高温, 最低温, 节假日长度, 第i个节假日, 工作日长度, 第i个工作日, date,
# 9 10 11
# 小时, 线路, 数量(y)]
# :return: 返回20150101到20150107的测试数据集
# 0 1 2 3 4 5 6 7 8 9
# [日期, 星期, 天气, 最高温, 最低温, 节假日长度, 第i个节假日, 工作日长度, 第i个工作日, 小时]
def test(min_day_train, max_day_train, min_day_test, max_day_test, line_num=[11], features=[0, 1, 2, 3, 4, 5, 6, 7, 9]):
print " ", min_day_train, \
" ", max_day_train, \
" ", min_day_test, \
" ", max_day_test, \
" ", line_num[0],
data = getData.get_train_data(min_day=min_day_train, max_day=max_day_train, line_num=line_num)
train = np.array(data)
xtrain = train[:, features]
ytrain = train[:, -1]
# data = getData.get_test_data()
# test = np.array(data)
# xtest = test[:, 1:]
data = getData.get_train_data(min_day=min_day_test, max_day=max_day_test, line_num=line_num)
test = np.array(data)
xtest = test[:, features]
ytest = test[:, -1]
from sklearn import linear_model
clf = linear_model.BayesianRidge(normalize=True)
clf.fit(xtrain, ytrain)
yHat = clf.predict(xtest)
print " ",rssError(ytest, yHat),
from sklearn import tree
clf = tree.DecisionTreeRegressor()
clf.fit(xtrain, ytrain)
yHat = clf.predict(xtest)
print " ",rssError(ytest, yHat),
from sklearn.ensemble import GradientBoostingRegressor
clf = GradientBoostingRegressor()
clf.fit(xtrain, ytrain)
yHat = clf.predict(xtest)
print " ",rssError(ytest, yHat),
from sklearn.neighbors import KNeighborsRegressor
clf = KNeighborsRegressor(n_neighbors=1)
clf.fit(xtrain, ytrain)
yHat = clf.predict(xtest)
print " ",rssError(ytest, yHat),
clf = linear_model.LassoLars(alpha=.01, normalize=True)
clf.fit(xtrain, ytrain)
yHat = clf.predict(xtest)
print " ",rssError(ytest, yHat)
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[0, 1, 4, 5, 6, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[0, 1, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[0, 1, 2, 3, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[0, 1, 4, 6, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[0, 1, 5, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[0, 1, 2,3,5, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[0,5, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[1, 5, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[1,2,3, 4, 5, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007",
line_num=[11], features=[1, 4, 5, 6, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[0, 1, 4, 5, 6, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[0, 1, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[0, 1, 2, 3, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[0, 1, 4, 6, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[0, 1, 5, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[0, 1,2,3, 5, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[0,5, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[1, 5, 7, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[1,2,3, 4, 5, 9])
test(min_day_train="20141010", max_day_train="20141120", min_day_test="20141001", max_day_test="20141007", line_num=[6],
features=[1, 4, 5, 6, 9])
# 0 1 2 3 4 5 6 7 8
# :return: data [星期, 天气, 最高温, 最低温, 节假日长度, 第i个节假日, 工作日长度, 第i个工作日, date,
# 9 10 11
# 小时, 线路, 数量(y)]