I have this data on houses from the Kaggle practice competition and I'm using rpart to train a simple first model to predict the sale price.
The model is not correctly identifying sales where the sale condition was abnormal or a down payment. Therefore, I'd like to increase the importance of this variable which is obviously overlooked in the model.
I'm assuming this is done by using the "weights" parameter but how is this parameter used? How can I pinpoint which variables I want to have a higher weight?
From the documentation:
weights
optional case weights.
cost
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.
The weights is for rows (e.g. give higher weight to smaller class), the cost is for columns.
Example usage for applying the weights parameter (not necessarily the best way to define the weights):
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)
来源:https://stackoverflow.com/questions/43452106/how-to-apply-weights-in-rpart