我有一個(gè)自己實(shí)現(xiàn)的自定義估計(jì)器,但無法使用,我相信這與我的方法cross_val_score()有關(guān)。predict()這是完整的錯(cuò)誤跟蹤: Traceback (most recent call last): File "/Users/joann/Desktop/Implementac?o?es ML/Adaboost Classifier/test.py", line 30, in <module> ada2_score = cross_val_score(ada_2, X, y, cv=5) File "/Users/joann/opt/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 390, in cross_val_score error_score=error_score) File "/Users/joann/opt/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 236, in cross_validate for train, test in cv.split(X, y, groups)) File "/Users/joann/opt/anaconda3/lib/python3.7/site-packages/joblib/parallel.py", line 1004, in __call__ if self.dispatch_one_batch(iterator): File "/Users/joann/opt/anaconda3/lib/python3.7/site-packages/joblib/parallel.py", line 835, in dispatch_one_batch self._dispatch(tasks) File "/Users/joann/opt/anaconda3/lib/python3.7/site-packages/joblib/parallel.py", line 754, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/Users/joann/opt/anaconda3/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 209, in apply_async result = ImmediateResult(func) File "/Users/joann/opt/anaconda3/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 590, in __init__ self.results = batch() File "/Users/joann/opt/anaconda3/lib/python3.7/site-packages/joblib/parallel.py", line 256, in __call__ for func, args, kwargs in self.items]我的predict(self, X)方法返回一個(gè)大小向量n_samples以及參數(shù)的預(yù)測(cè)X。我還做了一個(gè)score()功能如下:def score(self, X, y):
scr_pred = self.predict(X)
return sum(scr_pred == y) / X.shape[0]該方法只是計(jì)算給定樣本的模型的準(zhǔn)確性。如果我使用此score()方法或設(shè)置 across_val_score(... , scoring="accuracy")它不起作用。
1 回答

有只小跳蛙
TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個(gè)贊
然而,您的問題陳述在這里并不清楚,但是查看錯(cuò)誤,您似乎正在嘗試多類分類。
這里的問題是,您的代碼中可能在某些時(shí)候沒有正確完成預(yù)處理,因?yàn)殄e(cuò)誤是從 inverse_binarize_thresholding 記錄的,這是由于 sklearn 預(yù)處理的以下功能而引發(fā)的:
def?_inverse_binarize_thresholding(y,?output_type,?classes,?threshold):??? ????if?output_type?==?"binary"?and?y.ndim?==?2?and?y.shape[1]?>?2:? ???????????raise?ValueError("output_type='binary',?but?y.shape?=?{0}".? ???????????????????????????????????format(y.shape))
您的代碼中必須缺少一些轉(zhuǎn)換或預(yù)處理,并且您必須正確使用 LabelBinarizer
添加回答
舉報(bào)
0/150
提交
取消