Create multiple classes from continuous variables Python

断了今生、忘了曾经 提交于 2019-12-11 11:35:31

问题


I would like to convert my continuous predictor variable (stock returns) into a categorical variable (5 bins, either 5 bins with equal number of stocks OR absolute thresholds, say -30% to -20%, then -19% to -10% etc.)

Is there some Python package that does this? scikit learn etc?


回答1:


It seems like what you are looking for is either pandas.cut for absolute thresholds or pandas.qcut for equal sized bins.




回答2:


numpy.histogram is also a useful option for discretizing stuff



来源:https://stackoverflow.com/questions/52433738/create-multiple-classes-from-continuous-variables-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!