network输入数据有问题

network输入数据有问题

本文介绍了Scikit-neural_network输入数据有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试使用 sknn 训练一些神经网络.我已经通过pandas数据框对数据进行了预处理.当我在标准sklearn分类器上使用fit(x_train,y_train)时,预处理工作正常,但会引发属性错误

I'm trying to train some neural network using sknn. I have preprocessed my data through a pandas dataframe. The preprocessing works fine when I use the fit(x_train,y_train) on standard sklearn classifiers, but it throws the attribute error

anaconda/envs/py3k/lib/python3.4/site-packages/pandas/core/generic.py", line 2360, in __getattr__
(type(self).__name__, name))
 AttributeError: 'DataFrame' object has no attribute 'todense'

或此错误:

/anaconda/envs/py3k/lib/python3.4/site-packages/pandas/core/indexing.py", line 1750, in maybe_convert_indices
raise IndexError("indices are out-of-bounds")

IndexError: indices are out-of-bounds

看似随机(不同的运行,没有任何改变).

Seemingly at random (different runs, without changing anything).

相关代码如下:

            x_train, x_test, y_train, y_test = cross_validation.train_test_split(X_data, Y_data, test_size=1/kfold)
            regr = linear_model.LinearRegression(copy_X=True,fit_intercept=True)
            abr = AdaBoostRegressor(base_estimator=tree.DecisionTreeRegressor(max_depth=max_depth_gridsearch_values[max_depth_counter]), n_estimators = n_estimators_gridsearch_values[n_estimators_counter])
            nn=nn_simple_regressor


            x_train_numeric = x_train.iloc[:,2:]
            x_test_numeric = x_test.iloc[:,2:]

            regr.fit(x_train_numeric, y_train)
            abr.fit(x_train_numeric, y_train)
            nn.fit(x_train_numeric,y_train)

并将回归变量定义为

nn_simple_regressor = Regressor(
layers=[
    Layer("Rectifier", units=100),
    Layer("Linear")],
learning_rate=0.02,
n_iter=10)

我不明白为什么会这样,并且似乎对sknn的支持很小.我怀疑问题实际上与预处理有关,但我不明白为什么它适用于前两个分类器,但不适用于我的NN.有任何想法吗?

I cannot understand why this is happening, and seems like the support for sknn is pretty small. I suspect the issue is actually with the preprocessing, but I don't understand why it works for the first two classifiers but not my NN. Any ideas?

推荐答案

截至2016年2月,Sknn不支持熊猫.为了解决问题中提到的问题,最好的方法是将数据帧转换为numpy数组.在熊猫中使用.as_martix()函数是最简单的方法.

As of February 2016, Sknn does not support pandas. In order to fix the issues stated in the question, the best approach is to convert the dataframe into a numpy array. Using the .as_martix() function in pandas is the easiest way to do so.

这篇关于Scikit-neural_network输入数据有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:46