回归预测
构建数学模型,生成一个高维空间的超平面,使训练组的数据的坐标点尽可能落在该超平面上。这里需要使用SVR类
from sklearn import datasets;
from sklearn.svm import SVR; #构建支持向量回归所需的SVR模型
from sklearn.cross_validation import train_test_split;
from sklearn.preprocessing import StandardScaler;
from numpy import *;
house_dataset = datasets.load_boston()
house_data = house_dataset.data;
house_price = house_dataset.target;
x_train,x_test,y_train,y_test=train_test_split(house_data,house_price,test_size=0.2);
scaler = StandardScaler();
scaler.fit(x_train);
x_train = scaler.transform(x_train);
x_test = scaler.transform(x_test);
svr = SVR(kernel='rbf'); #构建基于rbf(径向基函数)的SVR模型
svr.fit(x_train,y_train); #将训练组数据输入进行训练
y_predict = svr.predict(x_test); #将处理过的预测组数据输入进行预测,得出结果
#将实际结果与预测结果对比观察,2列的数组,左边列是实际结果,右边列是预测结果
result = hstack((y_test.reshape(-1,1),y_predict.reshape(-1,1)));
print(result);