gpt4 book ai didi

python - 机器学习: UserWarning: Pandas doesn't allow columns to be created via a new attribute name

转载 作者:行者123 更新时间:2023-11-30 09:30:38 27 4
gpt4 key购买 nike

i am new in the machine learning. when i run the code basically icoped the code from the teacher's note. but i got some "userwarning"

using single csv file for performing decision tree

data = pd.read_csv("H:\spyder python program\data_file\iris_data.csv")

data.features = data[["SepalLength", "SepalWidth", "PetalLength", "PetalWidth"]]
data.targets = data.Class


这是警告显示的地方

输出

 UserWarning: Pandas doesn't allow columns to be created via a new attribute name 
data.features = data[["SepalLength", "SepalWidth", "PetalLength", "PetalWidth"]]

最佳答案

Pandas“认为”您正在尝试创建名为“features”和“targets”的新列。你不能这样做,你应该使用 data['features'] = ... 语法。但目前尚不清楚您总体上想做什么。你应该做这样的事情:

X = data[["SepalLength", "SepalWidth", "PetalLength", "PetalWidth"]]
y = data['Class']
model.fit(X, y)

关于python - 机器学习: UserWarning: Pandas doesn't allow columns to be created via a new attribute name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59480416/

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