-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestAll.py
58 lines (40 loc) · 1.62 KB
/
testAll.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
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn import datasets, linear_model
from sklearn.cross_validation import train_test_split
from sklearn import metrics
data = pd.read_csv("/home/jren/Project/CloudPridict/dataNew.csv")
x = data[['MachineNum','Mem/Exe','CPU/Exe','ExeNum/Machine','TotalExeNum','RealCPU/Machine','RealTotalCPU','RealMem/Machine','RealTotalMem']]
y = data[['TIME']]
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.15)
def try_different_method(clf,metheName):
clf.fit(x_train,y_train)
score = clf.score(x_test, y_test)
result = clf.predict(x_test)
plt.figure()
plt.plot(np.arange(len(result)), y_test,'go-',label='true value')
plt.plot(np.arange(len(result)),result,'ro-',label='predict value')
plt.title(metheName+'--'+'Score: %f'%score)
plt.legend()
plt.show()
#linear regression
linear_reg = linear_model.LinearRegression()
try_different_method(linear_reg,'LinearRegression')
#Tree regression
from sklearn import tree
tree_reg = tree.DecisionTreeRegressor()
try_different_method(tree_reg,'DecisionTreeRegressor')
from sklearn import svm
svr = svm.SVR()
try_different_method(svr,'SVM')
from sklearn import neighbors
knn = neighbors.KNeighborsRegressor()
try_different_method(knn,'KNN')
from sklearn import ensemble
rf =ensemble.RandomForestRegressor(n_estimators=20)
try_different_method(rf,'RandomForestRegressor')
ada = ensemble.AdaBoostRegressor(n_estimators=50)
try_different_method(ada,'AdaBoostRegressor')
gbrt = ensemble.GradientBoostingRegressor(n_estimators=100)
try_different_method(gbrt,'GradientBoostingRegressor')