csv file.csv 파일의 단일 추출 된 열의 standard deviation (σ = √ [(Σ (x - 평균)) 2 ÷ n])은 약 45000 개의 인스턴스와 17 개의 속성 ';'로 단장했습니다. 표준 편차를 찾기 위해 Xi의 substact에 대한 while 루프의 모든 반복에서 MEAN 값이 필요합니다. 그래서 나는 MEAN이 표준 편차를 찾기 위해 반복 루프를 반복해야한다고 생각합니다. 그러나 이것을 수행하는 방법을 모르거나이를 수행 할 방법이 있습니다. 여기 붙어있다. 그때 나는 오래된 Xi를 새로운 Xi로 대체하기위한 코드를 사용했다. 새로운 csv 파일을 작성 (생성)하십시오.csv 파일의 표준 편차를 찾았습니다
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.FileWriter;
import java.io.*;
import static java.lang.Math.sqrt;
public class Main {
public static void main(String[] args) throws IOException {
String filename = "ly.csv";
File file = new File(filename);
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter("bank-full_updated.csv"));
}
catch (IOException e) {
}
try {
double Tuple,avg;
double temp;
Tuple = 0;
double stddev=0;
Scanner inputStream = new Scanner(file);
inputStream.next();
while (inputStream.hasNext()) {
String data1 = inputStream.next();
String[] values = data1.split(";");
double Xi = Double.parseDouble(values[1]);
//now finding standard deviation
temp1 += (Xi-MEAN);
// temp2=(temp1*temp1);
// temp3=(temp2/count);
// standard deviation=Math.sqrt(temp3);
Xi=standard deviation * Xi
//now replace new Xi to original values1
values[1] = String.valueOf(Xi);
// iterate through the values and build a string out of them for write a new file
StringBuilder sb = new StringBuilder();
String newData = sb.toString();
for (int i = 0; i < values.length; i++) {
sb.append(values[i]);
if (i < values.length - 1) {
sb.append(";");
}
}
// get the new string
System.out.println(sb.toString());
writer.write(sb.toString()+"\n");
}
writer.close();
inputStream.close();
}
catch (FileNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
이것은 비교적 간단한 수학 문제가 아니라 프로그래밍 문제입니다. 먼저 수학을 이해하십시오 (실제로 이해하는 방식으로). (당신이 참조하는 페이지의 수식이 틀렸다는 것이 확실합니다.) –