Sklearn通过str&int预测多个输出

时间:2018-11-08 15:28:25

标签: python scikit-learn

使用此代码,出现错误!

import re
import sklearn
from sklearn import tree
from sklearn import preprocessing
from sklearn.preprocessing import OrdinalEncoder

from sklearn import tree
import numpy as np

# Dataset & labels
# features = [height, weight, style]
# styles = ['modern', 'classic']
features = [['1.65', '65', 'm'], 
            ['1.55', '50', 'm'],
            ['1.76', '64', 'm'],
            ['1.72', '68', 'c'],
            ['1.73', '68', 'c'],
            ['1.68', '77', 'c']]
labels =    ['Yellow dress',
            'Red dress',
            'Blue dress',
            'Green dress',
            'Purple dress',
            'Orange dress']

# Decision Tree
clf = tree.DecisionTreeClassifier()
clf = clf.fit(features, labels)

# Returns the dress
height = input('Height: ')
weight = input('Weight: ')
style = input('Modern [m] or Classic [c]: ')

print(clf.predict([[height,weight,style]]))

错误:

return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: 'm'

此错误与类型不同的数据有关,如何解决?

谢谢!

0 个答案:

没有答案