Repository navigation
0.2.0
Pre-releaseRelease Notes for LogRegSISEM2 v0.2.0
Overview
We are pleased to announce the release of version 0.2.0 of the LogRegSISEM2 package. This package provides a custom implementation of multinomial logistic regression, designed specifically for students of the M2 SISE program at Lyon in France.
Features
Custom R6 Logistic Regression Class: Implement logistic regression using gradient descent.
Encoding Methods: Includes label encoding, one-hot encoding, frequency encoding, and binary encoding for categorical variables.
Performance Metrics: Calculate accuracy, log-likelihood, and coefficients of the logistic regression model.
Example Usage: Demonstrates how to use the package with the Titanic dataset.
Installation
You can install the package from GitHub using the following command in R:
# Install devtools if you haven't already
install.packages("devtools")
# Install LogRegSISEM2 from GitHub
devtools::install_github("jdalfons/LogRegSISEM2")Usage
Here is a quick example of how to use the package:
library(LogRegSISEM2)
# Load Titanic dataset
data <- as.data.frame(Titanic)
data <- data[rep(seq_len(nrow(data)), data$Freq), ]
data$Freq <- NULL
data$Survived <- factor(data$Survived, levels = c("No", "Yes"))
data$Class <- factor(data$Class)
data$Sex <- factor(data$Sex)
data$Age <- factor(data$Age)
# Create a Hash table of encoding for variables
encoding_dict = list(Sex = "frequency", Age = "binary")
# Create the categorical verifier
verifier <- CategoricalVerifier$new(data, encoding_dict = encoding_dict)
# Apply the encoding
verifier$apply_encoding()
# Prepare data for logistic regression
X <- as.matrix(data[, c("Sepal.Length", "Sepal.Width")])
y <- data$Species
# Split data
train_indices <- createDataPartition(y, p = 0.8, list = FALSE)
X_train <- X[train_indices, ]
y_train <- y[train_indices]
X_test <- X[-train_indices, ]
y_test <- y[-train_indices]
# Train logistic regression model
reglog_model <- LogisticRegression$new(learning_rate = 0.01, iterations = 1000)
reglog_model$fit(X_train, y_train)
# Predict and evaluate
reglog_pred_class <- reglog_model$predict(X_test)
reglog_accuracy <- mean(reglog_pred_class == y_test)
print(paste("Accuracy:", reglog_accuracy))Contributions
We welcome contributions from the community. If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.
License
This package is licensed under the MIT License.