当前位置:网站首页>Data analysis series 3 σ Rule / eliminate outliers according to laida criterion

Data analysis series 3 σ Rule / eliminate outliers according to laida criterion

2022-07-07 23:45:00 Lang Xiaolin

1 Related principles
3σ The principle is
The values are distributed in (μ-σ,μ+σ) The probability of 0.6827
The values are distributed in (μ-2σ,μ+2σ) The probability of 0.9545
The values are distributed in (μ-3σ,μ+3σ) The probability of 0.9973
It can be said that ,Y The values of are almost all concentrated in (μ-3σ,μ+3σ) Within the interval , There is no possibility of going beyond that 0.3%.

2 Code implementation

public class Pauta{
     // Create the laida class 
	private double arr[]; // Accept raw array 
	public Pauta(double temp[]) {
     // The original array obtained by the construction method 
		this.arr=temp;
		System.out.print(" The original array :");
		for(double x:arr) {
    
			System.out.print(x+"、");
	}
System.out.println();
}

	public double average() {
     // The arithmetic average method of the original array 
		double sum=0;
		for(int x=0;x<arr.length;x++)
			sum+=arr[x];
			}
	return sum/arr.length;
}

	public double[] residualError() {
    // Residual error method of the original array 
		double rE[]=new double[] {
    };
			for(int x=0;x<arr.length;x++) {
    
			rE[x]=arr[x]-average();
		}
	return rE;
	}

	public double standardVariance() {
    // How to calculate the standard variance value of the original array 
		double sum=0;
		for(int int x=0;x<arr.length;x++) {
    
			sum+=Math.pow(arr[x]-average(),2);
		}
		return Math.sqrt(sum/(arr.length-1));
	}

	public void judge() {
     // How to judge outliers , If abnormal , The output 
		for(int int x=0;x<arr.length;x++) {
    
			if(Math.abs(arr[x]-average())>(3*standardVariance())) {
    
			System.out.println(" The... Th in the array "+(x+1)+" Elements belong to outliers ");
			}
		}
	}
}

public class client{
    
	public static void main(String args[]) {
    
		double data[]=new double[] {
    1,2,8,10,8,5,2,4,6,11,15};// The original array 
		Pauta pau=new Pauta(data);// The original array is output after encapsulation 
		System.out.println(" Count the average :"+pau.average());// Count the average 
		/* The residual error output here is slightly */
		System.out.println(" Standard deviation :"+pau.standardVariance());// Standard deviation 
		pau.judge();// How to judge outliers 
	}
}

Reference material :
https://wenku.baidu.com/view/cce8bacc142ded630b1c59eef8c75fbfc77d9407.html JAVA Use :3σ The rules 、 The procedure of eliminating outliers according to the laida criterion

原网站

版权声明
本文为[Lang Xiaolin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207072113282375.html