输入包含NaN,无穷大或对于dtype('float64')模型拟合而言太大的值

时间:2018-11-04 02:14:00

标签: python-2.7

我不断收到这个奇怪的错误: “输入包含NaN,无穷大或对于dtype('float64')而言太大的值”

当我尝试两次运行以下功能时。

def timeStudyNN(hiddenLayer,size,dataSet,xScale,technique):
dataSet['quality'] = dataSet['quality'].map({
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 1,
    8: 1
})
y = dataSet.quality
if technique == 'pca':
    pca = PCA(5)
    projected = pca.fit_transform(xScale)
elif technique == 'ica':
    ica = FastICA(random_state=0, n_components=5)
    projected = ica.fit_transform(xScale)
elif technique == 'rp':
    rp = GaussianRandomProjection(n_components=3)
    projected = rp.fit_transform(xScale)

X_train, X_test, y_train, y_test = train_test_split(projected, y, test_size=size, random_state=3)
start1 = time.time()
NN = MLPClassifier(hidden_layer_sizes=hiddenLayer, max_iter=500, alpha=0.0001,
                   verbose=False, random_state=3, tol=0.000000001, activation="logistic")
NN.fit(X_train, y_train)
end1 = time.time()
total_learning_time1 = end1 - start1
return total_learning_time1

当我运行以下代码时,我会报错。

print timeStudyNN((30,30,30),0.9,data,X_scaled,'pca')
print timeStudyNN((30,30,30),0.8,data,X_scaled,'pca')

但是,当我通过注释掉第二个或第一个“ print”语句一次运行它时,我不会收到任何错误。有人知道为什么会这样吗?

有关完整错误,请参考以下屏幕截图: enter image description here

0 个答案:

没有答案