Preparing for the Long Journey
As we know
it is very important to prepare before we embark on a journey. The
preprocessing phase is the similar one in case of machine learning. To make raw
data valuable and to refrain from facing the hurdles in deployment of machine
learning models, the data is preprocessed through several steps listed below :
Steps to Preprocess the Data before Machine Learning Model :
- Importing the Libraries
- Importing the Dataset
- Taking Care of Missing Data
- Encoding the Categorical Data
- Splitting Data into Testing and Training Set
- Feature Scaling of the Data
The first
and the foremost step is to import the libraries essential to handle the
mathematical computations and dataframes to handle huge data. The two most
popular libraries in python are Numpy and Pandas. Pandas is used to create
dataframes, Series and other such data handling units while on the other hand
Numpy handles the complex computational processes. For plotting the graphs we
need to import the matplotlib library.
The data
to be imported is available in various formats like Comma Separated
Values(csv),Tab separated values(tsv) and each one of those has its own
delimiter ( for eg. Comma in csv and Tab in tsv) on the basis of which words
are recognised distinctively. The pandas library provides a two dimensional
framework known as dataframes which handles the data. The default delimiter is
comma and if this is not the case then it has to be explicitly indicated while
importing the dataset.
Third, if
some rows of the data is missing then it would be an unwise practice to remove
it, it could result in a great loss in essential information. Instead we compute
the missing data using different strategies in different business situations (
for eg. Mean, Median or Mode).
Now
another problem arises when a categorical data is present in the data.
Categorical Data denotes the non-numeric data which cannot be employed for
building machine learning models. To convert it into numeric data we use Label Encoder
class from scikit learn library which solves our purpose. But any one category
don’t have priority over another category.
For Ex- If
there is a country field in the dataset and each country is assigned a random
number on the basis of alphabetical order it doesn’t mean that the country
assigned 1 has greater priority than others.
To avoid
this dilemma of the compiler we use dummy variables for each of the category of
data. Dummy variable denotes that each category is allotted a column which
contains 1 if the data appears and 0 if it doesn’t. But we consider only n-1
dummy variables to escape from the dummy variable trap problem. We will discuss
it later on.
As we know for building a machine learning
model we need to train it on a dataset so that it can learn relationship
between dependent and independent variables. We split the dataset into training
set and test set on the basis of split ratio. Generally test ratio is 20% of
the total data available.
Most of
the models implemented to solve business related problems are based on the
heavy mathematical calculations which include Euclidean distances which is
calculated by using coordinates of the observation points and if one point has
very large magnitude as compared to other one then it dominates the result. So
we consider each row of data as an observation point and apply feature scaling
to get standardized output and a stable model.
The code snippet for the data preprocessing step is included in the following Github link :
In the next post we will start building our machine learning models.
Stay tuned....
Comments
Post a Comment