Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toad.selection执行逐步回归方法时报错:ValueError: at least one array or dtype is required #121

Open
liuyin66670 opened this issue Mar 30, 2023 · 1 comment

Comments

@liuyin66670
Copy link

y = 'TARGET'
train_data = [
{'TARGET': 0, 'FEATURE1': -0.223144, 'FEATURE2': -0.223144, 'FEATURE3': -1.609438},
{'TARGET': 1, 'FEATURE1': -1.609438, 'FEATURE2': -0.223144, 'FEATURE3': -0.223144},
{'TARGET': 1, 'FEATURE1': -0.223144, 'FEATURE2': -0.223144, 'FEATURE3': -0.223144},
{'TARGET': 1, 'FEATURE1': -0.223144, 'FEATURE2': -0.223144, 'FEATURE3': -0.223144},
{'TARGET': 1, 'FEATURE1': -0.223144, 'FEATURE2': -1.609438, 'FEATURE3': -0.223144},
{'TARGET': 1, 'FEATURE1': -0.223144, 'FEATURE2': -0.223144, 'FEATURE3': -1.609438}
]
train_woe = pd.DataFrame(train_data)
final_train_data = toad.selection.stepwise(train_woe,target=y,estimator='lasso',max_iter=100,criterion='aic',direction='backward',exclude=to_drop,return_drop=False)
---------------------------- 代码如上,其中train_data为训练集经WOE转化后的数据 -------------------------------

执行逐步回归方法时,调用了selection.py里的stepwise方法,报错:ValueError: at least one array or dtype is required,按如下方式修改toad.selection.py里stepwise方法,可解决以上问题

    if direction == 'backward':
        if l <= 1:            --增加
            break             --增加
        for i in range(l):
            print(remaining)
            print(df[ remaining[:i] + remaining[i+1:] ])

请帮忙确认这样修改是否会影响到其他地方,是否是最优解决方案,感谢

系统:win10 64位
python版本:3.7
toad版本: 0.1.1

@Secbone
Copy link
Member

Secbone commented Dec 12, 2023

@liuyin66670 非常赞!感谢你发现的问题,如果你愿意的话,可以提交PR来贡献这部分代码。 如果没有时间的话,也没有关系,请告知我,我会在下个版本修复这个问题! 👍

这个问题确实是在 backward 的过程中,如果只剩下一个特征时,应该跳出循环,之前确实没有考虑到只筛剩下一个的情况 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants