
Case Based Reasoning using Statistical Models
The R package CaseBasedReasoning implements case-based reasoning with statistical and machine learning models: it learns a distance between cases from a fitted regression model or random forest, retrieves the most similar past cases, predicts outcomes (including survival curves) from them, and explains why cases match.
Introduction: What is Case Based Reasoning?
Case-Based Reasoning (CBR) is an artificial intelligence (AI) and problem-solving methodology that leverages the knowledge and experience gained from previously encountered situations, known as cases, to address new and complex problems. CBR relies on the principle that similar problems often have similar solutions, and it focuses on identifying, adapting, and reusing those solutions to solve new problems.
The CBR process consists of four main steps:
-
Retrieve: In this step, the system searches its case database to identify the most similar cases to the current problem. It uses similarity measures and pattern matching techniques to compare the features of the new problem with the existing cases.
-
Reuse: Once the relevant cases are retrieved, the system adapts the solutions from those cases to fit the new problem. This may involve combining multiple solutions, adjusting parameters, or modifying the solution to accommodate any differences between the old and new cases.
-
Revise: After the adapted solution has been applied to the new problem, the system evaluates the outcome to determine its effectiveness. If necessary, the solution is further revised and optimized to better suit the specific context of the problem.
-
Retain: Finally, the new problem and its corresponding solution are added to the case database for future reference. This step enhances the system's knowledge base and improves its ability to solve similar problems in the future.
CBR has been successfully applied in various domains, including medical diagnosis, legal reasoning, customer support, and design optimization. Its ability to learn from experience and adapt to new situations makes it a valuable approach in fields where expertise and problem-solving skills are crucial.
How This Package Implements CBR
The central challenge in CBR is defining what "similar" means. This package solves the Retrieve step by learning a distance function from data rather than relying on ad-hoc similarity measures.
The workflow follows three stages:
- Fit a statistical model to the training data. The model captures which variables matter and how strongly they influence the outcome.
- Derive a distance function from the fitted model. The model's structure determines how distance between cases is measured.
- Retrieve the k nearest cases for each new query observation using the learned distance.
The package offers two families of models for this:
Regression-based distance (Cox, linear, logistic)
A regression model (Cox proportional hazards, OLS, or logistic regression via the rms package) is fitted on the training data. The estimated regression coefficients are then used as weights in a weighted absolute distance function. Variables with larger coefficients contribute more to the distance, while variables the model deems irrelevant contribute little. This follows the approach of Dippon et al. (2002).
Distances are computed in contribution space: for each model term t, the contribution to the linear predictor, c_t(x) = X_t(x) %*% beta_t, is compared between two cases, and the absolute differences are summed. For main effects this is exactly the weighted distance above; it also covers any other rms term, such as splines (rcs(age, 4)), polynomials and interactions.
Random Forest distance (proximity and depth)