繁体   English   中英

计算Java中一个标准偏差的数据百分比?

[英]calculating percentage of data in one standard deviation in Java?

我想计算最大值、最小值、平均值、标准偏差和一个标准偏差内的数据百分比,该文件与使用 Java 的目录中已存在的文件相比。 正如你在下面看到的,我找到了最大值、最小值、平均值和标准偏差。 如何在以下代码中获得一个标准偏差内的数据百分比?

 int count = 1;
                int mean = 0;
                int sum = 0;
                int max = Integer.MIN_VALUE;
                int mini = Integer.MAX_VALUE;
                
                double std_deviation = 0;
                double squaresum=0;
                double computationalsum=0;
                int percentage;
                long lines = 0;
                Scanner file = null;
                int number=0;
                
                file_name = JOptionPane.showInputDialog("Enter the data file name:");
                
                try {
                 file = new Scanner (new FileInputStream (file_name));
                
                    }
                catch  (FileNotFoundException e)
                {
                    System.out.println("File not found");
                }
               max = file.nextInt();
               mini = max;
                while (file.hasNextInt()) {
                    number = file.nextInt();
                    
                    squaresum += Math.pow(number, 2);
                    computationalsum += number;
                    if (number > max) {
                        max = number;
                    }
                        else    if (number < mini)
                    {
                        mini = number;
                    }
                    sum += number;
                    count +=1;
                    
        
                }
                file.close();
                mean = sum/count;
                
              // use formula of standard deviation here
               double  sumofsquares = squaresum - ((Math.pow(computationalsum, 2)/(count-1)));
                double ssquared = sumofsquares/(count-1);
                double otherstdev = Math.sqrt(ssquared);
               double minrange = mean - otherstdev;
               double maxrange = mean + otherstdev;
                
             
                
//              calculate the percentage of mean in one stedv
//              while(scanner.hasNextInt()) { int = scanner.nextint() - mean / standard deviation;  if(int > -1 && int < 1) { then: this number is within 1 standard deviation (ie     oneDeviation++;}.......THEN you need to
//              take that counter and divide it by the total number of numbers in the file
//              }
//                for (int i =0; i=> min)
                System.out.println(count);
                System.out.println(mini);
                System.out.println(max);
        
                System.out.println(mean);
                                
               System.out.println(otherstdev);
//             System.out.println(newcount);
               

            }
            else
            {
                JOptionPane.showMessageDialog(null, "Exiting");
                done = true;
            }
        }
        while(!done);
          
  }

    
    
    }

简短的回答,通过计数。

例如,您有以下数据集:

Data value  Frequency
10          17
11          7
12          23
13          4
14          6
15          12
16          21

使用计算器,您发现平均值约为 13.06,标准差约为 2.24。 这意味着一个标准差的范围是从 13.06+2.24 到 13.06-2.24 或 15.3 到 10.8。 您可以简单地计算这两条线之间有多少数据点。

例如,您必须将数字存储在数组中。 最后,您可以遍历数组并检查间隔。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM