def test_min_max_scaler_zero_variance_features(): # Check min max scaler on toy data with zero variance features X = [[0., 1., +0.5], [0., 1., -0.1], [0., 1., +1.1]] X_new = [[+0., 2., 0.5], [-1., 1., 0.0], [+0., 1., 1.5]] # default params scaler = MinMaxScaler() X_trans = scaler.fit_transform(X) X_expected_0_1 = [[0., 0., 0.5], [0., 0., 0.0], [0., 0., 1.0]] assert_array_almost_equal(X_trans, X_expected_0_1) X_trans_inv = scaler.inverse_transform(X_trans) assert_array_almost_equal(X, X_trans_inv) X_trans_new = scaler.transform(X_new) X_expected_0_1_new = [[+0., 1., 0.500], [-1., 0., 0.083], [+0., 0., 1.333]] assert_array_almost_equal(X_trans_new, X_expected_0_1_new, decimal=2) # not default params scaler = MinMaxScaler(feature_range=(1, 2)) X_trans = scaler.fit_transform(X) X_expected_1_2 = [[1., 1., 1.5], [1., 1., 1.0], [1., 1., 2.0]] assert_array_almost_equal(X_trans, X_expected_1_2) # function interface X_trans = minmax_scale(X) assert_array_almost_equal(X_trans, X_expected_0_1) X_trans = minmax_scale(X, feature_range=(1, 2)) assert_array_almost_equal(X_trans, X_expected_1_2)
def MyWavelets(data,MyWidths): Widths = MyWidths ''' 将int型data转为float型sig ''' sig = np.ones(len(data),np.float) #产生空的float型sig for i in range(0,len(data)): sig[i] = float(data[i]) sig = np.array( sig ) wa = WaveletAnalysis(sig, wavelet=Morlet() ) # wavelet power spectrum power = wa.wavelet_power # scales scales = wa.scales # associated time vector t = wa.time # reconstruction of the original data rx = wa.reconstruction() ######################################## # 数据逐帧 0-1标准化 # print(power.shape) # power = np.transpose(power) #转置 power = power.T # print(power.shape) # # power_out = np.array([]) power_out = [] for i in power: # # np.append(power_out, minmax_scale(i), axis = 0) # power_out.append( minmax_scale(i).tolist() ) power_out.append( minmax_scale(i)) # print(max( minmax_scale(i) )) # power_out = np.array(power_out) return power_out
def test_minmax_scale_axis1(): X = iris.data X_trans = minmax_scale(X, axis=1) assert_array_almost_equal(np.min(X_trans, axis=1), 0) assert_array_almost_equal(np.max(X_trans, axis=1), 1)
def minmax_demo(): data = [[2, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]] minmax = minmax_scale(data) print(minmax)
from sklearn.preprocessing.data import minmax_scale import numpy as np X = np.array([[ 10., -1., 4.], [ 2., 0., 5.], [ 0., 0., -1.]]) # min_max_scaler = preprocessing.MinMaxScaler() # X_minMax = min_max_scaler.minmax_scale(X) for i in X: X_minMax = minmax_scale(i) print(X_minMax )