Member-only story

Animations of Logistic Regression with Python

Tobias Roeschl
Towards Data Science
8 min readNov 17, 2020

This article is about creating animated plots of simple and multiple logistic regression with batch gradient descent in Python. In the end, I will also present a visual explanation of why the cross-entropy cost function is the method of choice to quantify costs in logistic regression. In terms of structure and content, this article relates to — and partially builds on — previous articles I wrote about creating animations of batch gradient descent with the example of simple linear and multiple linear regression. The general idea is to set up a logistic regression model and train the model on some arbitrary training data while storing parameter values and costs for each epoch. After confirming our results through sklearn’s built-in logistic regression model, we will use the stored parameter values to generate animated plots with Python’s celluloid module. The animations we use to visualize logistic regression will be similar to the ones we created for previous articles on linear regression.

Setting up the model:

Logistic regression is a classification algorithm that predicts probabilities of particular outcomes given one or more independent variables. The independent variable can be continuous or categorical. The outcome can be interpreted as taking membership in one of a discrete set of classes. In this article, we confine the number of classes to two classes although it is theoretically possible to generalize logistic regression to multiclass problems with more than two possible outcomes…

--

--

Towards Data Science
Towards Data Science

Published in Towards Data Science

Your home for data science and AI. The world’s leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.

Tobias Roeschl
Tobias Roeschl

Written by Tobias Roeschl

Resident physician passionate about data science, statistics and machine learning. Get in touch: www.linkedin.com/in/tobi-roeschl-60430217b

Responses (2)