Feature engineering tips for improving predictions..

Feature engineering tips for improving predictions..

One of the key factors that data analysts focuses to improve the accuracy of a machine learning output is to choose the correct predictors that is feed into the system for prediction.

Inclusion of non impacting features will unnecessarily increases the complexity of the model and in general most of the algorithms suffer from curse of dimensionality and starts underperforming towards reduced accuracy. It becomes crucial to include the appropriate predictors and as well eliminate the non-impacting features for better results.

Feature Engineering is an area in machine learning that focus on enabling the correct features for the model being developed. Below are the some of the challenges that comes to the mind of a data Analyst and statistics has way of answering to those questions.

  1. How to make sure that a feature (variable) chosen creates an impact on the prediction outcome?
  2. Will the accuracy of my model increases with eliminating the non-impacting features?
  3. How do I understand and bring the correlation between the features in the model to improve accuracy?

Let’s try to analyze these challenges and some options to address them.. I have used R-language to show case the solutions..

  1. How do I make sure that a feature (variable) chosen creates impacts the prediction outcome?

Let us take a dataset Advertising Sales data (from reference ISLR book) from media TV, Radio, Newspaper and see if these features impacts the sales.

We are trying to load the data here and trying to fit a linear prediction for sales value given the expense spent on TV, Radio, Newspaper marketing.


sales = read.csv(file=’Advertising.csv’,header = TRUE)


lm.fit1 = (lm(Sales~TV+Radio+Newspaper,data=sales))

P value tests the null hypothesis that the coefficient is equal to zero . A low p-value ( <0.05 ) indicates that the feature makes meaningful addition to the model where a high value of p-value  shows that the feature has less impact on the result. R language has the summary command, feeding model to the command will show lot of details including p-value of each feature as below…


## Call:
## lm(formula = Sales ~ TV + Radio + Newspaper, data = sales)
## Residuals:
##     Min      1Q  Median      3Q     Max
## -8.8277 -0.8908  0.2418  1.1893  2.8292
## Coefficients:
##                           Estimate Std. Error t value    Pr(>|t|)   
## (Intercept)     2.938889   0.311908   9.422   <2e-16 ***
## TV                     0.045765   0.001395  32.809   <2e-16 ***
## Radio               0.188530   0.008611  21.893    <2e-16 ***
## Newspaper  -0.001037   0.005871  -0.177     0.86   
## —
## Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ‘ 1
## Residual standard error: 1.686 on 196 degrees of freedom
## Multiple R-squared:  0.8972, Adjusted R-squared:  0.8956
## F-statistic: 570.3 on 3 and 196 DF,  p-value: < 2.2e-16

The above command shows features TV, Radio has p-value less than 2e-16 where feature Newspaper has p-value of 0.86 which is very high. We can assume that newspaper feature creates the least impact to the prediction result.

  1. How to make sure that my model accuracy increases with eliminating the non-impacting features?
  • We have found just now newspaper feature is not creating impacting to the prediction result. let’s exclude newspaper and create the model , lets validate the stats of the new model without newspaper feature.Adjusted R-square value denotes the accuracy of fitment of training data to the model. We can see the R-square value improved from 0.8956 to 0.8962 with the removal of newspaper in the model fitment.

lm.fit2 = lm(Sales~TV+Radio,data=sales)

## Call:
## lm(formula = Sales ~ TV + Radio, data = sales)
## Residuals:
##     Min      1Q  Median      3Q     Max
## -8.7977 -0.8752  0.2422  1.1708  2.8328
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  2.92110    0.29449   9.919   <2e-16 ***
## TV                  0.04575    0.00139  32.909   <2e-16 ***
## Radio            0.18799    0.00804  23.382   <2e-16 ***
## —
## Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ‘ 1
## Residual standard error: 1.681 on 197 degrees of freedom
## Multiple R-squared:  0.8972, Adjusted R-squared:  0.8962
## F-statistic: 859.6 on 2 and 197 DF,  p-value: < 2.2e-16

Having too many non impacting features will make the model cluttered and more complex and impact the fitment of the model. It is always recommended to eliminate the non-impacting features.

  1. How features that are highly correlated impacts the prediction ?
  • Features that are highly correlated makes duplicate impact and highly influence the result. It is recommended to identify features that are highly correlated and eliminate the impact.A simple plot can help to visualize the correlation between features as below..



Variance Inflation Factor ( VIF ) defines a measure to statistically measure  correlation score among the feature columns. Smallest value of VIF ( close to 1 ) denotes complete absence of collinearity. A high value of VIF exceeding 5 or 10 denotes the presence of collinearity.


## [1] 1.003219

Based on the value of VIF , We can conclude features TV, newspaper are not correlated.

Generally it will be easy to analyze each column for feature selection when we have few features in the dataset but when the dataset is of high dimensional with 100s of features it will be difficult to do the analysis on n factorial combinations of collinearity.

Subset selection is a field in machine learning which defines best practices to for feature selection for a high dimensional dataset. Some approaches followed towards eliminating correlated feature are Principal Component Analysis ( PCA ) , Dimensionality reduction, forward selection, backward selection etc. I will detail about the process subset selection for high dimensional dataset detailed in a separate post.

Reference : The Elements of Statistical Learning

Choose your best platform for Machine Learning Solution

Choose your best platform for Machine Learning Solution

