The Complete Life Cycle of a Machine Learning Model
By: Anjani Kumar
Tags: Data Science, Feature Engineering, Machine Learning, Exploratory Data Analysis, Data Pre Processing

image: networkworld.com

The Complete Life Cycle of a Machine Learning Model

Requirement Gathering

This is, first and foremost, the important step. Business use cases that require modeling should be identified. It may be the case that the business problem can be solved by software engineering and no modeling required. Now, let’s go ahead considering we need a robust model that can give good accuracy with training and testing data set.

Collect Data

The source of data should be identified and collected. Few of the data sources could be SQL database, NoSQL database, cloud, .csv, .txt, etc.

Data Pre-Processing Steps (EDA):

Before building any machine learning model it is crucial to perform data pre-processing to feed the correct data to the model to learn and predict. The model strength depends on the quality of the data. Below are the various pre-processing steps which need to perform. Details here.

Handling Null or Missing Values.(Use Mean/Median/Mode in case of feature having continuous values, use majority class value or use any classification technique to predict value for feature having categorical values. Alternatively you can delete the row having null values in case dataset is large ) Outliers or Skewness detection and Removal. Finding and fixing the imbalanced class problem. Duplicate Data Check. Inconsistent Value Check. Scaling/Normalization. Encoding Categorical Variables.

Feature Engineering/Feature Selection Steps:

In this step, we will select those features which best suited for our machine learning model and by performing the below steps. Details here.

Domain Expertise. Correlation Check and Removal of one of the correlated features. Covariance check. Zero Variance check. Removing features having maximum empty or null records. Removal of Duplicate features (like a column created by the square of any other column). Removal of unwanted features (like ID, Name, Ticket Number, etc.) Removal of Dummy Variables. Dimensionality Reduction using principal component analysis (PCA).

Model Selection

In this step, we need to choose the right model (supervised or unsupervised, based on the problem statement whether its regression or classification or clustering problem )and the right set of parameters for our use case and train that model. Generally, for any use case, various models are created and the model which gives the best performance is selected. This step involves a thorough understanding of the use case and domain.

Regression Model: Predicts continuous values (eg. house price or salary)

Classification Model: Predicts discrete values (eg. Yes/No, True/False)

Note: Some of the classification models mentioned in the supervised category can also be used for regression.

Model Tuning

This is a very critical step in the data science life cycle. Here, we check training and testing accuracy for our model which we created. The model whose training accuracy is very high and the testing accuracy is low is a case of model overfitting.

In this case, our model doesn’t generalize well from our training data to unseen data. We can say this also overfitting — when we have a model that has memorized the training data set does not perform well in real-world cases. In other words, it occurs if the model or algorithm shows low bias but high variance.

To avoid an overfitting model, the below steps can be performed.

Provide different parameter values in model and fit the model multiple times to see the parameters which have high training and testing score. Use GridSearchCV to find the best hyperparameters. This will give the best parameters for that specific model.

Model Performance

There are various performance measuring for regression Models

R-Squared(R2) Adj. R-Squared(R2) Mean Squared Error(MSE) Root mean squared Error(RMSE)

Performance measuring tools based on classification models:

Confusion Matrix Precision Recall ROC-AUC curve Accuracy

Model Deployment

Once a model is created and tested we need to deploy it to production. There are various ways to deploy: