Gower Distance Model for Case-Based-Reasoning
Gower Distance Model for Case-Based-Reasoning
Details
A model-free case base: the distance between cases is the Gower distance
(gower_distance) of the variables on the right-hand side of
the formula, optionally weighted. The endpoint (left-hand side) is not used
for the distance, but for predict_outcome(),
predict_survival(), evaluate() and counterfactual cases. Use it
as a baseline for the model-derived distances of the other models, or with
expert-defined weights.
Ranges of numeric variables are taken from the training cases, so that distances of query cases do not depend on each other.
References
Gower, J. C. (1971). A general coefficient of similarity and some of its properties. Biometrics, 27(4), 857–871. doi:10.2307/2528823
Super class
CaseBasedReasoning::CBRBase -> GowerModel
Methods
Inherited methods
CaseBasedReasoning::CBRBase$add_cases()CaseBasedReasoning::CBRBase$assess_cases()CaseBasedReasoning::CBRBase$calc_distance_matrix()CaseBasedReasoning::CBRBase$evaluate()CaseBasedReasoning::CBRBase$evaluate_survival()CaseBasedReasoning::CBRBase$explain_match()CaseBasedReasoning::CBRBase$get_case_base()CaseBasedReasoning::CBRBase$get_counterfactual_cases()CaseBasedReasoning::CBRBase$get_similar_cases()CaseBasedReasoning::CBRBase$predict_outcome()CaseBasedReasoning::CBRBase$predict_survival()CaseBasedReasoning::CBRBase$remove_cases()
Method new()
Initialize a Gower distance model.
Usage
GowerModel$new(formula, data, weights = NULL)Arguments
formulaObject of class formula or character, e.g.
y ~ .orSurv(time, status) ~ x1 + x2.dataTraining data of class data.frame
weightsvariable weights, see
gower_distance
Examples
m <- GowerModel$new(Species ~ ., iris[-(1:3), ])
m$fit()
m$get_similar_cases(iris[1:3, ], k = 2)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species scDist caseId
#> 18 5.1 3.5 1.4 0.3 setosa 0.01041667 1
#> 28 5.2 3.5 1.5 0.2 setosa 0.01118173 2
#> 35 4.9 3.1 1.5 0.2 setosa 0.01465395 1
#> 26 5.0 3.0 1.6 0.2 setosa 0.01541902 2
#> 48 4.6 3.2 1.4 0.2 setosa 0.01118173 1
#> 30 4.7 3.2 1.6 0.2 setosa 0.01271186 2
m$predict_outcome(iris[1:3, ], k = 5)
#> prediction prob_setosa prob_versicolor prob_virginica
#> 1 setosa 1 0 0
#> 2 setosa 1 0 0
#> 3 setosa 1 0 0