Logistic Regression
Logistic Regression classical method implementation.
This section contains the Logistic Regression implementation for classification tasks. Logistic Regression is a linear model for classification that uses a logistic function to model the probability of a certain class or event.
- class TALENT.model.classical_methods.logreg.LogRegMethod(args, is_regression)
Bases:
classical_methods- construct_model(model_config=None)
- fit(data, info, train=True, config=None)
- predict(data, info, model_name)
- class TALENT.model.classical_methods.logreg.LogRegMethod
Logistic Regression method for classification tasks.
Key Features:
Uses sklearn’s LogisticRegression for classification
Linear model with logistic function for probability estimation
Supports both binary and multiclass classification
Automatically handles data preprocessing including normalization and encoding
Saves trained model to pickle file for later use
Provides probability predictions
Algorithm:
Logistic Regression is a linear model for classification that uses a logistic function to model the probability of a certain class or event. It is a special case of linear regression where the dependent variable is categorical.
- __init__(args, is_regression)
Initialize the Logistic Regression method.
Parameters:
args (object) – Configuration arguments containing model settings
is_regression (bool) – Whether the task is regression (True) or classification (False)
- construct_model(model_config=None)
Construct the Logistic Regression model instance.
Parameters:
model_config (dict, optional) – Model configuration parameters for Logistic Regression
Model Creation:
Creates LogisticRegression classifier
Configures parameters like regularization, solver, etc.
- fit(data, info, train=True, config=None)
Train the Logistic Regression model on the provided data.
Parameters:
data (tuple) – Tuple containing (N, C, y) where N is numerical features, C is categorical features, y is labels
info (dict) – Dataset information
train (bool, default=True) – Whether to train the model or just load from checkpoint
config (dict, optional) – Additional configuration parameters
Returns:
time_cost (float) – Training time in seconds
Training Process:
Data Preprocessing: Handles missing values, categorical encoding, normalization
Model Training: Fits the Logistic Regression model
Model Saving: Saves the trained model to disk for later use
- predict(data, info, model_name)
Make predictions using the trained Logistic Regression model.
Parameters:
data (tuple) – Tuple containing (N, C, y) where N is numerical features, C is categorical features, y is labels
info (dict) – Dataset information
model_name (str) – Name of the model for saving/loading
Returns:
test_logit (array-like) – Test predictions (probabilities for classification)
Prediction Process:
Data Preprocessing: Applies same preprocessing as training data
Model Loading: Loads the trained Logistic Regression model
Prediction: Generates probability predictions
Output: Returns probabilities for classification
Evaluation Metrics:
For classification: returns Accuracy, Avg_Precision, Avg_Recall, F1 metrics
References:
[1] Hosmer Jr, D. W., Lemeshow, S., & Sturdivant, R. X. (2013). Applied logistic regression (Vol. 398). John Wiley & Sons.