Python数学建模之数据无量纲化处理

您所在的位置:网站首页 无量纲数据怎么弄 Python数学建模之数据无量纲化处理

Python数学建模之数据无量纲化处理

2024-06-05 05:24| 来源: 网络整理| 查看: 265

1.正向化处理

        让正向指标数据(自变量与因变量正相关)压缩在[0,1]范围内。

x{}'=\frac{x-min(x)}{max(x)-min(x)}

2.负向化处理

         让负向指标数据压缩在[0,1]范围内。

x{}'=\frac{max(x)-x}{max(x)-min(x)}

3.归一化处理

        让数据压缩在[0,1]范围内,适用于进行多指标综合评价的时候,不涉及距离度量、协方差计算、数据不符合正态分布的时候。

x{}'=\frac{x-min(x)}{max(x)-min(x)}

Python代码:

import pandas as pd # 读取Excel文件 input_file = 'data.xlsx' data = pd.read_excel(input_file) # 定义函数进行归一化处理 def normalize_column(column): min_value = data[column].min() # 最小值 max_value = data[column].max() # 最大值 data[column] = (data[column] - min_value) / (max_value - min_value) print(f"已对列 {column} 进行归一化处理") # 指定需要进行归一化处理的列 columns_to_normalize = ['Column1', 'Column2', 'Column3'] # 遍历指定的列进行归一化处理 for column in columns_to_normalize: if column in data.columns: normalize_column(column) # 将处理后的数据输出到新的Excel文件 output_file = 'processed_data.xlsx' data.to_excel(output_file, index=False) print(f"处理后的数据已保存到 {output_file} 文件中。") 4.标准化处理

        让数据的平均值为0,标准差为1,适用于聚类、因子分析时。

x{}'=\frac{x-\mu }{\sigma }

5.求和归一化处理

        所有的数据均应该大于0,TOPSIS法常用该处理方式。

x{}'=\frac{x_{i}}{\sum (x_{i})}

6.中心化处理

        让数据平均值变为0,社会科学类研究使用较多,比如进行中介作用,或调节作用研究。

x{}'=x-\mu 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3