首页 > > 详细

解析matlab语言程序、matlab编程辅导留学生、调试matlab语言、Processing解析

#coding=utf-8
data=[1123.7,1138.483333,1165.383333,1177.8,1171.266667,1168.133333,1167,1166.133333,1166.266667,1166.466667,1167,1168.133333,1168.533333,1169.466667,1170.533333,1171,1172.333333,1173.633333,1172.7,1157.8]
def regression(data):
from sklearn.preprocessing import StandardScaler
from pandas import DataFrame.
import numpy as np
test=[]
for i in range(12):
data1 = [[0 for i in range(11)] for j in range(10)]
for i in range(10):
data1[i-1][0:11]=([data[i-1],data[i],data[i+1],data[i+2],data[i+3],data[i+4],data[i+5],data[i+6],data[i+7],data[i+8],data[i+9]])
data2 = [[0 for i in range(10)] for j in range(1)]
data2[0][0:10]=([data[10],data[11],data[12],data[13],data[14],data[15],data[16],data[17],data[18],data[19]])
df1=DataFrame(data1,
index=['1','2','3','4','5','6','7','8','9','10'],
columns=['1','2','3','4','5','6','7','8','9','10','11'])
df2=DataFrame(data2,
index=['1'],
columns=['1','2','3','4','5','6','7','8','9','10'])
x_train, y_train=np.split(df1, (10,),axis=1)
x_test, y_test=np.split(df2,(10,),axis=1)
ss_x=StandardScaler()
ss_y=StandardScaler()
x_train=ss_x.fit_transform(x_train)
x_test=ss_x.transform(x_test)
y_train=ss_y.fit_transform(y_train)
from sklearn.linear_model import SGDRegressor
sgd=SGDRegressor()
sgd.fit(x_train,y_train)
sgd_y_predict=sgd.predict(x_test)
test1 = ss_y.inverse_transform(sgd_y_predict) # €?
data.remove(data[0])
data.append(test1.tolist()[0])
test.append(test1.tolist()[0])
return test
print regression(data)
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!