gpt4 book ai didi

r - 如何在rpart中应用权重?

转载 作者:行者123 更新时间:2023-12-03 23:18:28 26 4
gpt4 key购买 nike

我有来自 Kaggle 实践比赛的房屋数据,我正在使用 rpart 训练一个简单的第一个模型来预测销售价格。

该模型未正确识别销售条件异常或预付定金的销售。因此,我想增加这个在模型中明显被忽略的变量的重要性。

我假设这是通过使用“权重”参数来完成的,但是这个参数是如何使用的?如何确定哪些变量需要更高的权重?

最佳答案

来自 documentation :

重量

optional case weights.



费用

a vector of non-negative costs, one for each variable in the model. Defaults to one for all variables. These are scalings to be applied when considering splits, so the improvement on splitting on a variable is divided by its cost in deciding which split to choose.



权重是针对行的(例如,给较小的类赋予更高的权重),成本是针对列的。

应用权重参数的示例用法
(不一定是定义权重的最佳方式):
positiveWeight = 1.0 / (nrow(subset(training, Y == TRUE)) / nrow(training))
negativeWeight = 1.0 / (nrow(subset(training, Y != TRUE)) / nrow(training))

modelWeights <- ifelse(training$Y== TRUE, positiveWeight, negativeWeight)

dtreeModel <- rpart(predFormula, training, weights = modelWeights)

关于r - 如何在rpart中应用权重?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43452106/

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