当前位置:网站首页>data normalization
data normalization
2022-07-24 06:10:00 【A little cute C】
Both input and output files are in \t Segmented txt file , Each row is a set of data (xi)
for example
24 42 9 8 3 4 39 43
23 43 5 54 5 32 25 54
52 54 43 53 55 2 5 5
For the first i That's ok ( Each normalized data of this row =( Initial data - Minimum value of this line )/( The maximum value of this line - Minimum value of this line ))
After normalization 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);
}
// obtain ArrayList<Double> dataone Maximum of
public static Double getMax(ArrayList<Double> dataone){
double max = dataone.get(0);
for (Double aDouble : dataone) {
if (max < aDouble) {
max = aDouble;
}
}
return max;
}
// obtain ArrayList<Double> dataone Minimum of
public static Double getMin(ArrayList<Double> dataone){
double min = dataone.get(0);
for (Double aDouble : dataone) {
if (min > aDouble) {
min = aDouble;
}
}
return min;
}
// Read txt File and write 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;
}
// Output
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');
}
}
}
边栏推荐
- day5-jvm
- 顺序栈 C语言 进栈 出栈 遍历
- 使用Keras和LSTM实现对于长期趋势记忆的时间序列预测-LSTNet
- Machine learning (Zhou Zhihua) Chapter 4 notes on learning experience of decision tree
- How to solve the problem of large distribution gap between training set and test set
- The detailed process of connecting MySQL with QT and outputting data to QT window tablewidget.
- 谷歌/火狐浏览器管理后台新增账号时用户名密码自动填入的问题
- 使用Qt连接MySql并创建表号、写入数据、删除数据
- STM32 DSP库MDK VC5\VC6编译错误: 256, (const float64_t *)twiddleCoefF64_256, armBitRevIndexTableF64_256,
- Qt char型转QString型 16进制与char型 转 16进制整型
猜你喜欢

STM32 standard peripheral Library (Standard Library) official website download method, with 2021 latest standard firmware library download link

HoloLens 2 中文开发文档 MRTK v2

机器学习&深度学习 入门资料分享总结

Jestson installs IBus input method

Deepsort summary

Day-7 JVM end

STM32 DSP library MDK vc5\vc6 compilation error: 256, (const float64_t *) twiddlecoeff64_ 256, armBitRevIndexTableF64_ 256,

Machine learning (zhouzhihua) Chapter 5 notes on neural network learning

MySql与Qt连接、将数据输出到QT的窗口tableWidget详细过程。

day3-jvm+排序总结
随机推荐
Solve modularnotfounderror: no module named "cv2.aruco“
Hit the wall record (continuously updated)
JVM系统学习
JUC并发编程基础(8)--读写锁
[MYCAT] related concepts of MYCAT
Accurate calculation of time delay detailed explanation of VxWorks timestamp
信号与系统:希尔伯特变换
Typora 安装包2021年11月最后一次免费版本的安装包下载V13.6.1
单播、组播、广播、工具开发、QT Udp通讯协议开发简介及开发工具源码
STM32 standard peripheral Library (Standard Library) official website download method, with 2021 latest standard firmware library download link
Day3 jvm+ sorting summary
HAL_ Delay() delay error about 1ms
Signals and systems: Hilbert transform
常见AR以及MR头戴显示设备整理
JDBC进阶—— 师承尚硅谷(DAO)
js星星打分效果
Introduction to QT new project
[raspberry pie 4B] VII. Summary of remote login methods for raspberry pie xshell, putty, vncserver, xrdp
Foundation of JUC concurrent programming (1) -- related basic concepts
Machine learning (Zhou Zhihua) Chapter 4 notes on learning experience of decision tree