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

📄 aprioritfpclass.java

📁 多关联分类算法
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    if (conversionArray[index][1] >= minSupport) counter++;	    }		// Return		return(counter+numClasses);	}			    /* CREATE TRAINING AND TEST DATA SETS. */    /** Populates test and training datasets. <P> Note: (1) assumes a 50:50     split, (2) training data set is stored in the dataArray structure in which     the input data is stored, (3) method called from application class as same     training and test sets may be required if using (say) "hill climbing"     approach to maximise accuracy, (4) method is not called from constructor    partly for same reason as 3 but also because the input data set may (given     a particular application) first require ordering and possibly also pruning    and recasting (see recastClassifiers method). */    	    public void createTrainingAndTestDataSets() {        // Determine size of training and test sets.	final double PERCENTAGE_SIZE_OF_TEST_SET = 50.0;        numRowsInTestSet     = (int) ((double) numRows*					PERCENTAGE_SIZE_OF_TEST_SET/100.0);	numRowsInTrainingSet = numRows-numRowsInTestSet;	numRows              = numRowsInTrainingSet;				  	// Dimension and populate training set. 	short[][] trainingSet = new short[numRowsInTrainingSet][];	int index1=0;	for (;index1<numRowsInTrainingSet;index1++) 				trainingSet[index1] = dataArray[index1];		// Dimension and populate test set	testDataArray = new short[numRowsInTestSet][];	for (int index2=0;index1<dataArray.length;index1++,index2++) 	 			testDataArray[index2] = dataArray[index1];		// Assign training set label to input data set label.	dataArray = trainingSet;   	}    /** Populates test and training datasets. <P> Note: (1) works on a 9:1    split with nine of the tenths data sets forming the training set and    the remaining one tenth the test set, (2) training data set is stored in     the same dataArray structure in which the initial input data is stored,    (3) this method is not called from the constructor as the input data set may    (given a particular application) first require ordering and possibly also     pruning.     @param testSetIndex the index of the tenths data sets to be used as the     test set. */    	    public void createTrainingAndTestDataSets(int testSetIndex) {        // Dimension and populate test set.        numRowsInTestSet = tenthDataSets[testSetIndex].length;	testDataArray    = tenthDataSets[testSetIndex];        // Dimension of and populate training set.	numRowsInTrainingSet = numRowsInInputSet-numRowsInTestSet;	numRows              = numRowsInTrainingSet;	short[][] trainingSet = new short[numRows][];	int trainingSetIndex=0;		// Before test set	for(int index=0;index<testSetIndex;index++) {	    for (int tenthsIndex=0;tenthsIndex<tenthDataSets[index].length;					tenthsIndex++,trainingSetIndex++) {	        trainingSet[trainingSetIndex] = 					tenthDataSets[index][tenthsIndex];	        }	    }    		// After test set	for(int index=testSetIndex+1;index<tenthDataSets.length;index++) {	    for (int tenthsIndex=0;tenthsIndex<tenthDataSets[index].length;					tenthsIndex++,trainingSetIndex++) {	        trainingSet[trainingSetIndex] = 					tenthDataSets[index][tenthsIndex];	        }	    }		// Assign training set label to input data set label.	dataArray = trainingSet;   	}	    /* CREATE TENTHS DATA SETS. */    /** Populates ten tenths data sets for use when doing Ten Cross Validation    (TCV) --- test and training datasets. <P> Note: this method is not called     from the constructor as the input data set may (given a particular     application) first require ordering (and possibly also pruning!). */    	    public void createTenthsDataSets() {		// If number of rows is less than 10 cannot create appropriate data 	// sets	if (numRows<10) {	    System.out.println("ERROR: only " + numRows + 			", therefore cannot create tenths data sets!");	    System.exit(1);	    }				// Determine size of first nine tenths data sets.	int tenthSize = numRows/10;		// Dimension first nine tenths data sets.	int index=0;	for( ;index<tenthDataSets.length-1;index++)			tenthDataSets[index] = new short[tenthSize][];	// Dimension last tenths data set	tenthDataSets[index] = new short[numRows-(tenthSize*9)][];			// Populate tenth data sets	int inputDataIndex=0;	for(index=0;index<tenthDataSets.length;index++) {	    for(int tenthIndex=0;tenthIndex<tenthDataSets[index].length;	    				tenthIndex++,inputDataIndex++) {	        tenthDataSets[index][tenthIndex] = dataArray[inputDataIndex];		}	    }	}    /* RECONSTRUCT INPUT DATA */    /** Reconstructs the input data set by appending the test set to the    training sets. <P> Note that the training set is stored in the dataArray    2-D short array. */    public void reconstructInputData() {        // Dimension new data sets        short[][] newDataArray = new short[dataArray.length+        					testDataArray.length][];        // Start populating newDataSet with training (data array) set        int newIndex=0;        for (int index=0;index<dataArray.length;index++) {            newDataArray[newIndex] = dataArray[index];            newIndex++;            }        // Complete populating bewData set with test set        for (int index=0;index<testDataArray.length;index++) {            newDataArray[newIndex] = testDataArray[index];            newIndex++;            }        // Assign local reference to global reference        dataArray=newDataArray;        }        		    /*------------------------------------------------------------------- */    /*                                                                    */    /*                             SET METHODS                            */    /*                                                                    */    /*------------------------------------------------------------------- */        /* SET NUM ROWS IN INPUT SET */    /** Assigns value to the <TT>numRowsInInputSet</TT> field. <P> used in    conjunction with TCV to "remember" the overall number of rows in the     input data set. <P> Usually called from application classes. */        public void setNumRowsInInputSet() {        numRowsInInputSet = numRows;	}    /* SET BUM ROWS IN TRAINING SET */    /** Assigns a value equavalent to the number of rows to the number of    rows in training set field. <P> used when the entire data set is    considered as the training set. */    public void setNumRowsInTrainingSet() {        numRowsInTrainingSet = numRows;	}	    /* ---------------------------------------------------------------- */    /*                                                                  */    /*                             GET METHODS                          */    /*                                                                  */    /* ---------------------------------------------------------------- */        /* GET AVERAGE ACCURACY */    /** Gets value for average accuracy field.    @return average accuracy. */       public double getAverageAccuracy() {        return(averageAccuracy);	}	    /* GET ACCURACY */    /** Gets the value of the <TT>accuracyt</TT> field.     @return the accuracy value (%). */        public double getAccuracy() {        return(accuracy);	}	        /* GET AVERAGE NUMBER OF FREQUENT SETS */    /** Gets value for average umber of frequent sets field.    @return averagenumber of frequent sets. */       public double getAverageNumFreqSets() {        return(averageNumFreqSets);	}        /* GET AVERAGE NUMBER OF UPDATES */    /** Gets value for average number of updates field.    @return average number of updates. */       public double getAvergaeNumUpdates() {        return(averageNumUpdates);	}        /* GET AVERAGE NUMBER OF CLASSIFICATION RULES */    /** Gets value for average number of generated classification rules field.    @return average number of classification rules. */       public double getAverageNumCRs() {        return(averageNumCRs);	}	    /* ---------------------------------------------------------------- */    /*                                                                  */    /*                               OUTPUT                             */    /*                                                                  */    /* ---------------------------------------------------------------- */            /* OUTPUT MENU */        /** Outputs menu for command line arguments. (Overides higher level method)    */        protected void outputMenu() {        System.out.println();	System.out.println("-A  = Number of attribute");	System.out.println("-C  = Confidence (default 80%)");	System.out.println("-F  = File name");		System.out.println("-R  = Number of records");	System.out.println("-S  = Support (default 20%)"); 	System.out.println("-N  = Number of classes"); 	System.out.println();		// Exit		System.exit(1);	}        /* OUTPUT SETTINGS */        /** Outputs command line values provided by user. (Overides higher level     method.) */        protected void outputSettings() {        System.out.println("SETTINGS\n--------");	System.out.println("File name                     = " + fileName);		System.out.println("Support (default 20%)         = " + support); 	System.out.println("Confidence (default 80%)      = " + confidence);	System.out.println("Number of classes             = " + numClasses);	System.out.println();        }        /* OUTPUT NUMBER OF CLASSES */        /** Outputs number of classes. */        public void outputNumClasses() {        System.out.println("Number of classes = " + numClasses);	}        /* OUTPUT ACCURACY */        /** Outputs classification accuracy. */        public void outputAccuracy() {        System.out.println("Accuracy = " + twoDecPlaces(accuracy));	}        /* OUTPUT TEST DATA TABLE */        /** Outputs stored input data set read from input data file. */         public void outputTestDataArray() {        for(int index=0;index<testDataArray.length;index++) {	    outputItemSet(testDataArray[index]);	    System.out.println();	    }	}    }    

⌨️ 快捷键说明

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