日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 标准化_数据标准化

發(fā)布時(shí)間:2024/1/23 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 标准化_数据标准化 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

常見的數(shù)據(jù)標(biāo)準(zhǔn)化方法有以下6種:

1、Min-Max標(biāo)準(zhǔn)化

Min-Max標(biāo)準(zhǔn)化是指對原始數(shù)據(jù)進(jìn)行線性變換,將值映射到[0,1]之間

2、Z-Score標(biāo)準(zhǔn)化

Z-Score(也叫Standard Score,標(biāo)準(zhǔn)分?jǐn)?shù))標(biāo)準(zhǔn)化是指:基于原始數(shù)據(jù)的均值(mean)和標(biāo)準(zhǔn)差(standard deviation)來進(jìn)行數(shù)據(jù)的標(biāo)準(zhǔn)化。

3、小數(shù)定標(biāo)(Decimal scaling)標(biāo)準(zhǔn)化

小數(shù)定標(biāo)標(biāo)準(zhǔn)化是指:通過移動小數(shù)點(diǎn)的位置來進(jìn)行數(shù)據(jù)的標(biāo)準(zhǔn)化。小數(shù)點(diǎn)移動的位數(shù)取決于原始數(shù)據(jù)中的最大絕對值。

4、均值歸一化法

均值歸一化是指:通過原始數(shù)據(jù)中的均值、最大值和最小值來進(jìn)行數(shù)據(jù)的標(biāo)準(zhǔn)化

5、向量歸一化

向量歸一化是指:通過用原始數(shù)據(jù)中的每個值除以所有數(shù)據(jù)之和來進(jìn)行數(shù)據(jù)的標(biāo)準(zhǔn)化

6、指數(shù)轉(zhuǎn)換

指數(shù)轉(zhuǎn)換是指:通過對原始數(shù)據(jù)的值進(jìn)行相應(yīng)的指數(shù)函數(shù)變換來進(jìn)行數(shù)據(jù)的標(biāo)準(zhǔn)化。進(jìn)行指數(shù)轉(zhuǎn)換常見的函數(shù)方法有l(wèi)g函數(shù)、Softmax函數(shù)和Sigmoid函數(shù)

實(shí)例1:實(shí)現(xiàn)數(shù)據(jù)的標(biāo)準(zhǔn)化

要對原始數(shù)據(jù)[1,2,3,4,5,6,7,8,9]進(jìn)行標(biāo)準(zhǔn)化,代碼如下:

"""

Author: Thinkgamer

Desc:

代碼4-1 Python實(shí)現(xiàn)標(biāo)準(zhǔn)化方法

"""

import numpy as np

import math

class DataNorm:

def init(self):

self.arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]

self.x_max = max(self.arr) # 最大值

self.x_min = min(self.arr) # 最小值

self.x_mean = sum(self.arr) / len(self.arr) # 平均值

self.x_std = np.std(self.arr) # 標(biāo)準(zhǔn)差

def Min_Max(self):

arr_ = list()

for x in self.arr:

# round(x,4) 對x保留4位小數(shù)

arr_.append(round((x - self.x_min) / (self.x_max - self.x_min), 4))

print("經(jīng)過Min_Max標(biāo)準(zhǔn)化后的數(shù)據(jù)為:\n{}".format(arr_))

def Z_Score(self):

arr_ = list()

for x in self.arr:

arr_.append(round((x - self.x_mean) / self.x_std, 4))

print("經(jīng)過Z_Score標(biāo)準(zhǔn)化后的數(shù)據(jù)為:\n{}".format(arr_))

# 有點(diǎn)問題,改為如下這樣

# def DecimalScaling(self):

# arr_ = list()

# j = self.x_max // 10 if self.x_max % 10 == 0 else self.x_max // 10 + 1

# for x in self.arr:

# arr_.append(round(x / math.pow(10, j), 4))

# print("經(jīng)過Decimal Scaling標(biāo)準(zhǔn)化后的數(shù)據(jù)為:\n{}".format(arr_))

def DecimalScaling(self):

arr_ = list()

j = 1

x_max = max([abs(one) for one in self.arr])

while x_max / 10 >= 1.0:

j += 1

x_max = x_max / 10

for x in self.arr:

arr_.append(round(x / math.pow(10, j), 4))

print("經(jīng)過Decimal Scaling標(biāo)準(zhǔn)化后的數(shù)據(jù)為:\n{}".format(arr_))

def Mean(self):

arr_ = list()

for x in self.arr:

arr_.append(round((x - self.x_mean) / (self.x_max - self.x_min), 4))

print("經(jīng)過均值標(biāo)準(zhǔn)化后的數(shù)據(jù)為:\n{}".format(arr_))

def Vector(self):

arr_ = list()

for x in self.arr:

arr_.append(round(x / sum(self.arr), 4))

print("經(jīng)過向量標(biāo)準(zhǔn)化后的數(shù)據(jù)為:\n{}".format(arr_))

def exponential(self):

arr_1 = list()

for x in self.arr:

arr_1.append(round(math.log10(x) / math.log10(self.x_max), 4))

print("經(jīng)過指數(shù)轉(zhuǎn)換法(log10)標(biāo)準(zhǔn)化后的數(shù)據(jù)為;\n{}".format(arr_1))

arr_2 = list()

sum_e = sum([math.exp(one) for one in self.arr])

for x in self.arr:

arr_2.append(round(math.exp(x) / sum_e, 4))

print("經(jīng)過指數(shù)轉(zhuǎn)換法(SoftMax)標(biāo)準(zhǔn)化后的數(shù)據(jù)為;\n{}".format(arr_2))

arr_3 = list()

for x in self.arr:

arr_3.append(round(1 / (1 + math.exp(-x)), 4))

print("經(jīng)過指數(shù)轉(zhuǎn)換法(Sigmoid)標(biāo)準(zhǔn)化后的數(shù)據(jù)為;\n{}".format(arr_3))

if name == "main":

dn = DataNorm()

dn.Min_Max()

dn.Z_Score()

dn.DecimalScaling()

dn.Mean()

dn.Vector()

dn.exponential()

在實(shí)現(xiàn)數(shù)據(jù)標(biāo)準(zhǔn)化中,使用round函數(shù)來進(jìn)行小數(shù)后數(shù)據(jù)位數(shù)的保留,如round(x,4)表示的是保留小數(shù)點(diǎn)后4位小數(shù)

總結(jié)

以上是生活随笔為你收集整理的python 标准化_数据标准化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。