MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# What is box cox transformation?

# What is box cox transformation?

This recipe explains what is box cox transformation

Transformation of any power-law or any non-linear distribution to normal distribution is generally carried on by Box-Cox Transformation. A Box cox transformation is defined as a way to transform non-normal dependent variables in our data to a normal shape.

So this recipe is a short example on what is box cox transformation. Let's get started.

```
import numpy as np
from scipy.stats import boxcox
import seaborn as sns
import matplotlib.pyplot as plt
```

Let's pause and look at these imports. Numpy is general one. boxcox will help in normalizing dataset. sns and plt are used for plotting of dataset.

```
original_data = np.random.exponential(size = 1000)
```

We have set here an exponential function for normalization.

Now our dataset is ready.

```
fitted_data, fitted_lambda = boxcox(original_data)
```

We have fitted our data usin boxcox into normal function and found the lamda used for the transformation.

```
fig, ax = plt.subplots(1, 2)
sns.distplot(original_data, hist = False, kde = True, kde_kws = {'shade': True, 'linewidth': 2}, label = "Non-Normal", color ="green", ax = ax[0])
sns.distplot(fitted_data, hist = False, kde = True, kde_kws = {'shade': True, 'linewidth': 2}, label = "Normal", color ="green", ax = ax[1])
plt.legend(loc = "upper right")
fig.set_figheight(5)
fig.set_figwidth(10)
```

We have simply used sns class to plot for original as well as fitted dataset.

Once we run the above code snippet, we will see:

Srcoll down the ipython file to visualize the results.

In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

In this project, we are going to work on Deep Learning using H2O to predict Census income.

Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.