【发布时间】:2017-04-07 19:51:02
【问题描述】:
我写了以下代码:
from sklearn import tree
# Dataset & labels
# Using metric units
# features = [height, weight, style]
styles = ['modern', 'classic']
features = [[1.65, 65, 1],
[1.55, 50, 1],
[1.76, 64, 0],
[1.68, 77, 0] ]
labels = ['Yellow dress', 'Red dress', 'Blue dress', 'Green dress']
# Decision Tree
clf = tree.DecisionTreeClassifier()
clf = clf.fit(features, labels)
# Returns the dress
height = input('Height: ')
weight = input('Weight: ')
style = input('Modern [0] or Classic [1]: ')
print(clf.predict([[height,weight,style]]))
此代码接收用户的身高和体重,然后返回更适合她的衣服。有没有办法返回多个选项?例如,退回两件或更多件衣服。
更新
from sklearn import tree
import numpy as np
# Dataset & labels
# features = [height, weight, style]
# styles = ['modern', 'classic']
features = [[1.65, 65, 1],
[1.55, 50, 1],
[1.76, 64, 1],
[1.72, 68, 0],
[1.73, 68, 0],
[1.68, 77, 0]]
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 [0] or Classic [1]: ')
print(clf.predict_proba([[height,weight,style]]))
如果用户是 1.72m 和 68kg,我想同时展示绿色和紫色的连衣裙。此示例仅返回 100% 的绿色连衣裙。
【问题讨论】:
-
什么时候返回多个?您的意思是按最可能的顺序退回它们吗?
标签: python python-3.x scikit-learn