Course Content
Logistic Regression Mastering
Logistic Regression Mastering
Model Training
The process of training an ML model involves providing an ML algorithm (that is, the learning algorithm) with training data to learn from. The term ML model refers to the model artifact that is created by the training process.
The training data must contain the correct answer, which is known as a target or target attribute. The learning algorithm finds patterns in the training data that map the input data attributes to the target (the answer that you want to predict), and it outputs an ML model that captures these patterns. We are going to investigate the accuracy of our model in the next section, just focus on training the model for now.
We are going to train a Logistic regression model. Formally, in binary logistic regression, there is a single binary dependent variable, coded by an indicator variable, where the two values are labeled "0" and "1", while the independent variables can each be a binary variable (two classes, coded by an indicator variable) or a continuous variable (any real value).
Methods description
sklearn.linear_model
: This module from scikit-learn provides various linear models for classification and regression tasks;LogisticRegression
: This is a class within thesklearn.linear_model
module used for logistic regression, a statistical method for analyzing datasets where there are one or more independent variables that determine an outcome. It's commonly used for binary classification problems;.random_state
: This parameter sets the random seed for reproducibility;.max_iter
: This parameter specifies the maximum number of iterations for the solver to converge;
.fit(X_train, y_train)
: This method trains the logistic regression model using the training data X_train and corresponding labels y_train. It adjusts the parameters of the model to minimize the loss function and fit the data as well as possible;.predict(X_test)
: This method predicts the labels for the input data X_test using the trained logistic regression model. It returns the predicted labels based on the learned parameters from the training data.
Swipe to show code editor
- Import LogisticRegression from
sklearn
. - Use the method just imported to initialize the classifier.
- Call
.fit()
and passX_train
andy_train
as parameters. - Predict on
X_test
.
Thanks for your feedback!