DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • When To Use Decision Trees vs. Random Forests in Machine Learning
  • Two-Pass Huffman in Blocks of 2 Symbols: Golang Implementation
  • Decoding Data Analysis: Transforming Cross-Tabulation Into Structured Tabular Tables
  • Solving Unique Search Requirements Using TreeMap Data Structure

Trending

  • AI-Driven Root Cause Analysis in SRE: Enhancing Incident Resolution
  • Cloud Security and Privacy: Best Practices to Mitigate the Risks
  • Building Reliable LLM-Powered Microservices With Kubernetes on AWS
  • Immutable Secrets Management: A Zero-Trust Approach to Sensitive Data in Containers
  1. DZone
  2. Data Engineering
  3. Data
  4. Logistic Regression vs. Decision Tree

Logistic Regression vs. Decision Tree

Find the best method for classification based on your data.

By 
Shital Kat user avatar
Shital Kat
·
Aug. 08, 19 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
36.3K Views

Join the DZone community and get the full member experience.

Join For Free

When to Use Each Algorithm

Logistics Regression (LR) and Decision Tree (DT) both solve the Classification Problem, and both can be interpreted easily; however, both have pros and cons. Based on the nature of your data choose the appropriate algorithm.

Of course, at the initial level, we apply both algorithms. Then, we choose which model gives the best result. But have you ever thought of why a particular model is performing best on your data?

Let's look at some aspects of data.

Is Your Data Linearly Separable?

Logistic Regression assumes that the data is linearly (or curvy linearly) separable in space.Separable in space

Separable in space


Decision Trees are non-linear classifiers; they do not require data to be linearly separable.

Non-linearly separable data

Non-linearly separable data



When you are sure that your data set divides into two separable parts, then use a Logistic Regression. If you're not sure, then go with a Decision Tree. A Decision Tree will take care of both.

Check Data Types

Categorical data works well with Decision Trees, while continuous data work well with Logistic Regression.

If your data is categorical, then Logistic Regression cannot handle pure categorical data (string format). Rather, you need to convert it into numerical data.

  1. Enumeration: If we enumerate the labels eg. Mumbai — 1, Delhi — 2, Bangalore — 3, Chennai — 4, then the algorithm will think that Chennai (2) is twice large as Mumbai (1).

  2. One Hot Encoding: For the above problem, use One Hot Encoding; however, this could result in a Dimension problem. Therefore, if you have lots of categorical data, go with a Decision Tree.

Is Your Data Highly Skewed?

Decision Trees handle skewed classes nicely if we let it grow fully.

Eg. 99% data is +ve and 1% data is –ve

Highly skewed data in a Decision Tree

Highly skewed data in a Decision Tree


So, if you find bias in a dataset, then let the Decision Tree grow fully. Don’t cut off or prune branches. Instead, identify max depth according to the skew.

Logistic Regression does not handle skewed classes well. So, in this case, either increase the weight to the minority class or balance the class.

Does Your Data Contain Outliers?

Logistic regression will push the decision boundary towards the outlier.

Ignoring and moving toward the outlier

Ignoring and moving toward outliers


While a Decision Tree, at the initial stage, won't be affected by an outlier, since an impure leaf will contain nine +ve and one –ve outlier. The label for the leaf will be +ve, since the majority are positive.

However, if we let the Decision Tree grow fully, the signal will mote to one side, while the outlier will be moved to the other — there will be one leaf for each outlier. 

Does Your Data Contain Many Missing Values?

Logistic Regression does not handle missing values; we need to impute those values by mean, mode, and median.

If there are many missing values, then imputing those may not be a good idea, since we are changing the distribution of data by imputing mean everywhere.

Decision Trees works with missing values.

Cheatsheet.

Linearly non - separable? Decision Tree
Categorical Data type Decision Tree
Continuous Data type Logistic Regression        
Skewed

Decision Tree, or give high weight to minority class in Logistic Regression

Outlier Decision Tree, or remove outlier for Logistic Regression
Lots of Missing values Decision Tree
Decision tree Tree (data structure) Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • When To Use Decision Trees vs. Random Forests in Machine Learning
  • Two-Pass Huffman in Blocks of 2 Symbols: Golang Implementation
  • Decoding Data Analysis: Transforming Cross-Tabulation Into Structured Tabular Tables
  • Solving Unique Search Requirements Using TreeMap Data Structure

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!