'How to shift a distribution to match it with a "target" distribution

Let's say that i have two 1-D arrays with 2 different statistical distributions. Now, i want to match both distributions using one of them as "target".

In the example, i "shifted" one of the distributions using MinMaxScaler() from SciKit to match it with the other one...but i am sure i can achieve a "automatic" and "better" match with some API...or some code...

In the example i have both arrays in the same DataFrame (and both have the same length), but i'd be very pleased if somebody kwnow a way to achieve it using 2 different Dataframes and/or 2 arrays with different lengths.

Thank you!!

CODE

import numpy as np
import pandas as pd

from sklearn.preprocessing import MinMaxScaler 
import plotly.figure_factory as ff


################## DATA ######################


np.random.seed(54)  
crv = np.random.uniform(1,99,(1,100)).flatten()

np.random.seed(115)  
crv_target = np.random.uniform(51,149,(1,100)).flatten()

# Create DataFrame
df = pd.DataFrame(data=[crv, crv_target]).T
df = df.rename(columns={0: "crv", 1: "crv_target"})


# Scaler
scale = MinMaxScaler(feature_range=(50,150))
df['crv_shifted'] = scale.fit_transform(X=df['crv'].values.reshape(-1, 1),y=df['crv_target'].values.reshape(-1, 1))


# Create distplot 
data = [df['crv_shifted'],df['crv_target'],df['crv']]
labels = ['crv_shifted','crv_target','crv']
colors = ['#F8C471', '#22D2E6','#CD6155']

fig = ff.create_distplot(data, labels,show_hist=False,show_rug=False,colors=colors)
fig.show()

LINK TO PLOT



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source