sklearn.gaussian_process fit()不适用于大于100的数组大小

时间:2012-11-13 22:51:51

标签: python scikit-learn

我正在生成一个random.uniform(low=0.0, high=100.0, size=(150,150))数组 我将此输入到生成Xxy的函数中。

但是,如果随机测试矩阵大于100,我会得到以下错误 我试过玩theta值。

有人有这个问题吗?这是一个错误吗? 我正在使用 python2.6 scikit-learn-0.10 。我应该尝试 python3 吗?

欢迎任何建议或意见。

谢谢。

gp.fit( XKrn, yKrn )
  File "/usr/lib/python2.6/scikit_learn-0.10_git-py2.6-linux-x86_64.egg/sklearn/gaussian_process/gaussian_process.py", line 258, in fit
    raise ValueError("X and y must have the same number of rows.")
ValueError: X and y must have the same number of rows.

2 个答案:

答案 0 :(得分:3)

ValueError: X and y must have the same number of rows.表示在您的情况下XKrn.shape[0]应该等于yKrn.shape[0]。生成数据集的代码可能有错误。

这是一个有效的例子:

In [1]: from sklearn.gaussian_process import GaussianProcess

In [2]: import numpy as np

In [3]: X, y = np.random.randn(150, 10), np.random.randn(150)

In [4]: GaussianProcess().fit(X, y)
Out[4]: 
GaussianProcess(beta0=None,
        corr=<function squared_exponential at 0x10d42aaa0>, normalize=True,
        nugget=array(2.220446049250313e-15), optimizer='fmin_cobyla',
        random_start=1,
        random_state=<mtrand.RandomState object at 0x10b4c8360>,
        regr=<function constant at 0x10d42a488>, storage_mode='full',
        theta0=array([[ 0.1]]), thetaL=None, thetaU=None, verbose=False)

目前尚不支持Python 3,目前最新发布的scikit-learn版本为0.12.1。

答案 1 :(得分:0)

我的原帖被删除了。谢谢,Flexo。

我遇到了同样的问题,我传入的行数与我的X和y相同。

在我的情况下,问题实际上是我传递了许多功能以适应我的输出。高斯过程适合单个输出特征。

“行数”错误具有误导性,并且源于我没有正确使用包的事实。要适合这样的多个输出功能,您需要为每个功能提供GP。