Replies: 1 comment
-
Thank you @sraghavm for raising the issue, nice catch! I have merged a fix and also added a notebook ( |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. please help
This is the code i am running:
**from sklearn.metrics import roc_auc_score
df = pd.read_csv("C:/Users/shubh/Desktop/smote/dataset/PROMISE/PROMISE/ant-1.7.csv")
X = df.iloc[:,:-1].values
y = df.iloc[:,-1].values
oversampler = ('smote_variants', 'ADASYN', {'proportion': 1.0})
classifier = ('sklearn.neighbors', 'KNeighborsClassifier', {})
model= Pipeline([('scale', StandardScaler()),
('clf', sv.classifiers.OversamplingClassifier(oversampler, classifier))])
scoring = ['accuracy','precision', 'recall','f1','roc_auc']
scores = cross_validate(model,X,y,cv=StratifiedKFold(n_splits=10),scoring='roc_auc',error_score='raise')
scores**
Whenever i am trying to evaluate AUC score using sklearn CROSS_VALIDATE, it shows following error:
AttributeError Traceback (most recent call last)
~\anaconda3\lib\site-packages\sklearn\metrics_scorer.py in _score(self, method_caller, clf, X, y, sample_weight)
354 try:
--> 355 y_pred = method_caller(clf, "decision_function", X)
356
~\anaconda3\lib\site-packages\sklearn\metrics_scorer.py in _cached_call(cache, estimator, method, *args, **kwargs)
67 if cache is None:
---> 68 return getattr(estimator, method)(*args, **kwargs)
69
~\anaconda3\lib\site-packages\sklearn\utils\metaestimators.py in get(self, obj, owner)
108 # this is to allow access to the docstrings.
--> 109 if not self.check(obj):
110 raise attr_err
~\anaconda3\lib\site-packages\sklearn\pipeline.py in check(self)
44 # raise original
AttributeError
ifattr
does not exist---> 45 getattr(self._final_estimator, attr)
46 return True
AttributeError: 'OversamplingClassifier' object has no attribute 'decision_function'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_6340\3286184398.py in
10 ('clf', sv.classifiers.OversamplingClassifier(oversampler, classifier))])
11 scoring = ['accuracy','precision', 'recall','f1','roc_auc']
---> 12 scores = cross_validate(model,X,y,cv=StratifiedKFold(n_splits=10),scoring='roc_auc',error_score='raise')
13 scores
14 r
~\anaconda3\lib\site-packages\sklearn\model_selection_validation.py in cross_validate(estimator, X, y, groups, scoring, cv, n_jobs, verbose, fit_params, pre_dispatch, return_train_score, return_estimator, error_score)
265 # independent, and that it is pickle-able.
266 parallel = Parallel(n_jobs=n_jobs, verbose=verbose, pre_dispatch=pre_dispatch)
--> 267 results = parallel(
268 delayed(_fit_and_score)(
269 clone(estimator),
~\anaconda3\lib\site-packages\joblib\parallel.py in call(self, iterable)
1083 # remaining jobs.
1084 self._iterating = False
-> 1085 if self.dispatch_one_batch(iterator):
1086 self._iterating = self._original_iterator is not None
1087
~\anaconda3\lib\site-packages\joblib\parallel.py in dispatch_one_batch(self, iterator)
899 return False
900 else:
--> 901 self._dispatch(tasks)
902 return True
903
~\anaconda3\lib\site-packages\joblib\parallel.py in _dispatch(self, batch)
817 with self._lock:
818 job_idx = len(self._jobs)
--> 819 job = self._backend.apply_async(batch, callback=cb)
820 # A job can complete so quickly than its callback is
821 # called before we get here, causing self._jobs to
~\anaconda3\lib\site-packages\joblib_parallel_backends.py in apply_async(self, func, callback)
206 def apply_async(self, func, callback=None):
207 """Schedule a func to be run"""
--> 208 result = ImmediateResult(func)
209 if callback:
210 callback(result)
~\anaconda3\lib\site-packages\joblib_parallel_backends.py in init(self, batch)
595 # Don't delay the application, to avoid keeping the input
596 # arguments in memory
--> 597 self.results = batch()
598
599 def get(self):
~\anaconda3\lib\site-packages\joblib\parallel.py in call(self)
286 # change the default number of processes to -1
287 with parallel_backend(self._backend, n_jobs=self._n_jobs):
--> 288 return [func(*args, **kwargs)
289 for func, args, kwargs in self.items]
290
~\anaconda3\lib\site-packages\joblib\parallel.py in (.0)
286 # change the default number of processes to -1
287 with parallel_backend(self._backend, n_jobs=self._n_jobs):
--> 288 return [func(*args, **kwargs)
289 for func, args, kwargs in self.items]
290
~\anaconda3\lib\site-packages\sklearn\utils\fixes.py in call(self, *args, **kwargs)
214 def call(self, *args, **kwargs):
215 with config_context(**self.config):
--> 216 return self.function(*args, **kwargs)
217
218
~\anaconda3\lib\site-packages\sklearn\model_selection_validation.py in _fit_and_score(estimator, X, y, scorer, train, test, verbose, parameters, fit_params, return_train_score, return_parameters, return_n_test_samples, return_times, return_estimator, split_progress, candidate_progress, error_score)
700
701 fit_time = time.time() - start_time
--> 702 test_scores = _score(estimator, X_test, y_test, scorer, error_score)
703 score_time = time.time() - start_time - fit_time
704 if return_train_score:
~\anaconda3\lib\site-packages\sklearn\model_selection_validation.py in _score(estimator, X_test, y_test, scorer, error_score)
759 scores = scorer(estimator, X_test)
760 else:
--> 761 scores = scorer(estimator, X_test, y_test)
762 except Exception:
763 if error_score == "raise":
~\anaconda3\lib\site-packages\sklearn\metrics_scorer.py in call(self, estimator, X, y_true, sample_weight)
214 Score function applied to prediction of estimator on X.
215 """
--> 216 return self._score(
217 partial(_cached_call, None),
218 estimator,
~\anaconda3\lib\site-packages\sklearn\metrics_scorer.py in _score(self, method_caller, clf, X, y, sample_weight)
370
371 if y_type == "binary":
--> 372 y_pred = self.select_proba_binary(y_pred, clf.classes)
373 elif isinstance(y_pred, list):
374 y_pred = np.vstack([p[:, -1] for p in y_pred]).T
~\anaconda3\lib\site-packages\sklearn\pipeline.py in classes_(self)
714 def classes_(self):
715 """The classes labels. Only exist if the last step is a classifier."""
--> 716 return self.steps[-1][1].classes_
717
718 def _more_tags(self):
AttributeError: 'OversamplingClassifier' object has no attribute 'classes_'
Beta Was this translation helpful? Give feedback.
All reactions