如何在这个初学者Python AI代码中修复语法错误?

问题描述 投票:-2回答:2

让初学者Ai将苹果与橙子从重量和质地区分开来,它在标签上带有语法错误以下是代码:

from sklearn import tree

## In Features 1 = Smooth, 0 = Bumpy

features = [[140, 1], [130, 1], [150, 0], [170, 0]
labels = ["apple", "apple", "orange", "orange"]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(features, labels)
print clf.predict([[150, 0]])
python python-2.7 artificial-intelligence
2个回答
0
投票

你错过了一个]

from sklearn import tree

    ## In Features 1 = Smooth, 0 = Bumpy

    features = [[140, 1], [130, 1], [150, 0], [170, 0]] # missed an ] here
    labels = ["apple", "apple", "orange", "orange"]
    clf = tree.DecisionTreeClassifier()
    clf = clf.fit(features, labels)
    print clf.predict([[150, 0]])

0
投票

运行Python脚本时出现的错误是什么?

例如:

>>> x = [ ["x", y"]

给我:

SyntaxError: EOL while scanning string literal

甚至指向它失败的线。你有没有尝试谷歌搜索?我觉得你正在努力学习一些关于人工智能的东西,但是用一种语言你仍然是新来的。

© www.soinside.com 2019 - 2024. All rights reserved.