I'm having trouble figuring out how to use the cross validation scoring
function. As far as I can tell, I'm exactly following the tutorial given
here:
http://scikit-learn.org/0.13/modules/cross_validation.html#computing-cross-validated-metrics

Paraphrase of code:

from sklearn import naive_bayes
from sklearn import cross_validation
from sklearn import metrics

alg = naive_bayes.GaussianNB()
folds = 10

//...data loaded here into x and y

score = cross_validation.cross_val_score(alg, x, y, cv=folds,
scoring=metrics.accuracy_score)

The error I get is:
Error:
Traceback (most recent call last):
  File "pylearn.py", line 431, in <module>
    l = Learn()
  File "pylearn.py", line 173, in __init__
    scores = self.crossVal(x, y, alg, args.cross_val[0])
  File "pylearn.py", line 241, in crossVal
    score = cross_validation.cross_val_score(alg, x, y, cv=folds,
scoring=metrics.f1_score)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/cross_validation.py",
line 1174, in cross_val_score
    for train, test in cv)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/externals/joblib/parallel.py",
line 514, in __call__
    self.dispatch(function, args, kwargs)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/externals/joblib/parallel.py",
line 311, in dispatch
    job = ImmediateApply(func, args, kwargs)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/externals/joblib/parallel.py",
line 135, in __init__
    self.results = func(*args, **kwargs)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/cross_validation.py",
line 1081, in _cross_val_score
    score = scorer(estimator, X_test, y_test)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/metrics/metrics.py", line
1212, in f1_score
    pos_label=pos_label, average=average)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/metrics/metrics.py", line
1359, in fbeta_score
    average=average)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/metrics/metrics.py", line
1635, in precision_recall_fscore_support
    y_type, y_true, y_pred = _check_clf_targets(y_true, y_pred)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/metrics/metrics.py", line
162, in _check_clf_targets
    y_true, y_pred = check_arrays(y_true, y_pred, allow_lists=True)
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/utils/validation.py",
line 181, in check_arrays
    n_samples = _num_samples(arrays[0])
  File
"/usr/local/lib64/python2.7/site-packages/sklearn/utils/validation.py",
line 123, in _num_samples
    raise TypeError("Expected sequence or array-like, got %r" % x)
TypeError: Expected sequence or array-like, got GaussianNB()

Could anyone tell me what I'm doing wrong? Does cross_val_score only work
with certain classifiers?
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to