# Tag Archives: python

## Eigenvalues & Eigenvectors with Python Examples In this post, you will learn about how to calculate Eigenvalues and Eigenvectors using Python code examples. Before getting ahead and learning the code examples, you may want to check out this post on when & why to use Eigenvalues and Eigenvectors. As a machine learning Engineer / Data Scientist, you must get a good understanding of Eigenvalues / Eigenvectors concepts as it proves to be very useful in feature extraction techniques such as principal components analysis. Python Numpy package is used for illustration purpose. The following topics are covered in this post: Creating Eigenvectors / Eigenvalues using Numpy Linalg module Re-creating original transformation matrix from eigenvalues & eigenvectors Creating Eigenvectors / Eigenvalues using Numpy In …

Continue reading

Posted in Data Science, Python. Tagged with , .

## Standard Deviation of Population & Sample – Python In this post, you will learn about the statistics concepts of standard deviation with the help of Python code example. The following topics are covered in this post: What is Standard deviation? Different techniques for calculating standard deviation Standard deviation of population vs sample What is Standard Deviation? The Standard Deviation (SD) of a data set is a measure of how spread out the data is. Take a look at the following example using two different samples of 4 numbers whose mean are same but the standard deviation (data spread) are different. Here is the code for calculating the mean of the above sample. One can either write Python code …

Continue reading

Posted in Data Science, Python, statistics. Tagged with , , .

## Sklearn SelectFromModel for Feature Importance In this post, you will learn about how to use Sklearn SelectFromModel class for reducing the training / test data set to the new dataset which consists of features having feature importance value greater than a specified threshold value. This method is very important when one is using Sklearn pipeline for creating different stages and Sklearn RandomForest implementation (such as RandomForestClassifier) for feature selection. You may refer to this post to check out how RandomForestClassifier can be used for feature importance. The SelectFromModel usage is illustrated using Python code example. SelectFromModel Python Code Example Here are the steps and related python code for using SelectFromModel. Determine the feature importance using …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## Feature Importance using Random Forest Classifier – Python In this post, you will learn about how to use Sklearn Random Forest Classifier (RandomForestClassifier) for determining feature importance using Python code example. This will be useful in feature selection by finding most important features when solving classification machine learning problem. It is very important to understand feature importance and feature selection techniques for data scientists to use most appropriate features for training machine learning models. Recall that other feature selection techniques includes L-norm regularization techniques, greedy search algorithms techniques such as sequential backward / sequential forward selection etc. The following are some of the topics covered in this post: Why feature importance? Random Forest for feature importance Using Sklearn RandomForestClassifier for Feature Importance Why …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## Sequential Forward Selection – Python Example In this post, you will learn about one of feature selection techniques namely sequential forward selection with Python code example. Refer to my earlier post on sequential backward selection technique for feature selection. Sequential forward selection algorithm is a part of sequential feature selection algorithms. Some of the following topics will be covered in this post: Introduction to sequential feature selection algorithms Sequential forward selection algorithm Python example using sequential forward selection Introduction to Sequential Feature Selection Sequential feature selection algorithms including sequential forward selection algorithm belongs to the family of greedy search algorithms which are used to reduce an initial d-dimensional feature space to a k-dimensional feature subspace where k < d. …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## Sequential Backward Feature Selection – Python Example In this post, you will learn about a feature selection technique called as Sequential Backward Selection using Python code example. Feature selection is one of the key steps in training the most optimal model in order to achieve higher computational efficiency while training the model, and also reduce the the generalization error of the model by removing irrelevant features or noise. Some of the important feature selection techniques includes L-norm regularization and greedy search algorithms such as sequential forward or backward feature selection, especially for algorithms which don’t support regularization. It is of utmost importance for data scientists to learn these techniques in order to build optimal models. Sequential backward …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## MinMaxScaler vs StandardScaler – Python Examples In this post, you will learn about concepts and differences between MinMaxScaler & StandardScaler with the help of Python code examples. Note that these are classes provided by sklearn.preprocessing module and used for feature scaling purpose. As a data scientist, you will need to learn these concepts in order to train machine learning models using algorithms which requires features to be on the same scale. For algorithms such as random forests and decision trees which are scale invariant, you do not need to use these feature scaling techniques. The following topics are covered in this post: Why is feature scaling needed? Normalization vs Standardization MinMaxScaler for normalization StandardScaler for standardization …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## One-hot Encoding Concepts & Python Code Examples In this post, you will learn about One-hot Encoding concepts and code examples using Python programming language. One-hot encoding is also called as dummy encoding. In this post, OneHotEncoder class of sklearn.preprocessing will be used in the code examples. As a data scientist or machine learning engineer, you must learn the one-hot encoding techniques as it comes very handy while training machine learning models. Some of the following topics will be covered in this post: One-hot encoding concepts Using OneHotEncoder for single categorical feature Using OneHotEncoder & ColumnTransformer for encoding multiple categorical features Using Pandas get_dummies API for one-hot encoding One-Hot Encoding Concepts Simply speaking, one-hot encoding is a technique …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## Pandas – Append Columns to Dataframe In this post, you will learn different techniques to append or add one column or multiple columns to Pandas Dataframe (Python). There are different scenarios where this could come very handy. For example, when there are two or more data frames created using different data sources, and you want to select a specific set of columns from different data frames to create one single data frame, the methods given below can be used to append or add one or more columns to create one single data frame. It will be good to know these methods as it helps in data preprocessing stage of building machine learning models. In this post, …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## LabelEncoder Example – Single & Multiple Columns In this post, you will learn about LabelEncoder code examples for handling encoding labels related to categorical features of single and multiple columns in Python Pandas Dataframe. The following are some of the points which will get covered: Background What are labels and why encode them? How to use LabelEncoder to encode single & multiple columns (all at once)? When not to use LabelEncoder? Background When working with dataset having categorical features, you come across two different types of features such as the following. Many machine learning algorithms require the categorical data (labels) to be converted or encoded in the numerical or number form. Ordinal features – Features which has …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## Pandas – Fillna method for replacing missing values In this post, you will learn about how to use fillna method to replace or impute missing values of one or more feature column with central tendency measures in Pandas Dataframe (Python).The central tendency measures which are used to replace missing values are mean, median and mode. Here is a detailed post on how, what and when of replacing missing values with mean, median or mode. This will be helpful in the data preprocessing stage of building machine learning models. Other technique used for filling missing values is backfill or bfill and forward-fill or ffill. Before going further and learn about fillna method, here is the Pandas sample dataframe we will work with. It represents marks in …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## Python – Replace Missing Values with Mean, Median & Mode In this post, you will learn about how to impute or replace missing values  with mean, median and mode in one or more numeric feature columns of Pandas DataFrame while building machine learning (ML) models with Python programming. You will also learn about how to decide which technique to use for imputing missing values with central tendency measures of feature column such as mean, median or mode. This is important to understand this technique for data scientists as handling missing values one of the key aspects of data preprocessing when training ML models. The dataset used for illustration purpose is related campus recruitment and taken from Kaggle page on Campus Recruitment.  As a first step, the …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

