ML Exp 8
ML Exp 8
Experiment 8
• Implementation of Logistic
Regression using sklearn
Logistic Regression
• A basic machine learning approach that is frequently
used for binary classification tasks is called logistic
regression.
• It uses the sigmoid function to simulate the likelihood of
an instance falling into a specific class, producing
values between 0 and 1.
• Logistic regression, with its emphasis on interpretability,
simplicity, and efficient computation, is widely applied
in a variety of fields, such as marketing, finance, and
healthcare, and it offers insightful forecasts and useful
information for decision-making
• A statistical model for binary classification is called
logistic regression.
• Using the sigmoid function, it forecasts the likelihood
that an instance will belong to a particular class,
guaranteeing results between 0 and 1.
• To minimize the log loss, the model computes a linear
combination of input characteristics, transforms it using
the sigmoid, and then optimizes its coefficients using
methods like gradient descent.
• These coefficients establish the decision boundary that
divides the classes.
• Because of its ease of use, interpretability, and
versatility across multiple domains, Logistic Regression
is widely used in machine learning for problems that
involve binary outcomes.
• Overfitting can be avoided by implementing
regularization
Logistic Regression uses a linear equation to combine the
input information and the sigmoid function to restrict
predictions between 0 and 1.
Gradient descent and other techniques are used to
optimize the model’s coefficients to minimize the log loss
.
These coefficients produce the resulting decision
boundary, which divides instances into two classes.
• When it comes to binary classification, logistic
regression is the best choice because it is easy to
understand, straightforward, and useful in a variety of
settings.
• Generalization can be improved by using regularization.
Python Code Import Libraries
• # Standardize features
• scaler = StandardScaler()
• X_train = scaler.fit_transform(X_train)
• X_test = scaler.transform(X_test)
Train The Model
• plt.figure(figsize=(8, 6))
• plt.plot(fpr, tpr, color='darkorange', lw=2,
• label=f'ROC Curve (AUC = {roc_auc:.2f})')
• plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--', label='Random')
• plt.xlabel('False Positive Rate')
• plt.ylabel('True Positive Rate')
• plt.title('Receiver Operating Characteristic (ROC) Curve\nAccuracy: {:.2f}%'.format(
• accuracy * 100))
• plt.legend(loc="lower right")
• plt.show()
OUTPUT