@ Override public double [ ] getVotesForInstance ( Instance inst ) { // Prepare the results array double [ ] votes = new double [ getNumberOfClasses ( ) ] ; // Over all classes for ( int classIndex = 0 ; classIndex < votes . length ; classIndex ++ ) { // Get the prior for this class votes [ classIndex ] = Math . log ( getPrior ( classIndex ) ) ; // Iterate over the instance attributes for ( int index = 0 ; index < inst . numAttributes ( ) ; index ++ ) { int attributeID = inst . index ( index ) ; // Skip class attribute if ( attributeID == inst . classIndex ( ) ) continue ; Double value = inst . value ( attributeID ) ; // Get the observer for the given attribute GaussianNumericAttributeClassObserver obs = attributeObservers . get ( attributeID ) ; // Init the estimator to null by default GaussianEstimator estimator = null ; if ( obs != null && obs . getEstimator ( classIndex ) != null ) { // Get the estimator estimator = obs . getEstimator ( classIndex ) ; } double valueNonZero ; // The null case should be handled by smoothing! if ( estimator != null ) { // Get the score for a NON-ZERO attribute value valueNonZero = estimator . probabilityDensity ( value ) ; } // We don't have an estimator else { // Assign a very small probability that we do see this value valueNonZero = ADDITIVE_SMOOTHING_FACTOR ; } votes [ classIndex ] += Math . log ( valueNonZero ) ; // - Math.log(valueZero); } // Check for null in the case of prequential evaluation if ( this . classPrototypes . get ( classIndex ) != null ) { // Add the prototype for the class, already in log space votes [ classIndex ] += Math . log ( this . classPrototypes . get ( classIndex ) ) ; } } return votes ; }
Predicts the class memberships for a given instance . If an instance is unclassified the returned array elements will be all zero .