gpt4 book ai didi

Python 机器学习警告

转载 作者:行者123 更新时间:2023-11-30 22:57:01 24 4
gpt4 key购买 nike

我正在使用以下 python 程序来实现基本的决策树分类器。

from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
import numpy as np

features = [[140,1],[130,1],[150,0],[170,0]]
labels = [0,0,1,1]

clf = DecisionTreeClassifier()
model = clf.fit(features, labels)
a = model.predict ([160,0])
print (a)

它打印出预测值,但给出警告,

DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and   
willraise ValueError in 0.19. Reshape your data either using X.reshape(-1,
1) if your data has a single feature or X.reshape(1, -1) if it contains a
single sample.

我尝试用这个来修复它,

features = np.array(features).reshape(-1, 2)
labels = np.array(labels).reshape(-1, 1)

但这显示了相同的警告。有什么建议吗?

最佳答案

问题出在 model.predict 上。这有效:
a = model.predict([[160,0]])

关于Python 机器学习警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36852103/

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