2017-10-05 98 views
0

我正在爲二元分類問題構建一個隨機森林分類器。我的標籤都是數字。ValueError:未知標籤類型:'unknown' - 標籤是數字

print labels.unique() 
[1 0] 

print type(labels) 
    <class 'pandas.core.series.Series'> 
print labels.shape 
(3000,) 

但是,當我在擬合模型Gridsearchcv

pipeline = Pipeline(steps=[('scaler', scaler), ('algorithm', algo)]) 
cv = StratifiedShuffleSplit(labels, 5, test_size=0.25, random_state=42) 
gs = GridSearchCV(pipeline, param_grid, cv=cv, scoring='f1') 
gs.fit(features, labels) 

我收到此錯誤

ValueError: Unknown label type: 'unknown' 

但是當我使用

gs.fit(features, labels.astype(int)) 

它工作正常有人讓我知道謊言在哪裏是我標籤中的問題嗎?

回答

1

您只需要使用tolist()方法將標籤的類型更改爲列表。使用

labels_lst = labels.tolist() 

Scikit-learn無法將系列自動轉換爲標籤列表。