Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Practical Data Analysis Cookbook

You're reading from   Practical Data Analysis Cookbook Over 60 practical recipes on data exploration and analysis

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher
ISBN-13 9781783551668
Length 384 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Tomasz Drabas Tomasz Drabas
Author Profile Icon Tomasz Drabas
Tomasz Drabas
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Preparing the Data FREE CHAPTER 2. Exploring the Data 3. Classification Techniques 4. Clustering Techniques 5. Reducing Dimensions 6. Regression Methods 7. Time Series Techniques 8. Graphs 9. Natural Language Processing 10. Discrete Choice Models 11. Simulations Index

Using logistic regression as a universal classifier

Logistic regression is probably the second most (after linear regression) popular regression model. However, it can be easily adapted to solve a classification problem.

Getting ready

To run this recipe, you will need pandas and StatsModels; if you use the Anaconda distribution of Python, both of the modules are included in the distribution. We import two parts of StatsModels:

import statsmodels.api as sm
import statsmodels.genmod.families.links as fm

The first one allows us to select our models and the other one to specify the link function. No other prerequisites are required.

How to do it…

Following a similar pattern to our previous recipe, we import all the necessary modules first, read in the data, and split the read dataset into training and testing subsets. We then call the fitLogisticRegression(...) method to estimate the model (the classification_logistic.py file):

@hlp.timeit
def fitLogisticRegression(data):
    ''&apos...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime