Exemplo n.º 1
0
def test_actual_results_power_transformer_yeo_johnson():
    """Test that the actual results are the expected ones."""
    for standardize in [True, False]:
        pt = PowerTransformer(method='yeo-johnson', standardize=standardize)
        arr_actual = pt.fit_transform(X)
        arr_desired = [yeojohnson(X[i].astype('float64'))[0] for i in range(3)]
        if standardize:
            arr_desired = StandardScaler().transform(arr_desired)
        np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)
Exemplo n.º 2
0
def test_actual_results_power_transformer_box_cox():
    """Test that the actual results are the expected ones."""
    for standardize in [True, False]:
        pt = PowerTransformer(method='box-cox', standardize=standardize)
        arr_actual = pt.fit_transform(X)
        arr_desired = [boxcox(X[i])[0] for i in range(3)]
        if standardize:
            arr_desired = StandardScaler().transform(arr_desired)
        np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)
Exemplo n.º 3
0
def test_actual_results_standard_scaler(params, arr_desired):
    """Test that the actual results are the expected ones."""
    arr_actual = StandardScaler(**params).transform(X)
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)
Exemplo n.º 4
0
"""

import numpy as np
import matplotlib.pyplot as plt
from pyts.preprocessing import (StandardScaler, MinMaxScaler,
                                MaxAbsScaler, RobustScaler)

# Parameters
n_samples, n_timestamps = 100, 48

# Toy dataset
rng = np.random.RandomState(41)
X = rng.randn(n_samples, n_timestamps)

# Scale the data with different scaling algorithms
X_standard = StandardScaler().transform(X)
X_minmax = MinMaxScaler(sample_range=(0, 1)).transform(X)
X_maxabs = MaxAbsScaler().transform(X)
X_robust = RobustScaler(quantile_range=(25.0, 75.0)).transform(X)

# Show the results for the first time series
plt.figure(figsize=(16, 6))

ax1 = plt.subplot(121)
ax1.plot(X[0], 'o-', label='Original')
ax1.set_title('Original time series')
ax1.legend(loc='best')

ax2 = plt.subplot(122)
ax2.plot(X_standard[0], 'o--', color='C1', label='StandardScaler')
ax2.plot(X_minmax[0], 'o--', color='C2', label='MinMaxScaler')