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
Python Machine Learning By Example

You're reading from   Python Machine Learning By Example Implement machine learning algorithms and techniques to build intelligent systems

Arrow left icon
Product type Paperback
Published in Feb 2019
Publisher Packt
ISBN-13 9781789616729
Length 382 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Yuxi (Hayden) Liu Yuxi (Hayden) Liu
Author Profile Icon Yuxi (Hayden) Liu
Yuxi (Hayden) Liu
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Section 1: Fundamentals of Machine Learning FREE CHAPTER
2. Getting Started with Machine Learning and Python 3. Section 2: Practical Python Machine Learning By Example
4. Exploring the 20 Newsgroups Dataset with Text Analysis Techniques 5. Mining the 20 Newsgroups Dataset with Clustering and Topic Modeling Algorithms 6. Detecting Spam Email with Naive Bayes 7. Classifying Newsgroup Topics with Support Vector Machines 8. Predicting Online Ad Click-Through with Tree-Based Algorithms 9. Predicting Online Ad Click-Through with Logistic Regression 10. Scaling Up Prediction to Terabyte Click Logs 11. Stock Price Prediction with Regression Algorithms 12. Section 3: Python Machine Learning Best Practices
13. Machine Learning Best Practices 14. Other Books You May Enjoy

Converting categorical features to numerical – one-hot encoding and ordinal encoding

In the previous chapter, Predicting Online Ads Click-through with Tree-Based Algorithms, we mentioned how one-hot encoding transforms categorical features to numerical features in order to be used in the tree algorithms in scikit-learn and TensorFlow. This will not limit our choice to tree-based algorithms if we can adopt one-hot encoding to any other algorithms that only take in numerical features.

The simplest solution we can think of in terms of transforming a categorical feature with k possible values is to map it to a numerical feature with values from 1 to k. For example, [Tech, Fashion, Fashion, Sports, Tech, Tech, Sports] becomes [1, 2, 2, 3, 1, 1, 3]. However, this will impose an ordinal characteristic, such as Sports being greater than Tech, and a distance property, such as Sports...

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