⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chi squared testing.txt

📁 多关联分类算法
💻 TXT
字号:
 /* -------------------------------------------- */ 
    /*                                              */ 
    /*              CHI SQUARED TESTING             */ 
    /*                                              */ 
    /* -------------------------------------------- */ 
	     
    /* TEST RULE USING CHI SQUARED TESTING */ 
     
    /** Tests a classification rule with the given parameters to determine  
    the interestingness/surprisingness of the rule. 
    @param supA the support value for the antecedent of the rule.  
    @param supC the support value for the consequent of the rule.  
    @param supAC the support for the rule.  
    @param numR the number of records in the input (training) sets.  
    @return true if Chi squared value is above critical threshold and false 
    otherwise.  */ 
     
    public boolean testRuleUsingChiSquaredTesting(double supA, double supC,  
    					double supAC, double numR) { 
	// Calculate Chi squared value 
	double chiSquaredValue = getChiSquaredValue(supA,supC,supAC,numR);
				 
	// Test Chi Squared value. 
	if (chiSquaredValue>threshold) return(true); 
	else return(false); 
	} 
	 
    /* GET CHI-SQUARED VALUE */ 
         
    /** Calculates and returns the Chi-Squared value for a rule.  
    @param supA the support value for the antecedent of the rule.  
    @param supC the support value for the consequent of the rule.  
    @param supAC the support for the rule.  
    @param numR the number of records in the input (training) sets.  
    @return the Chi squared value.  */ 
     
    private double getChiSquaredValue(double supA, double supC,  
    						double supAC, double numR) { 
	// Set values 
	supAntecedent = supA; 
    	supConsequent = supC; 
    	supRule       = supAC;	 
    	numRecords    = numR; 
    	 
	// Calculate observed and expected values 
	calculateObsValues(); 
	calculateExpValues(); 
	 
	// Calculate and return Chi squared value 
	return(calcChiSquaredValue()); 
	} 
				 
    /* CALCULATE OBSERVED VALUES */ 
     
    /** Calculates observed values for Chi squared testing calculation. */ 
      
    private void calculateObsValues() { 
        obsValues[0]=supRule; 
	obsValues[1]=supAntecedent-supRule; 
	obsValues[2]=supConsequent-supRule; 
	obsValues[3]=numRecords-supAntecedent-supConsequent+supRule; 
	  
	// Calculate additional support values 
	supNotAntecedent=numRecords-supAntecedent; 
    	supNotConsequent=numRecords-supConsequent;
	} 
	 
    /* CALIULASTE EXPECTED VALUES */ 
     
    /** Calculates expected values for Chi squared testing calculation. */ 
      
    private void calculateExpValues() { 
         expValues[0]=(supConsequent*supAntecedent)/numRecords; 
	 expValues[1]=(supNotConsequent*supAntecedent)/numRecords; 
	 expValues[2]=(supConsequent*supNotAntecedent)/numRecords; 
	 expValues[3]=(supNotConsequent*supNotAntecedent)/numRecords;
	 } 
	 
    /* CALCULATE CHI SQUARED VALUE */ 
     
    /** Calculates the Chi squared values and returns their sum. 
    @return the sum of the Chi Squared values. */  
     
    private double calcChiSquaredValue() { 
        double sumChiSquaredValues = 0.0; 
	 
	for (int index=0;index<obsValues.length;index++) { 
	    double chiValue = Math.pow((obsValues[index]- 
	    			    expValues[index]),2.0)/expValues[index]; 
	    sumChiSquaredValues = sumChiSquaredValues+chiValue; 
	    } 
	 
	// Return
	return(sumChiSquaredValues); 
	} 
		 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -