gpt4 book ai didi

python - 名称错误 : name 'tree' is not defined

转载 作者:行者123 更新时间:2023-12-04 12:07:42 25 4
gpt4 key购买 nike

嘿,我是 Python 新手,我正在尝试按照教程进行操作,但出现此错误:

NameError: name 'tree' is not defined.



目标显然是让程序根据输入的特征来确定水果是苹果还是橙子。我在 Win 10 上使用 Python 3.6 和 spyder 编辑器。我确定这很简单,感谢您的帮助!
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

# features = [[140, "smooth"], [130, "smooth"], [150, "bumpy"], [170, "bumpy"]]
# labels = ["apple", "apple", "orange", "orange"]
features = [[140, 1], [130, 1], [150, 0], [170, 0]]
labels = [0, 0, 1, 1]
# We build a "Decision Tree" yes/no -> yes/no
# clf means classifier
clf = tree.DecisionTreeClassifier()
# Think of "fit" as "find patters in data"
clf = clf.fit(features, labels)
print (clf.predict([[160, 0]]))

最佳答案

将此添加到代码的顶部:

from sklearn import tree

这是假设您正在学习机器学习。

关于python - 名称错误 : name 'tree' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42979156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com