python 深度学习（2） -- 神经网络回归模型

from sklearn import datasets
x,y = boston.data,boston.target


from sklearn import preprocessing
x_MinMax = preprocessing.MinMaxScaler()
y_MinMax = preprocessing.MinMaxScaler()
import numpy as np
''' 将 y 转换成 列 '''
y = np.array(y).reshape(len(y),1)
x = x_MinMax.fit_transform(x)
y = y_MinMax.fit_transform(y)
''' 打印列平均值 共 13 列 '''
print x.mean(axis = 0)

''' 打印 x 中的缩放值，共 13 列'''
print x_MinMax.scale_

''' 打印 y 中的缩放值, 共 1 列 '''
print y_MinMax.scale_

''' 按二八原则划分训练集和测试集 '''
import random
from sklearn.cross_validation import train_test_split
np.random.seed(2018)
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size = 0.2)

pip install scikit-neuralnetwork

from sknn.mlp import Regressor,Layer
'''

random_state 参数用来再现相同的数据

'''
fit1 = Regressor(
layers = [Layer("Sigmoid",units = 6),Layer("Sigmoid",units = 14),Layer("Linear")],
learing_rate = 0.02,
random_state = 2018,
n_iter = 10)

# 拟合实际数据，训练属性在 x_train 中，目标存储在 y_train 中
print "fitting model right now"
fit1.fit(x_trian,y_train)

# 预测值
pred1_train = ft1.predict(x_train)
# 计算 MSE
from sklearn.metrics import mean_squared_error
mse_1 = mean_squared_error(pred1_train,y_train)
print "Train ERROR = ", mse_1