gpt4 book ai didi

python - 获取错误 : KeyError: 'Only the Series name can be used for the key in Series dtype mappings.' when trying to do pandas Smote algorithm

转载 作者:行者123 更新时间:2023-12-04 14:35:20 31 4
gpt4 key购买 nike

我的数据有点不平衡,所以我在做逻辑回归模型之前尝试做一个 SMOTE 算法。当我这样做时,我收到错误: KeyError: 'Only the Series name can be used for the key in Series dtype mappings.'有人可以帮我弄清楚原因吗?
这是代码:

X = dummies.loc[:, dummies.columns != 'Count']
y = dummies.loc[:, dummies.columns == 'Count']
#from imblearn.over_sampling import SMOTE
os = SMOTE(random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
columns = X_train.columns
os_data_X,os_data_y=os.fit_sample(X_train, y_train) # here is where it errors
os_data_X = pd.DataFrame(data=os_data_X,columns=columns )
os_data_y= pd.DataFrame(data=os_data_y,columns=['Count'])
谢谢!

最佳答案

我自己刚刚遇到了这个问题。事实证明,我的数据集中有一个重复的列。也许仔细检查您的数据集不是这种情况。

关于python - 获取错误 : KeyError: 'Only the Series name can be used for the key in Series dtype mappings.' when trying to do pandas Smote algorithm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65311823/

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