Get Coefficients of a Model
get_model_coef-libml.RdExtract the coefficients for an arbitrary model.
Usage
# S3 method for class 'glm'
get_model_coef(model, ...)
# S3 method for class 'lm'
get_model_coef(model, ...)
# S3 method for class 'lda'
get_model_coef(model, ...)
# S3 method for class 'libml_nb'
get_model_coef(model, ...)
# S3 method for class 'naiveBayes'
get_model_coef(model, ...)
# S3 method for class 'kknn'
get_model_coef(model, ...)
# S3 method for class 'randomForest'
get_model_coef(model, ...)
# S3 method for class 'gbm'
get_model_coef(model, ...)
# S3 method for class 'glmnet'
get_model_coef(model, lambda = NULL, ...)
# S3 method for class 'cv.glmnet'
get_model_coef(model, lambda = NULL, ...)
# S3 method for class 'train'
get_model_coef(model, lambda = NULL, ...)
# S3 method for class 'svm'
get_model_coef(model, ...)Arguments
- model
A model object, currently one of:
#> [1] get_model_coef.cv.glmnet #> [2] get_model_coef.default* #> [3] get_model_coef.gbm #> [4] get_model_coef.glm #> [5] get_model_coef.glmnet #> [6] get_model_coef.kknn #> [7] get_model_coef.lda #> [8] get_model_coef.libml_nb #> [9] get_model_coef.lm #> [10] get_model_coef.naiveBayes #> [11] get_model_coef.randomForest #> [12] get_model_coef.svm #> [13] get_model_coef.train #> see '?methods' for accessing help and source code- ...
Additional parameters for extensibility.
- lambda
The value of the penalty parameter
lambdawhich can either beNULLornumeric. IfNULL, the default value depends on the underlying class:glmnetThe first value of lambda.
cv.glmnetThe lambda where the cross validated error is minimized.
trainThe optimal value of lambda. When given a numeric value of
lambda, the closest value oflambdawithin the model will be used.
Value
A named numeric vector of the coefficients of the model.
If the model is non-linear (e.g. random forest), NULL.
Functions
get_model_coef(glm): S3 method forglmmodels.get_model_coef(lm): S3 method forlmmodels.get_model_coef(lda): S3 method forldamodels.get_model_coef(libml_nb): S3 method forlibml_nbmodels.get_model_coef(naiveBayes): S3 method fornaiveBayesmodels.get_model_coef(kknn): S3 method forkknnmodels.get_model_coef(randomForest): S3 method forrandomForestmodels.get_model_coef(gbm): S3 method forgbmmodels.get_model_coef(glmnet): S3 method forglmnetmodels.get_model_coef(cv.glmnet): S3 method forcv.glmnetmodels.get_model_coef(train): S3 method fortrainmodels.get_model_coef(svm): S3 method for SVM models. If the modelkernel = linear, coefficients are returned. Otherwise,NULL.
Examples
# set up training and test data:
iris2 <- droplevels(iris[iris$Species != "setosa", ])
# Logistic Regression
stats::glm(Species ~ ., data = iris2, family = "binomial") |>
get_model_coef()
#> (Intercept) Sepal.Length Sepal.Width Petal.Length Petal.Width
#> -42.637804 -2.465220 -6.680887 9.429385 18.286137