如何修复此初学者Python AI代码中的语法错误?

时间:2019-04-11 22:26:12

标签: python python-2.7 artificial-intelligence

让初学者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]])

2 个答案:

答案 0 :(得分: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]])

答案 1 :(得分:0)

运行Python脚本时遇到什么错误?

例如:

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

给我:

SyntaxError: EOL while scanning string literal

甚至指向失败的行。您尝试使用Google搜索吗?我觉得您正在尝试学习有关AI的知识,但是用一种新的语言来学习。