在scikit-learn中使用learning_curve(Python)

时间:2014-04-22 18:05:31

标签: python scikit-learn

我在Python 2.7.6中运行scikit-learn(0.15)。

我的训练集(X)是33x3(33条记录,3个特征),目标(y)是33x1。我正在尝试在此数据集上使用learning_curve函数(来自sklearn.learning_curve import learning_curve)。

这是X的值:

array([[ 1.        , -0.12493874,  0.04575749],
       [ 0.        , -0.30103   ,  0.03140846],
       [ 1.        , -0.17609126,  0.11394335],
       [ 1.        , -0.30103   , -0.06694679],
       [ 1.        , -0.30103   , -0.12104369],
       [ 1.        , -0.23408321,  0.11270428],
       [ 1.        ,  0.19188553,  0.22577904],
       [ 1.        , -0.23736092, -0.42100531],
       [ 0.        ,  0.21085337,  0.13966199],
       [ 1.        , -0.06214791,  0.07716595],
       [ 1.        ,  0.14612804, -0.01223446],
       [ 1.        ,  0.1383027 ,  0.1217336 ],
       [ 1.        , -0.30103   , -0.18073616],
       [ 0.        ,  0.02996322, -0.09108047],
       [ 0.        ,  0.05435766,  0.1638568 ],
       [ 1.        , -0.11394335,  0.        ],
       [ 1.        ,  0.06694679,  0.30998484],
       [ 0.        ,  0.64345268,  0.02802872],
       [ 1.        ,  0.        , -0.01639042],
       [ 0.        ,  0.11394335, -0.0234811 ],
       [ 0.        ,  0.        ,  0.18799048],
       [ 1.        ,  0.        ,  0.10914447],
       [ 1.        , -0.04139269,  0.        ],
       [ 0.        ,  0.18905624,  0.17026172],
       [ 1.        , -0.14132915,  0.15209098],
       [ 0.        ,  0.30103   ,  0.27036118],
       [ 1.        ,  0.22184875,  0.05435766],
       [ 0.        ,  0.34242268,  0.09455611],
       [ 1.        , -0.20411998, -0.1173856 ],
       [ 0.        ,  0.11394335,  0.01189922],
       [ 1.        , -0.22184875, -0.01378828],
       [ 1.        ,  0.13262557,  0.14390658],
       [ 0.        ,  0.14612804,  0.13353891]])

对于y:

array([1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1,
       0, 1, 0, 0, 0, 1, 0, 1, 0, 0])

当我进入时:

Gmodel=GaussianNB()
learning_curve(Gmodel,X,y,train_sizes=[3,6,10],cv=3)

我收到以下错误:我做错了什么?

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-143-f7cccd85f1fe> in <module>()
----> 1 learning_curve(Gmodel,train_all,target,train_sizes=[3,6,10],cv=3)

/Users/***/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sklearn/learning_curve.pyc in learning_curve(estimator, X, y, train_sizes, cv, scoring, exploit_incremental_learning, n_jobs, pre_dispatch, verbose)
    131             clone(estimator), X, y, scorer, train[:n_train_samples], test,
    132             verbose, parameters=None, fit_params=None, return_train_score=True)
--> 133             for train, test in cv for n_train_samples in train_sizes_abs)
    134         out = np.array(out)[:, :2]
    135         n_cv_folds = out.shape[0] // n_unique_ticks

/Users/***/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.pyc in __call__(self, iterable)
    642             self._iterating = True
    643             for function, args, kwargs in iterable:
--> 644                 self.dispatch(function, args, kwargs)
    645 
    646             if pre_dispatch == "all" or n_jobs == 1:

/Users/***/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.pyc in dispatch(self, func, args, kwargs)
    389         """
    390         if self._pool is None:
--> 391             job = ImmediateApply(func, args, kwargs)
    392             index = len(self._jobs)
    393             if not _verbosity_filter(index, self.verbose):

/Users/***/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.pyc in __init__(self, func, args, kwargs)
    127         # Don't delay the application, to avoid keeping the input
    128         # arguments in memory
--> 129         self.results = func(*args, **kwargs)
    130 
    131     def get(self):

/Users/***/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sklearn/cross_validation.pyc in _fit_and_score(estimator, X, y, scorer, train, test, verbose, parameters, fit_params, return_train_score, return_parameters)
   1195     start_time = time.time()
   1196 
-> 1197     X_train, y_train = _safe_split(estimator, X, y, train)
   1198     X_test, y_test = _safe_split(estimator, X, y, test, train)
   1199     if y_train is None:

/Users/***/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sklearn/cross_validation.pyc in _safe_split(estimator, X, y, indices, train_indices)
   1245 
   1246     if y is not None:
-> 1247         y_subset = y[safe_mask(y, indices)]
   1248     else:
   1249         y_subset = None

TypeError: only integer arrays with one element can be converted to an index 

0 个答案:

没有答案