Feature scaling in python using scikit-learn

In my previous post, I explained the importance of feature encoding and how to do it in python using scikit-learn. In this post, we are going to talk about another component of the preprocessing step in applying machine learning models which is feature scaling. Very rarely would you be dealing with features that share the same scale. What do I mean by that? For example, let’s look at the famous wine dataset which can be found here. This dataset contains several features such as alcohol content, malic acid and color intensity which describe a type of wine. Focusing on just these three features, we can see that they do not share same scale. Alcohol content is measured in alcohol/volume where as malic acid is measured in g/l.

Why is feature scaling important?

If we were to leave the features as they are and feed them to a machine learning algorithm, we may get incorrect predictions. This is because most algorithms such as SVM, K-nearest neighbors, and logistic regression expect features to be scaled. If the features are not scaled, your machine learning algorithm might assign increased weight to one feature compared to another solely based on its value.

Continue…

Feature encoding in python using scikit-learn

Note: You can now subscribe to my blog updates here to receive latest updates.

A key step in applying machine learning models to your data is feature encoding and in this post, we are going to discuss what that consists of and how we can do that in python using scikit-learn.

Not all the fields in your dataset will be numerical. Many times you will have at least one non-numerical feature, which is also known as a categorical feature. For example, your dataset might have a feature called ‘ethnicity’ to describe the ethnicity of employees at a company. Similarly, you can also have a categorical dependent variable if you are dealing with a classification problem where your dataset is used to predict a class instead of a number (regression).

For example, let’s look at a famous machine learning dataset called Iris. This dataset has 4 numerical features: sepal length, sepal width, petal length and petal width. The output is a type of species which can be one of these three classes: setosa, versicolor and virginica.

Continue…

Difference between supervised and unsupervised learning models

Note: You can now subscribe to my blog updates here to receive latest updates.

In my introductory post about machine learning (ML), I listed a bunch of ML models by their output (regression, classification and clustering). These models can be classified differently as either supervised or unsupervised learning models.

Supervised learning models

In a supervised learning model, your data consists of independent variable(s) and dependent variable(s). You build your model by feeding it this data. The goal is to have a model which can take values of your independent variable and accurately predict corresponding values of the dependent variable.

These types of models are called supervised learning models because your test dataset is labeled with the right ‘answers’ for the model to learn from. You can say that you are supervising the model during its learning process.

Continue…

A brief overview of machine learning

Note: You can now subscribe to my blog updates here to receive latest updates.

A few years ago, ‘big data‘ was the latest buzzword. Since about a year or two ago, we have moved on to ‘machine learning‘ (and blockchain). Machine learning (ML) is nothing new. It has been used for at least a few decades but only recently has it become accessible enough to be used in mainstream. Only recently have the ML models been made so easily available to everyone through open source libraries. And only recently has the computer processing power become so cheap that it can be easily afforded to deploy computation heavy ML models. Never before was there a better time to learn ML and start using it!

I am no ML expert. Maybe one day I can become one but for now, I am simply an ML enthusiast. One of the main issues with getting started with ML is that it sounds very sophisticated and by all means, it is! ML consists of a lot of complex models that have been optimized over several decades. Unless you have a strong background in mathematics, you will find it extremely difficult to understand the inner workings of these models. But don’t let that intimidate you! Thanks to all the recent development in open source software, most of the ML models are easily available to be used. All you need to do is understand how the models work and when to use them! Instead of getting bogged down by the mathematical details, try to focus on high level theory and how to easily apply ML models. Once you build your basic understanding, you can pick which model(s) you want to explore further.

Continue…