我正在运行多标签分类1的[代码]。如何修复未定义“X_train”的NameError。Python代码如下所示。
import scipy
from scipy.io import arff
data, meta = scipy.io.arff.loadarff('./yeast/yeast-train.arff')
from sklearn.datasets import make_multilabel_classification
# this will generate a random multi-label dataset
X, y = make_multilabel_classification(sparse = True, n_labels = 20,
return_indicator = 'sparse', allow_unlabeled = False)
# using binary relevance
from skmultilearn.problem_transform import BinaryRelevance
from sklearn.naive_bayes import GaussianNB
# initialize binary relevance multi-label classifier
# with a gaussian naive bayes base classifier
classifier = BinaryRelevance(GaussianNB())
# train
classifier.fit(X_train, y_train)
# predict
predictions = classifier.predict(X_test)
from sklearn.metrics import accuracy_score
accuracy_score(y_test,predictions)
2条答案
按热度按时间rxztt3cl1#
您忘记将数据集拆分为训练集和测试集。
导入库
在www.example.com()之前添加此行classifier.fit
mm9b1k5b2#
从sklearn.预处理导入标准缩放器s =标准缩放器()
x_训练=s.fit_转换(X_训练)x_测试= s.拟合_转换(X_测试)