The normalized data preprocessing

MATLAB function can directly call mapminmax
Example:
% read matrix A
A = xlsread ( 'D: filename .xlsx');
% normalized matrix
F = mapminmax (A);
% output a normalized matrix F of the
xlswrite ( 'D: a new file name', F)

https://blog.csdn.net/weixin_38706928/article/details/80329563
link with the code

table of Contents

Normalized

Data normalization of Background

MinMaxScaler: normalized to [0,1]

MaxAbsScaler: Normalized to [-1,1]

standardization

To the mean, variance scale

Normalized
data normalized Background
doing cluster analysis before we found clustering effects which are often particularly affected by the impact of a data, making the original plan should be spread over a two-dimensional point, become gathered in point of a line, surprisingly, the clustering effect is certainly not ideal.

Left: after all the data for the cluster property of a scatter plot analysis;

Right: one of which is for the contract amount, and does not scatter plot of normalized data;

Normalization method has two forms, one is the number of fractional turns between the (0,1), one is the dimensionless expression becomes dimensionless expression, become a scalar. Among which is common in the microwave, i.e. circuit analysis, the signal system, the transmission of electromagnetic waves, etc. Physical person will be familiar. And like us ordinary routine data analysts, the less will be the need to meet the situation normalized non-dimensional expressions, and therefore only discuss the situation normalized to [0,1].

Normalized data are generally mapped to the [0,1], but there are normalized to [-1, 1], the two cases may be realized by a method in MaxAbsScaler MinMaxScaler or Python.

MinMaxScaler: normalized to [0,1]
principle

In principle, we noticed a axis = 0, which means MinMaxScaler default method for each column doing normalization operation, which is more in line with practical application.

eg: a data normalized to the [0,1]

from sklearn import preprocessing
import numpy as np

x = np.array([[3., -1., 2., 613.],
[2., 0., 0., 232],
[0., 1., -1., 113],
[1., 2., -3., 489]])

= preprocessing.MinMaxScaler min_max_scaler ()
x_minmax = min_max_scaler.fit_transform (X)
Print (x_minmax)
result:

[[1. 0. 1. 1. ]
[0.66666667 0.33333333 0.6 0.238 ]
[0. 0.66666667 0.4 0. ]
[0.33333333 1. 0. 0.752 ]]

If new test data come in, we want to do the same conversion, then add the new data to the end of the test data to the original

from sklearn import preprocessing
import pandas as pd

min_max_scaler = preprocessing.MinMaxScaler()

= X ([[3., -1., 2., 613.],
[2., of 0. The, of 0. The, 232],
[of 0. The, 1., -1., 113],
[1., 2, -3., 489]]) of the original data #

y = [. 7., 1., -4, 987] # new test data
x.append (y) # x to y to the end of the
Print ( 'x: \ n-', x)
x_minmax = min_max_scaler.fit_transform (X)
Print ( 'x_minmax: \ n-', x_minmax)
the results:

X:
[[3.0, -1.0, 2.0, 613.0], [2.0, 0.0, 0.0, 232], [0.0, 1.0, -1.0, 113], [1.0, 2.0, -3.0, 489], [7.0, 1.0 , -4.0, 987]]
x_minmax:
[[0.42857143 0.57208238 of 0. The 1.]
[.28571429 .33333333 0.66666667 0.13615561]
[of 0. The 0.66666667 of 0. The 0.5]
[0.14285714 1. .16666667 .43020595]
[0.66666667 of 0. The 1. 1.]]
per It features a minimum value becomes 0, the maximum value becomes 1.

MaxAbsScaler: Normalized to [-1,1]
Principle and MinMaxScaler similar,

from sklearn import preprocessing
import numpy as np

np.array = X ([[. 3., -1., 2., 613.],
[2., of 0. The, of 0. The, 232],
[of 0. The, 1., -1., 113],
[ . 1., 2., -3, 489]])
max_abs_scaler = preprocessing.MaxAbsScaler ()
x_train_maxsbs = max_abs_scaler.fit_transform (X)
x_train_maxsbs
result:

Array ([[1., -0.5, 0.66666667, 1.],
[0.66666667, of 0. The, of 0. The, 0.37846656],
[of 0. The, 0.5, -0.33333333, 0.18433931],
[.33333333, 1., -1., 0.79771615]])
If new test data in, and the original table is normalized with:

from sklearn import preprocessing
import pandas as pd

max_abs_scaler = preprocessing.MaxAbsScaler()

= X ([[3., -1., 2., 613.],
[2., of 0. The, of 0. The, 232],
[of 0. The, 1., -1., 113],
[1., 2, -3., 489]]) of the original data #

y = [. 5., 1., -4, 888] # new test data
x.append (Y)
Print ( 'X: \ n-', X)
x_train_maxsbs = max_abs_scaler.fit_transform (X)
Print ( 'x_train_maxsbs: \ n ', x_train_maxsbs)
the results:

x :
[[3.0, -1.0, 2.0, 613.0], [2.0, 0.0, 0.0, 232], [0.0, 1.0, -1.0, 113], [1.0, 2.0, -3.0, 489], [5.0, 1.0, -4.0, 888]]
x_train_maxsbs :
[[ 0.6 -0.5 0.5 0.69031532]
[ 0.4 0. 0. 0.26126126]
[ 0. 0.5 -0.25 0.12725225]
[ 0.2 1. -0.75 0.55067568]
[ 1. 0.5 -1. 1. ]]


Author: Huang engaged in technical analysis package
Source: CSDN
Original: https://blog.csdn.net/weixin_40683253/article/details/81508321
Copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin blog.csdn.net/JiangLongShen/article/details/90443275