Train a regression model and create a lime
object that uses a linear simple model. When you create a lime
object, if you do not specify a query point and the number of important predictors, then the software generates samples of a synthetic data set but does not fit a simple model. Use the object function fit
to fit a simple model for a query point. Then display the coefficients of the fitted linear simple model by using the object function plot
.
Load the carbig
data set, which contains measurements of cars made in the 1970s and early 1980s..
Create a table containing the predictor variables Acceleration
, Cylinders
, and so on, as well as the response variable MPG
.
Removing missing values in a training set can help reduce memory consumption and speed up training for the fitrkernel
function. Remove missing values in tbl
.
Create a table of predictor variables by removing the response variable from tbl
.
Train a blackbox model of MPG
by using the fitrkernel
function, and create a lime
object. Specify a predictor data set because mdl
does not contain predictor data. Your results might vary from those shown because of randomness of fitrkernel
and lime
. You can set a random seed by using rng
for reproducibility.
results =
lime with properties:
BlackboxModel: [1×1 RegressionKernel]
DataLocality: 'global'
CategoricalPredictors: [2 5]
Type: 'regression'
X: [392×6 table]
QueryPoint: []
NumImportantPredictors: []
NumSyntheticData: 5000
SyntheticData: [5000×6 table]
Fitted: [5000×1 double]
SimpleModel: []
ImportantPredictors: []
BlackboxFitted: []
SimpleModelFitted: []
results
contains the generated synthetic data set. The SimpleModel
property is empty ([]
).
Fit a linear simple model for the first observation in tblX
. Specify the number of important predictors to find as 3.
queryPoint=1×6 table
Acceleration Cylinders Displacement Horsepower Model_Year Weight
____________ _________ ____________ __________ __________ ______
12 8 307 130 70 3504
Plot the lime
object results
by using the object function plot
. To display an existing underscore in any predictor name, change the TickLabelInterpreter
value of the axes to 'none'
.
The plot displays two predictions for the query point, which correspond to the BlackboxFitted property and the SimpleModelFitted property of results
.
The horizontal bar graph shows the coefficient values of the simple model, sorted by their absolute values. LIME finds Horsepower
, Model_Year
, and Cylinders
as important predictors for the query point.