TypeError:“ numpy.int32”对象不可迭代-使用sklearn_crfsuite时出错

时间:2019-05-24 03:25:47

标签: python crfsuite

crf.fit(X_train,y_train)无法运行,并显示上述错误。此外,当我运行labels2 = list(crf.classes_)时,我得到NoneType对象是不可迭代的。我以前没有使用过crfsuite,也无法在线找到令人满意的信息。

需要注意的事情:csv文件没有NO类型,是一个简单的数据集,仅由数字(包括标签)组成,最后一列是标签。使用CRF,因为它是一个多标签顺序问题。

data = np.genfromtxt("training.csv", delimiter = ',', skip_header = 1)
data = data.astype(int, order='K', casting='unsafe', subok=True, 
copy=True)
labels = data[:,6]
features = data[:,0:6]
X_train,X_test,y_train,y_test = 
train_test_split(features,labels,test_size=0.3,random_state=1)

features = np.asmatrix(features)

X_train = [features[i] for i in X_train]
y_train = [labels[i] for i in y_train]

X_test = [X_test[i] for i in X_test]
y_test = [y_test[i] for i in y_test]
crf = sklearn_crfsuite.CRF(algorithm='lbfgs',c1=0.1,c2=0.1,max_iterations=100,all_possible_transitions=True)
crf.fit(X_train, y_train)

labels2 = list(crf.classes_)
y_pred = crf.predict(X_test)
metrics.flat_f1_score(y_test, y_pred,average='weighted', labels=labels2)

我希望最终的代码能使我获得F1分数,但我无法通过培训:/

0 个答案:

没有答案