【问题标题】:program is not working "TypeError: fit() missing 1 required positional argument: 'y'"程序不工作“TypeError:fit()缺少1个必需的位置参数:'y'”
【发布时间】:2018-05-20 13:26:47
【问题描述】:
from sklearn import tree
from sklearn.datasets import load_iris
iris=load_iris()
dir(iris)
#output data to traixn setosa,versicolor and virginica
x=iris.data
#fetching data
x=np.delete(x, np.s_[::50], 0)
#print(x)
y=iris.target
#featching output
y=np.delete(y, np.s_[::50], 0)
algo=tree.DecisionTreeClassifier

当我尝试使用 fit 时它不支持

train=algo.fit(x,y)
res=train.pridict([test_setosa])
print(res)

【问题讨论】:

    标签: python-3.x scikit-learn jupyter-notebook


    【解决方案1】:

    您需要更改代码中的某些内容。 DecisionTreeClassifier 是一个类,您在代码中调用它的方式是错误的。

    替换

    algo=tree.DecisionTreeClassifier
    

    algo=tree.DecisionTreeClassifier()
    

    完整代码

    from sklearn import tree
    from sklearn.datasets import load_iris
    import numpy as np
    
    iris=load_iris()
    dir(iris)
    #output data to traixn setosa,versicolor and virginica
    x=iris.data
    #fetching data
    x=np.delete(x, np.s_[::50], 0)
    #print(x)
    y=iris.target
    #featching output
    y=np.delete(y, np.s_[::50], 0)
    
    algo=tree.DecisionTreeClassifier()
    
    train=algo.fit(x,y)
    res=train.predict([test_setosa])
    

    【讨论】:

    • 谢谢..这是我的代码中唯一缺少的东西
    猜你喜欢
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    • 2020-11-15
    • 2017-05-28
    • 2020-01-06
    • 2021-10-19
    相关资源
    最近更新 更多