【发布时间】:2018-11-06 15:30:15
【问题描述】:
下面是我的代码:
import sklearn
#features = [[140,"smooth"],[130,"smooth"],[150,"bumpy"],[170,"bumpy"]]
#labels = ["apple","apple","orange","orange"]
# Now replace 1 for smooth & 0 for bumpy and 0 for apple & 1 for orange
features = [[140,1],[130,1],[150,0],[170,0]]
labels = [0,0,1,1]
# Now I train a classifier
from sklearn import tree
my_classifier = tree.DecisionTreeClassifier()
my_classifier.fit(features,labels)
predict = my_classifier.predict([[150,0]])
print(predict)
如何训练分类器而不将其转换为数字?
例如我想要下面的代码行来对我的分类器进行分类。请建议,提前谢谢:)
features = [[140,"smooth"],[130,"smooth"],[150,"bumpy"],[170,"bumpy"]]
labels = ["apple","apple","orange","orange"]
【问题讨论】:
-
教程中说过。但是您可以使用任何类型作为标签或特征。
-
对于不需要转换的目标(标签),它将由 scikit 处理。但是对于您需要转换的功能
-
我删除了“...in supervised learning”,因为那是多余的。我将“字符串标签和特征”重新命名为“字符串标签和特征”,因为它们是不同的东西,它们的处理方式不同,无论是算法还是 sklearn 中的编码(取决于分类器的类型:基于树的、NN 等)。 (此外,字符串特征通常需要规范化,字符串标签不需要。)
-
已经有124 questions for classifier string features,主要是Python。哪一个应该是规范的?
标签: python machine-learning artificial-intelligence classification decision-tree