Enterprise applications trending to adopt Machine Learning as one of their strategic implementation and performing machine learning based deep analytics across multiple problem statements is becoming a common trend. There are variety of machine learning solutions / packages / platform that exist in market. One of the main challenges that the teams initially trying to resolve is to choose the correct platform / package for their solution.

Based on my experience with different machine learning solutions I thought to write this blog to list out the points (features in machine learning term) to consider while choosing a specific ML platform and list pros and cons of each of the solutions in market.

Let’s look at feature set that can be weighted before deciding a ML solution

High Level Feature Feature Set Comments
Data Storage High Storage Volume Need Ability to store huge volume of data to serve growing storage needs


High Availability High availability of data on partial failures


Data Exploration Visualizing summary tables and patterns in input data Ability to find patterns in input data, This will be helpful to understand and define features



Data Preparation / Cleansing Feature Extraction Manipulating the raw data to extract features needed for algorithm execution. This could be time consuming task when we deal with huge volume of data..


Distributed Execution Ability to perform the data manipulation in a distributed way , this is required when you have huge volume of data and need to reduce the time to complete. Many ML solutions are trying to bring this capability.


Development Supported Languages Scripting languages support for development


Ease of development How easy is the platform to develop scripts and execution?


General Purpose Programming Other than model creation , prediction , will the language support the general purpose programming needs for the application ?


Model Algorithms Supported Availability of different algorithm implementation packages on the platform. This is a critical requirement as we cannot switch to different products for different solutions.


Distributed Execution in Model Creation Model creation is a time consuming operation and needs lot of experimentation and hence the ability to create the model in a distributed way saves lot of time and will help to do experiments


Deep Learning Support Support for Deep learning algorithms


GPU Support GPU execution support will help to reduce execution by multi folds


Flexibility to Tune Model How flexible are the API exposing the mode parameters that can be tuned


Model Examination Flexibility Ability to examine the model helps to deep dive into what is happening behind the model


Ease in switching between Models Switch between different models for suitable choice


Data Visualization Visualize and Plot the results Availability of different charts to visualize the output


Productionizing Ease of deploying the model in production use case on web environment Run in large scale deployment

Ability to deploy the model in web

Scale to huge volume of data handling


Support Official / Community Support with Active development Commercial support availability for the platform / solution

Active community development




Now let’s look at the different machine learning solutions / platforms available in the market and where they stand with respect address the feature requirements.

Solution Language Pros Cons
RStudio R Thousands of packages for different solutions

Easy to develop

Deep Model examination and tuning

Time consuming execution due to single threaded nature.

Not easy productionizing for  web environment


Spark ML Scala, Python, R Scalable Machine learning library

Distributed execution utilizing platform like Yarn , Mesos etc.

Faster execution

Supports multiple languages like Scala, Python, R



New to market

Does not have exhaust list of algorithm implementation

Knowledge of Hadoop eco system

H20 Scala, Python, R Easy integration to platforms like Spark through Sparkling water , R

Connect to data from hdfs, S3, NOSQL db etc…



Compatibility between H20 and Spark with Sparkling water

No support for scala in H20 Notebooks


Tensorflow Python, C++ Flexible architecture that can deployed to run CPU / GPU

Effective utilization of underlying hardware.

Stronger in Deep Learning implementations


Learning Curve is comparatively more

Generally meant for Neural network based implementation

Matlab Matlab Advanced tool box with wide variety of algorithm implementations

Algorithms can be deployed as Java or dot net packages for deployment


Learning of Matlab language

Expensive product


Anaconda Python Good collection of algorithm implementations

Easy to learn and develop

Integration with PYSPARK

Good for local usage and trials


Enterprise license cost

Advanced features is licensed and expensive


Turi Python SFrame concept aims for distributed machine learning executions

Can read and process from HDFS, S3 etc.

Simplified machine learning executions


Commercial licensed product


IBM Watson PaaS for ML PaaS platform for Machine Learning on IBM Blue Mix

Easy integration with social, cloud

End to end solution development with limited knowledge

Easy to deploy


Limited control in model creation & tuning

Limited control over underlying infrastructure


Azure ML PaaS for ML PaaS platform for Machine Learning on Microsoft Azure

Workflow based ML solution on Azure

Easy to develop ML solutions on Azure cloud


Limited control in model creation & tuning


Limited control over underlying infrastructure

AWS ML SaaS for ML PaaS platform for Machine Learning on AWS

Easy to develop ML solutions on AWS cloud


Limited control in model creation & tuning


Limited control over underlying infrastructure


To summarize

Machine learning packaged solutions like RStudio, H20, Anaconda, Turi are trying to improve in the space of connecting to distributed storage platform and trying to add capabilities for distributed multi thread / core /node execution to reduce time for execution on data preparation, feature extraction  and model creation.

Machine learning PaaS solutions like IBM Watson, Azure ML, AWS ML having benefits of cloud background tries to abstract the overhead of packaging and aims for easy deployment and scalability. But these solutions limits the capabilities on the level of fine tuning the models and algorithms exposed for execution but a common man without knowledge of algorithms should able to execute.

With respect to cost and licensing most of the packaged solutions are free to run on local system with limited compute and storage capabilities , enterprise usage or when the distributed version of these solution needs comes with cost. ML solutions on cloud works with pay as use cloud pricing and service model.

Reference :





Auto-scaling scikit-learn with Apache Spark