2017-10-05 97 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无法将系列自动转换为标签列表。