I have a question I try build my own classifier, it's finish and it works perfect but when I try use a cross-validation score I got a error:
File "/home/webinterpret/workspace/nlp/wi-item-attribute-extraction/attr_extractor.py", line 95, in fit
print self.fitted_models[attr][len(self.fitted_models[attr]) - 1].cross_validation_score(x_train, y_train, 5, 0.2)
File "/home/webinterpret/workspace/nlp/wi-item-attribute-extraction/attr_extractor.py", line 163, in cross_validation_score
cv=self.cv).mean()
File "/home/webinterpret/.virtualenvs/nlp/local/lib/python2.7/site-packages/sklearn/cross_validation.py", line 1361, in cross_val_score
for train, test in cv)
File "/home/webinterpret/.virtualenvs/nlp/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 659, in __call__
self.dispatch(function, args, kwargs)
File "/home/webinterpret/.virtualenvs/nlp/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 406, in dispatch
job = ImmediateApply(func, args, kwargs)
File "/home/webinterpret/.virtualenvs/nlp/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 140, in __init__
self.results = func(*args, **kwargs)
File "/home/webinterpret/.virtualenvs/nlp/local/lib/python2.7/site-packages/sklearn/cross_validation.py", line 1478, in _fit_and_score
test_score = _score(estimator, X_test, y_test, scorer)
File "/home/webinterpret/.virtualenvs/nlp/local/lib/python2.7/site-packages/sklearn/cross_validation.py", line 1534, in _score
score = scorer(estimator, X_test, y_test)
File "/home/webinterpret/.virtualenvs/nlp/local/lib/python2.7/site-packages/sklearn/metrics/scorer.py", line 201, in _passthrough_scorer
return estimator.score(*args, **kwargs)
File "/home/webinterpret/workspace/nlp/wi-item-attribute-extraction/attr_extractor.py", line 198, in score
return (pd.Series(self.predict(x_test)) == y_test).mean()
File "/home/webinterpret/workspace/nlp/wi-item-attribute-extraction/attr_extractor.py", line 190, in predict
result[i] = 1 if self.pattern in item else 0
File "/home/webinterpret/.virtualenvs/nlp/local/lib/python2.7/site-packages/scipy/sparse/compressed.py", line 216, in __eq__
if np.isnan(other):
TypeError: Not implemented for this type
My predict function:
result = np.zeros(text.shape[0])
i = 0
for item in text:
result[i] = 1 if self.pattern in item else 0
i+=1
return result
The error is in "if self.pattern in item else 0" but I don't know how I can make it in a different way?
Pattern is a text like: "car", text is just a text: "This car is broken."
if pattern in item: \n result[i] = 1 \n else: \n result[i]=0Hopefully that will force the error to focus on one aspect of what is happening. Also, try using the debugger to see what the values ofself.patternanditemlook like.