今天用python实现了一下神经网络回归,遇到了好几个问题,总结了一下问题的类型和解决方案:
本文侧重实现过程中的问题解决
代码如下:

from sklearn import datasets
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
from sknn.mlp import Regressor, Layer
from sklearn.metrics import mean_squared_error

boston = datasets.load_boston()
x, y = boston.data, boston.target

x_MinMax = preprocessing.MinMaxScaler()
y_MinMax = preprocessing.MinMaxScaler()   # 归一化 

y = np.array(y).reshape(len(y), 1)
x = x_MinMax.fit_transform(x)
y = y_MinMax.fit_transform(y)  

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, train_size=0.8, random_state=0)

fit1 = Regressor(layers=[Layer("Sigmoid", units=6), Layer("Sigmoid", units=14), Layer("Linear")], learning_rate=0.01,random_state=2000, n_iter=10)
fit1.fit(x_train, y_train)

pred1_train = fit1.predict(x_train)

mse_1 = mean_squared_error(pred1_train,y_train)

print ("Train ERROR = ", mse_1)

 下面是关键部分要想实现上述代码需要装以下几个工具包

如果报错信息 
ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True

1、conda install libpython mingw (这里下载很慢很慢,而且有可能会断 所以下载的时候 时不时看一眼 如果断了 重复上述代码)

如果报错信息,无法加载downsample 

点错误得链接会进入pool.py文件,

修改以下几处地方

(1)把原来from theano.tensor.signal import downsample 修改为图中

(2)用contrl+F 搜索第二处downsample 修改为下图

 注:除了把downsample改为pool 还要把ds 改为ws

(3)用contrl+F 搜索第二处downsample 修改为

 

 

Logo

欢迎加入西安开发者社区!我们致力于为西安地区的开发者提供学习、合作和成长的机会。参与我们的活动,与专家分享最新技术趋势,解决挑战,探索创新。加入我们,共同打造技术社区!

更多推荐