fit: Logistic Regression

Description Usage Arguments Value Examples

View source: R/fit.R

Description

A function to compute logistic regression with the stochastic gradient descent algorithm

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
fit(
  formula,
  data,
  eta = 0.3,
  iter_Max = 200,
  mode = "Online",
  batch_size = 10,
  tol = 0.001,
  coefs = rep(0, (dim(model.frame(formula, data))[2]) - 1),
  intercept = 0,
  nb_Coeurs = 1
)

Arguments

formula

An object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted.

data

A data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model.

eta

The learning rate. Represents the speed of the descend gradient

iter_Max

Maximum iteration realized by the function.

mode

The mode to be used in fitting the model (Batch_Simple, Mini_Batch, Online). The default mode is Online.

batch_size

Size of the batch.

tol

Value that represents the stopping criterion. If the difference between the deviance from the previous epoch and the deviance from the current epoch is less than tol we suppose that the deviance is minimized and the training is stopped,

coefs

Initialized coefficients which will be learned by the stochastic gradient descent.

intercept

Initialized bias which will be learned by algorithm.

nb_Coeurs

Number of chores that have to be used by.

Value

Returns a S3 class object containing the features, the coefficients, the bias, a vector of deviances, the number of iterations done by the algorith and two variables to apply the same transformation to the data test than the data train.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data = iris[(iris$Species=="setosa" | iris$Species=="versicolor"),]
levels(data$Species)
levels(data$Species) <- c(levels(data$Species), c(0,1))
data$Species[data$Species=="setosa"] = 1
data$Species[data$Species=="versicolor"] = 0
data$Species = as.numeric(data$Species)
rows <- sample(nrow(data))
data <- data[rows,]
data$Species = data$Species -4
data_train = data[1:70,]
data_test = data[71:100,]
rm(data)
fit(formula=Species~.,data=data_train,eta=0.3,iter_Max=300,mode="Batch_Simple",batch_size=15)

yanisb3812/DyrRegLog documentation built on Dec. 23, 2021, 7:15 p.m.