## How to Create a Pandas Sample Dataframe In this post, you will learn about how to create a Pandas dataframe with some sample data. The following represent two different techniques using which one can create the Pandas Dataframe: Create Dataframe without using Numpy Array Create Dataframe using Numpy Array Create Dataframe without using Numpy Array Here is the python code for creating a Pandas dataframe without using Numpy array: Create Dataframe using Numpy Array Here is the code for creating a dataframe using Numpy array. Note the usage of np.array used for creating an instance of Numpy Ndarray. The following will be printed:

Posted in Data Science, Python. Tagged with , .

## Random Forest Classifier Python Code Example In this post, you will learn about how to train a Random Forest Classifier using Python Sklearn library. This code will be helpful if you are a beginner data scientist or just want to quickly get code sample to get started with training a machine learning model using Random Forest algorithm. The following topics will be covered: Brief introduction of Random Forest Python code example for training a random forest classifier Brief Introduction to Random Forest Classifier Random forest can be considered as an ensemble of several decision trees. The idea is to aggregate the prediction outcome of multiple decision trees and create a final outcome based on averaging mechanism …

Continue reading

Posted in AI, Data Science, Machine Learning, Python. Tagged with , , .

## Decision Tree Classifier Python Code Example In this post, you will learn about how to train a decision tree classifier machine learning model using Python. The following points will be covered in this post: What is decision tree? Decision tree python code sample What is Decision Tree? Simply speaking, the decision tree algorithm breaks the data points into decision nodes resulting in a tree structure. The decision nodes represent the question based on which the data is split further into two or more child nodes. The tree is created until the data points at a specific child node is pure (all data belongs to one class). The criteria for creating the most optimal decision questions is …

Continue reading

Posted in AI, Data Science, Machine Learning, Python. Tagged with , , .

## SVM RBF Kernel Parameters with Code Examples In this post, you will learn about SVM RBF (Radial Basis Function) kernel hyperparameters with the python code example.  The following are the two hyperparameters which you need to know while training a machine learning model with SVM and RBF kernel: Gamma  C (also called regularization parameter) Knowing the concepts on SVM parameters such as Gamma and C used with RBF kernel will enable you to select the appropriate values of Gamma and C and train the most optimal model using the SVM algorithm.  Let’s understand why we should use kernel functions such as RBF. Why use RBF Kernel? When the data set is linearly inseparable or in other words, the …

Continue reading

Posted in AI, Data Science, Machine Learning. Tagged with , , .