数据挖掘-数据标准化 python实现
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了数据挖掘-数据标准化 python实现,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3062字,纯文字阅读大概需要5分钟。
内容图文
![数据挖掘-数据标准化 python实现](/upload/InfoBanner/zyjiaocheng/605/748389b7c3a34e128be487916d1285fb.jpg)
数据挖掘-数据标准化 python实现
- 数据标准化
数据是
[1, 2, 3, 4, 5, 6, 7, 8, 9]
# -*-coding:utf-8-*-
"""
Author: Thinkgamer
Desc:
代码4-1 Python实现标准化方法
"""
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) # 标准差
def Min_Max(self):
arr_ = list()
for x in self.arr:
# round(x,4) 对x保留4位小数
arr_.append(round((x - self.x_min) / (self.x_max - self.x_min), 4))
print("经过Min_Max标准化后的数据为:\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("经过Z_Score标准化后的数据为:\n{}".format(arr_))
# 有点问题,改为如下这样
# 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("经过Decimal Scaling标准化后的数据为:\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("经过Decimal Scaling标准化后的数据为:\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("经过均值标准化后的数据为:\n{}".format(arr_))
def Vector(self):
arr_ = list()
for x in self.arr:
arr_.append(round(x / sum(self.arr), 4))
print("经过向量标准化后的数据为:\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("经过指数转换法(log10)标准化后的数据为;\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("经过指数转换法(SoftMax)标准化后的数据为;\n{}".format(arr_2))
arr_3 = list()
for x in self.arr:
arr_3.append(round(1 / (1 + math.exp(-x)), 4))
print("经过指数转换法(Sigmoid)标准化后的数据为;\n{}".format(arr_3))
if __name__ == "__main__":
dn = DataNorm()
dn.Min_Max()
dn.Z_Score()
dn.DecimalScaling()
dn.Mean()
dn.Vector()
dn.exponential()
- 结果
经过Min_Max标准化后的数据为:
[0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0]
经过Z_Score标准化后的数据为:
[-1.5492, -1.1619, -0.7746, -0.3873, 0.0, 0.3873, 0.7746, 1.1619, 1.5492]
经过Decimal Scaling标准化后的数据为:
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
经过均值标准化后的数据为:
[-0.5, -0.375, -0.25, -0.125, 0.0, 0.125, 0.25, 0.375, 0.5]
经过向量标准化后的数据为:
[0.0222, 0.0444, 0.0667, 0.0889, 0.1111, 0.1333, 0.1556, 0.1778, 0.2]
经过指数转换法(log10)标准化后的数据为;
[0.0, 0.3155, 0.5, 0.6309, 0.7325, 0.8155, 0.8856, 0.9464, 1.0]
经过指数转换法(SoftMax)标准化后的数据为;
[0.0002, 0.0006, 0.0016, 0.0043, 0.0116, 0.0315, 0.0856, 0.2326, 0.6322]
经过指数转换法(Sigmoid)标准化后的数据为;
[0.7311, 0.8808, 0.9526, 0.982, 0.9933, 0.9975, 0.9991, 0.9997, 0.9999]
内容总结
以上是互联网集市为您收集整理的数据挖掘-数据标准化 python实现全部内容,希望文章能够帮你解决数据挖掘-数据标准化 python实现所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。