Posts

Feature Scaling

Understanding Feature Scaling is very simple. We will look at the sample data set below. The 'Buy' column is the dependent variable while others are independent variables. If we consider Age and Salary columns they have two different scales. Age has 25-40 scale while Salary has 58000-78000 scale. In ML we are creating mathematical models. If we use this kind of unscaled data to build ML models then it may end up with bad models. For example, the Euclidean distance is used in most ML model building. Just think that we apply Euclidean distance to Age and Salary when age is 35. The value is  √ (35^2 + 62000^2) =  √ (1225 + 3844000000). We can see that the effect of 35 is negligible with compare to 62000. On the other hand we can say that there is no effect of Age variable in above type of calculations although it should be. The reason to this issue is the different scales of Age and Salary. To overcome this problem we have to take variables into a same scale. The pr...

Splitting the dataset into the Training set and Test set

In Machine learning we have to train(teach) the machine with the data set, and at the same time we have test the learning of the machine agains the data set. In this case we have to divide the data set into two set call Training set and Test set. In Python from sklearn.cross_validation import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) In R # Splitting the dataset into Training set and Test set #install.packages('caTools') library(caTools) set.seed(123) split = sample.split(dataset$Purchased, SplitRatio = 0.8) # split may be array like:  [TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE,TRUE, TRUE, TRUE] training_set = subset(dataset, split == TRUE) test_set = subset(dataset, split == FALSE) * Note: most probably test set size may be 20%

Encoding categorical data

In some data set there may be categorical data. For example we can consider following data set. Country     Age     Salary USA            35        $62,000 UK              25        $58,000 Canada        40        $69,000 USA            40        $78,000 UK              30        $64,000 Canada        30        $61,000 If we consider the country column, it can be categorized by country. We are going to categorize it by giving USA=1, UK=2 and Canada=3. * Note: Since we are going to build mathematical model, we can't deal with data like row values in Country column. Therefore we convert them to numerical values. Country     Age    ...

Taking care of missing data in a data set

In Python Imputation For various reasons, many real world datasets contain missing values, often encoded as blanks, NaNs or other placeholders. Such datasets however are incompatible with scikit-learn estimators which assume that all values in an array are numerical, and that all have and hold meaning. A basic strategy to use incomplete datasets is to discard entire rows and/or columns containing missing values. However, this comes at the price of losing data which may be valuable (even though incomplete). A better strategy is to impute the missing values, i.e., to infer them from the known part of the data. Eg: >>> import numpy as np >>> from sklearn.preprocessing import Imputer >>> imp = Imputer ( missing_values = 'NaN' , strategy = 'mean' , axis = 0 ) >>> imp . fit ([[ 1 , 2 ], [ np . nan , 3 ], [ 7 , 6 ]]) Imputer(axis=0, copy=True, missing_values='NaN', strategy='mean', verbose=0) >...

Importing libraries in Python

What is a library? Library is a tool that is used to make specific jobs # Importing the libraries  import numpy as np import  matplotlib.pyplot  as  plt import  pandas  as  pd Meaning of " import  numpy  as  np" import  is the import keyword  numpy is the name of the library as  np says: np is used as a shortcut for numpy  numpy is a mathematical tool. Since ML is based on mathematics, this is a very useful and commonly used library. matplotlib.pyplot is a sub library of matplotlib library. The pyplot sub lib is used to plotting in Python. pandas is useful for import data set and manage data set.  Above three libraries are commonly used in ML.  

Following online Machine Learning courses with Python and R

Udemy online course: Machine Learning A-Z™: Hands-On Python & R In Data Science Udacity online course: Machine Learning - Supervised Learning This is a big start. I'll complete these courses. And I'll be expert in Python and R too. 

Completed online Machine Learning course in 2011

Image
I'm really happy about successfully completing a online Machine Learning course in 2011.