在Python中将偏移合并到sklearn Poisson决策树回归中?

2024-06-25 23:30:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究如何最好地在Python中重现类似于此R代码的内容:

library(rpart) # "Recursive partitioning for classification, regression and survival trees". Default metric: Gini impurity
tree <- rpart(cbind(Exposure,ClaimNb) ~ Area + VehPower + VehAge + DrivAge 
              + BonusMalus + VehBrand + VehGas + Density + Region, dat, 
              method="poisson", control=rpart.control(maxdepth=3,cp=0.001))      
#            complexity-parameter cp is used to control the number of splits

资料来源:https://www.kaggle.com/floser/glm-neural-nets-and-xgboost-for-insurance-pricing/comments

是否有一种优雅的方式将偏移(在本例中为曝光)合并到决策树累加器中?还是我要用我的响应变量除以偏移量

另一方面,链接中的决策树图形非常好,似乎很难在Python中重现。首先,sklearn决策树似乎无法处理分类变量,除非对它们进行热编码,我还没有弄清楚如何让变量名在决策树中很好地显示出来


Tags: and代码决策树内容forlibrarycptrees