【发布时间】:2016-05-08 00:04:30
【问题描述】:
这是我第一次使用 Scikit,如果问题很愚蠢,我深表歉意。我正在尝试在 UCI 的蘑菇数据集上实现一个朴素贝叶斯分类器,以针对我自己从头开始编码的 NB 分类器测试结果。
数据集是分类的,每个特征都有超过 2 个可能的属性,所以我使用多项式 NB 而不是高斯或伯努利 NB。
但是,我不断收到以下错误 ValueError: could not convert string to float: 'l' ,不知道该怎么办。多项式NB不应该可以取字符串数据吗?
Example line of data - 0th column is the class (p for poisonous and e for edible) and the remaining 22 columns are the features.
p,x,s,n,t,p,f,c,n,k,e,e,s,s,w,w,p,w,o,p,k,s,u
# based off UCI's mushroom dataset http://archive.ics.uci.edu/ml/datasets/Mushroom
df = pd.DataFrame(data)
msk = np.random.rand(df.shape[0]) <= training_percent
train = data[msk]
test = data[~msk]
clf = MultinomialNB()
clf.fit(train.iloc[:, 1:], train.iloc[:, 0])
【问题讨论】:
标签: python machine-learning scikit-learn