fit: Fit model to train data

Description Usage Arguments Details Value Author(s) Examples

View source: R/fit.R

Description

Logistic regression on train data (classication)

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
fit(
  formule,
  data,
  mode = "mini_batch",
  batch_size = 32,
  alpha = 0.01,
  max_iter = 500,
  tol = 0.001,
  ncores = NA,
  parallel = FALSE,
  plot = FALSE,
  lambda = 0,
  beta = 1
)

Arguments

formule

an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. The details of model specification are given under ‘Details’

data

a dataframe containing the variables in the model.

mode

parameter is the way you feed your data to the model ( online, mini-batch or batch). The mode is set to mini-batch by default.

batch_size

the batch size when mode is mini-batch

alpha

the learning rate in gradient descent

max_iter

maximum number of iteration

tol

tolerance for accepting a model :

ncores

indicates the number of cores to use; if invalid (<= 0 or> number of cores available), the maximum capacities of the host machine are used

parallel

logical.Should we use parallel computing ? specifies whether you want to perform a parallel or a sequential computing. The default value is set to False ( meaning it's sequential). Note that parallel computing is not performed in the case of online gradient descent.

plot

logical. Should we plot the cost function while iterating ?

lambda

parameter is set to zero by default if no regularization is applied to the model. You may want to modify this value if your model is overfitting.

beta

beta parameter which takes only two values (beta = 1 by default: ridge regularization case) beta = 0 lasso case

Details

Function that trains your model via gradient descent and outputs the model weights. This function comes with a bunch of parameters.

Value

An object S3 of class Reg.Log md$coeffs : Coefficients ( model weights) md$nb_iter: Number of epochs md$cost: cost function values at each epoch md$mean_col= mean value of each feature md$sd: Standard deviation value of each feature

Author(s)

Marie Vachet, Afaf Ben Haj, Sami Ait Tilat

Examples

1
2
3
4
## Not run: 
modele = fit_grad(formule = y~., data=nos_data,max_iter = 300, mode='batch', parallel = TRUE )

## End(Not run)

samiaittilat/Logistic-Regression-from-scratch-in-R documentation built on Dec. 22, 2021, 10:11 p.m.