def test_actual_results_quantile_transformer_normal(): """Test that the actual results are the expected ones.""" X_ppf = norm.ppf(np.linspace(0, 1, 1000)[1:-1]) weights = np.round(norm.pdf(X_ppf) * 1000).astype('int64') X = [] for value, weight in zip(X_ppf, weights): X += [value] * weight X = np.asarray(X).reshape(1, -1) transformer = QuantileTransformer(n_quantiles=11, output_distribution='normal') arr_actual = transformer.fit_transform(X) arr_desired = X atol = 0.01 * X.shape[1] np.testing.assert_allclose(arr_actual, arr_desired, atol=atol, rtol=0.)
""" import numpy as np import matplotlib.pyplot as plt from pyts.preprocessing import PowerTransformer, QuantileTransformer # 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_power = PowerTransformer().transform(X) X_quantile = QuantileTransformer().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_power[0], 'o--', color='C1', label='PowerTransformer') ax2.plot(X_quantile[0], 'o--', color='C2', label='QuantileTransformer') ax2.set_title('Transformed time series') ax2.legend(loc='best')
def test_actual_results_quantile_transformer_uniform(): """Test that the actual results are the expected ones.""" transformer = QuantileTransformer(n_quantiles=11) arr_actual = transformer.fit_transform(X) arr_desired = [np.linspace(0, 1, 11) for _ in range(3)] np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)
* :class:`pyts.preprocessing.PowerTransformer` * :class:`pyts.preprocessing.QuantileTransformer`. This example illustrates the transformation from both algorithms. """ # Author: Johann Faouzi <*****@*****.**> # License: BSD-3-Clause import matplotlib.pyplot as plt from pyts.datasets import load_gunpoint from pyts.preprocessing import PowerTransformer, QuantileTransformer X, _, _, _ = load_gunpoint(return_X_y=True) n_timestamps = X.shape[1] # Transform the data with different transformation algorithms X_power = PowerTransformer().transform(X) X_quantile = QuantileTransformer(n_quantiles=n_timestamps).transform(X) # Show the results for the first time series plt.figure(figsize=(6, 4)) plt.plot(X[0], '--', label='Original') plt.plot(X_power[0], '--', label='PowerTransformer') plt.plot(X_quantile[0], '--', label='QuantileTransformer') plt.legend(loc='best', fontsize=8) plt.title('Non-linear transformations', fontsize=16) plt.tight_layout() plt.show()