arid_logreg.Rd
Given a matrix X of explanatory variables, a response y numeric variable, this function fits either a 'binomial' or 'multinomial' logistic regression model and returns a class object similar to sci-kit learn's object
arid_logreg(X, y, regularization = NULL, lambda = NULL)
X | (data frame): the explanatory variables matrix |
---|---|
y | (numeric): the response variable numeric vector |
regularization | (character): what level of regularization to use in the model (default NULL) |
lambda | (double): the regularization strength parameter to use (default: NULL) |
arid_logreg: a class object after fitting a 'binomial' or 'multinomial' logistic regression model
#> $thisEnv #> <environment: 0x000000004c316798> #> #> $fit #> function (X, y) #> { #> model <- NULL #> regularization <- regularization_ #> lambda <- lambda_ #> if (is.null(regularization)) { #> lambda <- 0 #> model <- glmnet::glmnet(X, y, family = family, alpha = 1, #> lambda = lambda) #> } #> else if (regularization == c("L1")) { #> model <- glmnet::glmnet(X, y, alpha = 1, family = family) #> } #> else if (regularization == c("L2")) { #> model <- glmnet::glmnet(X, y, alpha = 0, family = family) #> } #> else if (regularization == c("L1L2")) { #> model <- glmnet::glmnet(X, y, alpha = 0.5, family = family) #> } #> coefs <- get_coefs(X, y, model, lambda) #> set_coefs(coefs) #> return(model) #> } #> <bytecode: 0x000000004c308ac0> #> <environment: 0x000000004c316798> #> #> $predict #> function (newx) #> { #> if (family == "binomial") { #> prob <- glmnet::predict.glmnet(model_, s = lambda_, newx = newx, #> type = "response") #> pred <- ifelse(prob > 0.5, 1, 0) #> return(pred) #> } #> else { #> return("Only predictions for binomial logistic regression are available") #> } #> } #> <bytecode: 0x000000004c311360> #> <environment: 0x000000004c316798> #> #> $score #> function () #> { #> model_$dev.ratio #> } #> <bytecode: 0x000000004c310870> #> <environment: 0x000000004c316798> #> #> $intercept_ #> [1] 0.004002721 #> #> $coef_ #> [1] -0.4014806 -0.5452708 0.0649694 #> #> attr(,"class") #> [1] "arid_logreg"