当前位置:网站首页>数据归一化
数据归一化
2022-07-24 05:20:00 【一枚小可爱c】
输入和输出文件都是以\t分割的txt文件,每一行是一组数据(xi)
例如
24 42 9 8 3 4 39 43
23 43 5 54 5 32 25 54
52 54 43 53 55 2 5 5
对于第i行(该行的每个归一化后的数据=(初始数据-该行最小值)/(该行最大值-该行最小值))
归一化后xij = (xij-min)/(max-min)
import java.io.*;
import java.net.URI;
import java.nio.file.FileSystem;
import java.util.ArrayList;
public class Guiyihua {
public static void main(String[] args) throws Exception {
String oldPath = "C:\\Users\\hong\\Desktop\\electric.txt";
String newPath = "C:\\Users\\hong\\Desktop\\new\\electric.txt";
ArrayList<ArrayList<Double>> data =getFile(oldPath);
double max;
double min;
double temp;
double a;
for (ArrayList<Double> datum : data) {
max = getMax(datum);
min = getMin(datum);
for (int j = 0; j < datum.size(); j++) {
temp =datum.get(j);
a = (temp - min) / (max - min);
datum.set(j,a);
}
}
out(newPath,data);
}
//获取ArrayList<Double> dataone中的最大值
public static Double getMax(ArrayList<Double> dataone){
double max = dataone.get(0);
for (Double aDouble : dataone) {
if (max < aDouble) {
max = aDouble;
}
}
return max;
}
//获取ArrayList<Double> dataone中的最小值
public static Double getMin(ArrayList<Double> dataone){
double min = dataone.get(0);
for (Double aDouble : dataone) {
if (min > aDouble) {
min = aDouble;
}
}
return min;
}
//读取txt文件并且写入ArrayList<ArrayList<Double>>
private static ArrayList<ArrayList<Double>> getFile(String pathName) throws Exception {
File file = new File(pathName);
if (!file.exists())
throw new RuntimeException("Not File!");
BufferedReader br = new BufferedReader(new FileReader(file));
String str;
ArrayList<ArrayList<Double>> data = new ArrayList<>();
while ((str = br.readLine()) != null) {
ArrayList<Double> oneData = new ArrayList<>();
String[] arr = str.split("\t");
for (String s : arr) {
oneData.add(Double.valueOf(s));
}
data.add(oneData);
}
return data;
}
//输出
public static void out(String path,ArrayList<ArrayList<Double>> data) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(path));
for (int i = 0; i <data.size() ; i++) {
for (int j = 0; j < data.get(i).size(); j++) {
writer.write(String.valueOf(data.get(i).get(j)));
writer.write('\t');
}
writer.write('\n');
}
}
}
边栏推荐
- 达梦数据库_触发器、视图、物化视图、序列、同义词、自增列、外部链接等基本的操作
- Logical structure of Oracle Database
- Syntax differences between MySQL and Oracle
- Creation and generation of SVG format map in Heilongjiang Province
- plsql查询数据乱码
- 第五章神经网络
- 如何快速打通CRM系统和ERP系统,实现业务流程自动化流转
- 【数据挖掘】零基础入门决策树
- Problems in SSM project configuration, various dependencies, etc. (for personal use)
- Canal+kafka实战(监听mysql binlog实现数据同步)
猜你喜欢

Multi merchant mall system function disassembly lesson 03 - platform side merchant management

删除分类网络预训练权重的的head部分的权重以及修改权重名称

多商户商城系统功能拆解03讲-平台端商家管理

多商户商城系统功能拆解08讲-平台端商品分类

多商户商城系统功能拆解07讲-平台端商品管理

Flink format series (1) -json

推荐一款完全开源,功能丰富,界面精美的商城系统

likeshop单商户商城系统搭建,代码开源无加密

【mycat】mycat介绍

多商户商城系统功能拆解06讲-平台端商家入驻协议
随机推荐
[vSphere high availability] host failover
Recommend a fully open source, feature rich, beautiful interface mall system
多商户商城系统功能拆解09讲-平台端商品品牌
Problems in SSM project configuration, various dependencies, etc. (for personal use)
公众号开发自定义菜单和服务器配置同时启用
《统计学习方法(第2版)》李航 第16章 主成分分析 PCA 思维导图笔记 及 课后习题答案(步骤详细)PCA 矩阵奇异值 第十六章
达梦数据库_在使用过程中的需要注意的小事项
Zotero快速上手指南
ThreadLocal stores the current login user information
MySQL batch insert demo
likeshop单商户SAAS商城系统搭建,代码开源无加密。
Creation and generation of SVG format map in Heilongjiang Province
《统计学习方法(第2版)》李航 第十三章 无监督学习概论 思维导图笔记
Use streaming media to transfer RSTP to the Web terminal for playback (II) [review]
[virtualization] how to convert virtual machines from workstation to esxi
Flink重启策略
【activiti】组任务
达梦数据库_常用的用户管理命令
Inventory of well-known source code mall systems at home and abroad
Sqlserver completely deleted