ظهور الخطأ التالي IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices أثناء بناء نموذج BaggingClassifier
قمت ببناء نموذج BaggingClassifier لكن يظهر لي الخطأ التالي:
from sklearn.ensemble importBaggingClassifierfrom sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.datasets import load_breast_cancer
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.svm import SVR
Data= load_breast_cancer()
X =Data.data
y =Data.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=44, shuffle =True)
clf =BaggingClassifier(base_estimator=SVR(),n_estimators=150, random_state=444)
clf.fit(X_train, y_train)print('BaggingClassifier Train Score is : ', clf.score(X_train, y_train))print('BaggingClassifier Test Score is : ', clf.score(X_test, y_test))
c = confusion_matrix(y_test, clf.predict(X_test))print('Confusion Matrix is : \n', c)
sns.heatmap(c, center =True)
plt.show()---------------------------------------------------------------------------IndexErrorTraceback(most recent call last)<ipython-input-45-1d3261b5c2fc>in<module>12 clf =BaggingClassifier(base_estimator=SVR(),n_estimators=150, random_state=444)13 clf.fit(X_train, y_train)--->14print('BaggingClassifier Train Score is : ', clf.score(X_train, y_train))15print('BaggingClassifier Test Score is : ', clf.score(X_test, y_test))16 c = confusion_matrix(y_test, clf.predict(X_test))~\anaconda3\lib\site-packages\sklearn\base.py in score(self, X, y, sample_weight)367"""
368 from .metrics import accuracy_score
--> 369 return accuracy_score(y, self.predict(X), sample_weight=sample_weight)
370
371
~\anaconda3\lib\site-packages\sklearn\ensemble\_bagging.py in predict(self, X)
668 The predicted classes.
669 """-->670 predicted_probabilitiy = self.predict_proba(X)671return self.classes_.take((np.argmax(predicted_probabilitiy, axis=1)),672 axis=0)~\anaconda3\lib\site-packages\sklearn\ensemble\_bagging.py in predict_proba(self, X)718 X,719 self.n_classes_)-->720for i in range(n_jobs))721722# Reduce~\anaconda3\lib\site-packages\joblib\parallel.py in __call__(self, iterable)1002# remaining jobs.1003 self._iterating =False->1004if self.dispatch_one_batch(iterator):1005 self._iterating = self._original_iterator isnotNone1006~\anaconda3\lib\site-packages\joblib\parallel.py in dispatch_one_batch(self, iterator)833returnFalse834else:-->835 self._dispatch(tasks)836returnTrue837~\anaconda3\lib\site-packages\joblib\parallel.py in _dispatch(self, batch)752with self._lock:753 job_idx = len(self._jobs)-->754 job = self._backend.apply_async(batch, callback=cb)755# A job can complete so quickly than its callback is756# called before we get here, causing self._jobs to~\anaconda3\lib\site-packages\joblib\_parallel_backends.py in apply_async(self, func, callback)207def apply_async(self, func, callback=None):208"""Schedule a func to be run"""-->209 result =ImmediateResult(func)210if callback:211 callback(result)~\anaconda3\lib\site-packages\joblib\_parallel_backends.py in __init__(self, batch)588# Don't delay the application, to avoid keeping the input589# arguments in memory-->590 self.results = batch()591592def get(self):~\anaconda3\lib\site-packages\joblib\parallel.py in __call__(self)254with parallel_backend(self._backend, n_jobs=self._n_jobs):255return[func(*args,**kwargs)-->256for func, args, kwargs in self.items]257258def __len__(self):~\anaconda3\lib\site-packages\joblib\parallel.py in<listcomp>(.0)254with parallel_backend(self._backend, n_jobs=self._n_jobs):255return[func(*args,**kwargs)-->256for func, args, kwargs in self.items]257258def __len__(self):~\anaconda3\lib\site-packages\sklearn\ensemble\_bagging.py in _parallel_predict_proba(estimators, estimators_features, X, n_classes)140141for i in range(n_samples):-->142 proba[i, predictions[i]]+=1143144return proba
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`)and integer or boolean arrays are valid indices
السؤال
Meezo ML
قمت ببناء نموذج BaggingClassifier لكن يظهر لي الخطأ التالي:
بماذا أخطأت؟
2 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.