Step-by-step function engineering

Contents

Introduction

importance-of-feature-engineering-in-datahack-competitions-6888452

Table of Contents

  1. Why should we use function engineering in data science?
  2. Feature selection
  3. Handling missing values
  4. Handling unbalanced data
  5. Handling of outliers
  6. Binning
  7. Coding
  8. Function scale

1. Why should we use function engineering in data science?

En Data Science, model performance depends on preprocessing and data handling. Suppose that if we build a model without Data handling, we obtain a precision of around 70%. By applying function engineering on the same model, there is the possibility to increase the performance of the 70% to more.

Simply, when using function engineering, we improve the performance of the model.

2. Feature selection

The selection of functions is nothing more than a selection of necessary independent functions. Selecting the important independent characteristics that are most related to the dependent characteristic will help to build a good model.. There are some methods for selecting functions:

2.1 Correlation matrix with heat map

The heat map es una representación gráfica de datos 2D (two-dimensional). Each data value is represented in an array.

First, draw the pair graph between all independent characteristics and dependent characteristics. Will give the relationship between dependent and independent characteristics. The relationship between the independent characteristic and the dependent characteristic is less than 0.2, then choose that independent feature to build a model.

953241-8931125

2.2 Univariate selection

In this, statistical tests can be used to select the independent characteristics that have the strongest relationship with the dependent characteristic. Select KBest The method can be used with a set of different statistical tests to select a specific number of characteristics.

225322-3258208
194213-4864398
  • The characteristic that has the highest score will be more related to the dependent characteristic, and choose those characteristics for the model.

2.3 ExtraTreesClassifier method

In this method, the ExtraTreesClassifier method will help to give the importance of each independent characteristic with a dependent characteristic. Role Importance will give you a score for each role in your data, the higher the score, más importante o relevante para la función con respecto a su variable de salida.

780774-2551883
924605-4264414

3. Handling missing values

In some data sets, we obtained the NA values ​​in the characteristics. They are just missing data. Handling this type of data there are many ways:

  • In the places of lost values, para reemplazar los valores perdidos con la media o median en los datos numéricos y para los datos categóricos con la moda.
458796-5086083
  • Eliminate NA values ​​in entire rows.
341087-2368081
  • Eliminate NA values ​​for full features. (helps if NA values ​​are more than 50% in a function)
963308-9197745
  • Replace the NA values ​​with 0.
560829-5765615

If you choose to discard options, there is the possibility of losing important information from them. So it is better to choose to replace the options.

4. Handling unbalanced data

Why is it necessary to handle unbalanced data? Due to reduce the problem of overfitting and misfitting.

suppose a characteristic has a factor level2 (0 Y 1). consists of 1 it is 5% Y 0 it is 95%. It's called unbalanced data.

Example:-

7333210-1974615

To prevent this problem, there are some methods:

4.1 Subsampled Majority Class

A subsampling of the majority class will resample the points of the majority class in the data to make them equal to the minority class.

8541811-8269732

4.2 Duplication oversampling minority class

Oversampling the minority class will resample the minority class points in the data to make them equal to the majority class.

8171312-9391373

4.3 Oversampling the minority class using the synthetic minority oversampling technique (SMOTE)

In this method, synthetic samples are generated for the minority class and equal to the majority class.

4998913-5701817

5. Handling of outliers

First, Calculate the skewness of the features and check if they are positively biased, negatively or normally biased. Another method is to plot the box plot on the characteristics and check if any value is out of bounds or not.. if they exist, are called outliers.

7193414-3602537

how to handle these outliers: –

First, compute quantile values ​​at 25% Y 75%.

8737115-2563705
  • then, calculate the interquartile range

IQR = Q3 – Q1

1178816-3559397
  • Then, calculate the values ​​of the upper and lower extremes.

lower end = Q1 – 1,5 * IQR

upper end = Q3– 1,5 * IQRe

9813417-8409527
  • finally, check that the values ​​are above the upper limit or below the lower limit. if it is presented, remove or replace them with the stocking, the median or any quantile value.
  • Replace outliers with mean
4137018-2718517
  • Replace outliers with quantile values
9596719-4220187
5643320-3385882

6. Binning

Binning is nothing more than any data value within the range that fits the bin. It is important in your data exploration activity. We normally use it to transform continuous variables into discrete variables..

Suppose that if we have the AGE function continuously and we need to divide the age into groups as a function, then it will be useful.

8629321-8977454

7. Coding:

Why will this apply? because in data sets we can contain data types of objects. to build a model, we need all features to be in integer data types. Thus, Label Encoder and OneHotEncoder are used to convert the data type of the object to an integer data type.

9572922-7746688

Before applying tag encoding

4483023-6484144
1144524-9472054

After applying tag encoding, apply column transformer method to convert labels to 0 Y 1

5214325-1367715

Al aplicar get_dummies, we directly convert categorical to numeric

1468326-3386882

8. Function scale

Why is this scale applied? because to reduce the variance effect and overcome the fit problem. there are two types of scaling methods:

8.1 Standardization

When is this method used ?. when all characteristics have high values, no 0 Y 1.

It is a technique to standardize the independent characteristics that occur in a fixed range to bring all the values ​​to the same magnitudes..

5627627-7112131

In standardization, the mean of the independent characteristics is 0 and the standard deviation is 1.

Method 1:

1517028-4794777
1602029-9839686

Method 2:

6623530-8889788

After encoding, feature labels are on 0 Y 1. This can affect standardization. To get over this, we use Normalization.

8.2 Normalization

La normalización también hace que el proceso de training sea menos sensible por la escala de las características. This results in obtaining better coefficients after training..

9710531-6241503

Method 1: -MinMaxScaler

It is a method of rescaling the characteristic to a fast and strict range of [0,1] subtracting the minimum value of the characteristic and then dividing by the range.

4247132-3737407
6890033-7357998

Method 2: – Average normalization

It is a method of rescaling the characteristic to a fast and strict range of [-1,1] with mean = 0.

2341734-1886395
43212screenshot2039-8683522
7337735-2828581

Final notes: –

In this article, I covered the function engineering process step by step. This is most useful for increasing the accuracy of the prediction..

Please note that there are no particular methods to increase the accuracy of your prediction. It all depends on your data and applies multiple methods.

As next step, I encourage you to try different data sets and analyze them. And don't forget to share your ideas in the comment section below!!

About the Author:

Soy Pavan Kumar Reddy Elluru. I completed my graduation from G.Pullareddy Engineering College in the year 2020. I am a certified data scientist in the year 2021 y me apasiona el aprendizaje automático y los proyectos de deep learning.

Please, write me in case of any query or just to say hello.

Email identification:- [email protected]

Linkedin identification:www.linkedin.com/in/elluru-pavan-kumar-reddy-a1b183197

ID de Github: – pawankumarreddy1999 (Pavan Kumar Reddy Elluru) (github.com)

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.

Datapeaker