loading...
Cover image for Logistic Regression for Machine Learning Problem

Logistic Regression for Machine Learning Problem

codeperfectplus profile image CodePerfectPlus Updated on ・2 min read

Machine Learning Algorithms (4 Part Series)

1) Single-layer Neural Networks in Machine Learning (Perceptrons) 2) Logistic Regression for Machine Learning Problem 3) What is Simple Linear Regression In Machine Learning World ? 4) How do Convolutional Neural Networks work?

This article was originally published at Codeperfectplus.

Introduction

Logistic Regression is a kind of parametric classification model. It's a binary classification machine learning algorithm. It can only be used to distinguish between 2 different categories like —

  • Like if an E-mail is spam(1) or not(0).
  • Whether the tumour is malignant (1) or not (0)

Email is spam or not

The theory behind Logistic Regression is very similar to the one from Linear Regression, so if you don’t know what Linear Regression is, take 5 minutes to read this Introduction.

Types of Logistic Regression

  1. Binary Logistic Regression
  2. Multinomial Logistic Regression
  3. Ordinal Logistic Regression

Assumptions for Logistic Regression

  1. For Logistic regression, there should be minimal or no multicollinearity among the independent variables.
  2. The Logistic regression assumes that the independent variables are linearly related to the log of odds.
  3. The Logistic regression usually requires a large sample size to predict properly.
  4. In Logistic regression dependent, the variable should be binary.
  5. The Logistic regression assumes the observations to be independent of each other.

Iris Flower Classification

# Impoer Library for classification
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.linear_model import Logi
from sklearn.metrics import accuracy_score
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
import joblib
np.random.seed(10)
# split data for training and testing purpose
iris = load_iris()
X = iris.data
y = iris.target
train_X, test_X, train_y, test_y = train_test_split(X, y, train_size=0.8)
# Create pipeline
pipe = Pipeline([
    ('scaler', StandardScaler()),
    ('logistic',LogisticRegression(),)
])

# fit and predict
clf = pipe.fit(train_X, train_y)
pred_y = clf.predict(test_X)
score = accuracy_score(test_y, pred_y)
print(score)

More Articles by Author

Join for Weekly Updates.

Machine Learning Algorithms (4 Part Series)

1) Single-layer Neural Networks in Machine Learning (Perceptrons) 2) Logistic Regression for Machine Learning Problem 3) What is Simple Linear Regression In Machine Learning World ? 4) How do Convolutional Neural Networks work?

Posted on by:

codeperfectplus profile

CodePerfectPlus

@codeperfectplus

Skilled in Data Science, Machine Learning, Deep Learning, As Well As Web Development Knowledge. React ❤️ to encourage Author.

Discussion

markdown guide