test_class.declarator: log = LoggerFactory.getLogger( NaiveBayesTest.class )
test_class.modifier: static
test_class.original_string: static Logger log = LoggerFactory.getLogger( NaiveBayesTest.class );
test_class.type: Logger
test_class.var_name: log
test_class.file: ml/streaminer/src/test/java/org/streaminer/stream/classifier/bayes/NaiveBayesTest.java
test_class.identifier: NaiveBayesTest
test_case.body: @Test
  	public void testLearn() throws Exception {
              List<Data> dataset = new ArrayList<Data>();
              
              ICsvListReader listReader = new CsvListReader(
                      new FileReader("src/test/resources/golf.csv"), 
                      CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
              
              listReader.getHeader(true);
              
              List<String> list;
              while( (list = listReader.read()) != null ) {
                  Data data = new DataImpl();
                  data.put("outlook", list.get(0));
                  data.put("temperature", Integer.parseInt(list.get(1)));
                  data.put("humidity", Integer.parseInt(list.get(2)));
                  data.put("wind", Boolean.parseBoolean(list.get(3)));
                  data.put("play", list.get(4));
                  
                  dataset.add(data);
              }
  		
              NaiveBayes nb = new NaiveBayes();
              nb.setLabelAttribute( "play" );
              
              
              for (Data data : dataset) {
                  nb.learn( data );
              }
  
  
              Data test = new DataImpl();
              test.put( "outlook", "sunny" );
              test.put( "temperature", "cool" );
              test.put( "humidity", "high" );
              test.put( "windy", "TRUE" );
  
              String prediction = nb.predict( test );
              log.info( "item is: {}", test );
              log.info( "Prediction is: {}", prediction );
  
              test.put( "outlook", "overcast" );
              test.put( "temperature", "mild" );
              test.put( "humidity", "normal" );
              test.put( "windy", "FALSE" );
  
              prediction = nb.predict( test );
              log.info( "item is: {}", test );
              log.info( "Prediction is: {}", prediction );
  
              //  Ein Trainingsbeispiel:  "overcast";"hot";"normal";"FALSE";"yes"
              test.put( "outlook", "overcast" );
              test.put( "temperature", "hot" );
              test.put( "humidity", "normal" );
              test.put( "windy", "FALSE" );
  
              prediction = nb.predict( test );
              log.info( "item is: {}", test );
              log.info( "Prediction is: {}", prediction );
              Assert.assertEquals( "yes", prediction );
  	}
test_case.class_method_signature: NaiveBayesTest.testLearn()
test_case.full_signature: @Test public void testLearn()
test_case.identifier: testLearn
test_case.invocations: getHeader read put get put parseInt get put parseInt get put parseBoolean get put get add setLabelAttribute learn put put put put predict info info put put put put predict info info put put put put predict info info assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testLearn()
focal_class.declarator: serialVersionUID = 1095437834368310484L
focal_class.modifier: private static final
focal_class.original_string: private static final long serialVersionUID = 1095437834368310484L;
focal_class.type: long
focal_class.var_name: serialVersionUID
focal_class.declarator: log = LoggerFactory.getLogger( NaiveBayes.class )
focal_class.modifier: static
focal_class.original_string: static Logger log = LoggerFactory.getLogger( NaiveBayes.class );
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: labelAttribute = null
focal_class.original_string: String labelAttribute = null;
focal_class.type: String
focal_class.var_name: labelAttribute
focal_class.declarator: laplaceCorrection = 0.0001
focal_class.original_string: Double laplaceCorrection = 0.0001;
focal_class.type: Double
focal_class.var_name: laplaceCorrection
focal_class.declarator: confidenceGap = new Double( 0.0d )
focal_class.original_string: Double confidenceGap = new Double( 0.0d );
focal_class.type: Double
focal_class.var_name: confidenceGap
focal_class.declarator: wop = false
focal_class.original_string: Boolean wop = false;
focal_class.type: Boolean
focal_class.var_name: wop
focal_class.declarator: classDistribution = null
focal_class.original_string: Distribution<String> classDistribution = null;
focal_class.type: Distribution<String>
focal_class.var_name: classDistribution
focal_class.declarator: distributions = new HashMap<String,Distribution<?>>()
focal_class.original_string: Map<String,Distribution<?>> distributions = new HashMap<String,Distribution<?>>();
focal_class.type: Map<String,Distribution<?>>
focal_class.var_name: distributions
focal_class.file: ml/streaminer/src/main/java/org/streaminer/stream/classifier/bayes/NaiveBayes.java
focal_class.identifier: NaiveBayes
focal_class.class_method_signature: NaiveBayes.NaiveBayes()
focal_class.full_signature: public  NaiveBayes()
focal_class.identifier: NaiveBayes
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  NaiveBayes()
focal_class.class_method_signature: NaiveBayes.NaiveBayes( String labelAttribute )
focal_class.full_signature: public  NaiveBayes( String labelAttribute )
focal_class.identifier: NaiveBayes
focal_class.modifiers: public
focal_class.parameters: ( String labelAttribute )
focal_class.signature:  NaiveBayes( String labelAttribute )
focal_class.class_method_signature: NaiveBayes.getLabelAttribute()
focal_class.full_signature: public String getLabelAttribute()
focal_class.identifier: getLabelAttribute
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getLabelAttribute()
focal_class.class_method_signature: NaiveBayes.setLabelAttribute(String labelAttribute)
focal_class.full_signature: public void setLabelAttribute(String labelAttribute)
focal_class.identifier: setLabelAttribute
focal_class.modifiers: public
focal_class.parameters: (String labelAttribute)
focal_class.return: void
focal_class.signature: void setLabelAttribute(String labelAttribute)
focal_class.class_method_signature: NaiveBayes.getLaplaceCorrection()
focal_class.full_signature: public Double getLaplaceCorrection()
focal_class.identifier: getLaplaceCorrection
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Double
focal_class.signature: Double getLaplaceCorrection()
focal_class.class_method_signature: NaiveBayes.setLaplaceCorrection(Double laplaceCorrection)
focal_class.full_signature: public void setLaplaceCorrection(Double laplaceCorrection)
focal_class.identifier: setLaplaceCorrection
focal_class.modifiers: public
focal_class.parameters: (Double laplaceCorrection)
focal_class.return: void
focal_class.signature: void setLaplaceCorrection(Double laplaceCorrection)
focal_class.class_method_signature: NaiveBayes.getConfidenceGap()
focal_class.full_signature: public Double getConfidenceGap()
focal_class.identifier: getConfidenceGap
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Double
focal_class.signature: Double getConfidenceGap()
focal_class.class_method_signature: NaiveBayes.setConfidenceGap(Double confidenceGap)
focal_class.full_signature: public void setConfidenceGap(Double confidenceGap)
focal_class.identifier: setConfidenceGap
focal_class.modifiers: public
focal_class.parameters: (Double confidenceGap)
focal_class.return: void
focal_class.signature: void setConfidenceGap(Double confidenceGap)
focal_class.class_method_signature: NaiveBayes.getWop()
focal_class.full_signature: public Boolean getWop()
focal_class.identifier: getWop
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Boolean
focal_class.signature: Boolean getWop()
focal_class.class_method_signature: NaiveBayes.setWop(Boolean wop)
focal_class.full_signature: public void setWop(Boolean wop)
focal_class.identifier: setWop
focal_class.modifiers: public
focal_class.parameters: (Boolean wop)
focal_class.return: void
focal_class.signature: void setWop(Boolean wop)
focal_class.class_method_signature: NaiveBayes.vote(Data item)
focal_class.full_signature: @SuppressWarnings("unchecked") public Map<String,Double> vote(Data item)
focal_class.identifier: vote
focal_class.modifiers: @SuppressWarnings("unchecked") public
focal_class.parameters: (Data item)
focal_class.return: Map<String,Double>
focal_class.signature: Map<String,Double> vote(Data item)
focal_class.class_method_signature: NaiveBayes.predict( Data item )
focal_class.full_signature: @Override public String predict( Data item )
focal_class.identifier: predict
focal_class.modifiers: @Override public
focal_class.parameters: ( Data item )
focal_class.return: String
focal_class.signature: String predict( Data item )
focal_class.class_method_signature: NaiveBayes.getNominalCondition( String attribute, Data item )
focal_class.full_signature: public String getNominalCondition( String attribute, Data item )
focal_class.identifier: getNominalCondition
focal_class.modifiers: public
focal_class.parameters: ( String attribute, Data item )
focal_class.return: String
focal_class.signature: String getNominalCondition( String attribute, Data item )
focal_class.class_method_signature: NaiveBayes.learn(Data item)
focal_class.full_signature: @SuppressWarnings("unchecked") @Override public void learn(Data item)
focal_class.identifier: learn
focal_class.modifiers: @SuppressWarnings("unchecked") @Override public
focal_class.parameters: (Data item)
focal_class.return: void
focal_class.signature: void learn(Data item)
focal_class.class_method_signature: NaiveBayes.getClassDistribution()
focal_class.full_signature: public Distribution<String> getClassDistribution()
focal_class.identifier: getClassDistribution
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Distribution<String>
focal_class.signature: Distribution<String> getClassDistribution()
focal_class.class_method_signature: NaiveBayes.getNumericalDistributions()
focal_class.full_signature: @SuppressWarnings("unchecked") public List<Distribution<Double>> getNumericalDistributions()
focal_class.identifier: getNumericalDistributions
focal_class.modifiers: @SuppressWarnings("unchecked") public
focal_class.parameters: ()
focal_class.return: List<Distribution<Double>>
focal_class.signature: List<Distribution<Double>> getNumericalDistributions()
focal_class.class_method_signature: NaiveBayes.createNominalDistribution()
focal_class.full_signature: public Distribution<String> createNominalDistribution()
focal_class.identifier: createNominalDistribution
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Distribution<String>
focal_class.signature: Distribution<String> createNominalDistribution()
focal_class.class_method_signature: NaiveBayes.createNumericalDistribution()
focal_class.full_signature: public Distribution<Double> createNumericalDistribution()
focal_class.identifier: createNumericalDistribution
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Distribution<Double>
focal_class.signature: Distribution<Double> createNumericalDistribution()
focal_class.superclass: extends AbstractClassifier<Data,String>
focal_method.body: @SuppressWarnings("unchecked")
  	@Override
  	public void learn(Data item) {
  
  		//
  		// determine the label attribute, if not already set
  		//
  		if( labelAttribute == null ){
  			for( String name : item.keySet() )
  				if( name.startsWith( "_class" ) ){
  					labelAttribute = name;
  					break;
  				}
  		}
  
  
  		if( item.get( labelAttribute ) == null ){
  			log.warn( "Not processing unlabeled data item {}", item );
  			return;
  		}
  
  		String clazz = item.get( labelAttribute ).toString();
  		log.debug( "Learning from example with label={}", clazz );
  		if( this.classDistribution == null )
  			this.classDistribution = new NominalDistributionModel<String>(); //this.createNominalDistribution();
  
  
  		if( log.isDebugEnabled() ){
  			log.debug( "Classes: {}", classDistribution.getElements() );
  			for( String t : classDistribution.getElements() )
  				log.debug( "    {}:  {}", t, classDistribution.getCount( t ) );
  		}
  		//
  		// For learning we update the distributions of each attribute
  		//
  		for( String attribute : item.keySet() ){
  
  			if( attribute.equalsIgnoreCase( labelAttribute ) ){
  				//
  				// adjust the class label distribution
  				//
  				classDistribution.update( clazz );
  
  			} else {
  
  				Object obj = item.get( attribute );
  
  				if( obj.getClass().equals( Double.class ) ){
  					Double value = (Double) obj;
  					log.debug( "Handling numerical case ({}) with value  {}", obj, value );
  					//
  					// manage the case of an numerical attribute
  					//
  					Distribution<Double> numDist = (Distribution<Double>) distributions.get( attribute );
  					if( numDist == null ){
  						numDist = this.createNumericalDistribution();
  						log.debug( "Creating new numerical distribution model for attribute {}", attribute );
  						distributions.put( attribute, numDist );
  					}
  					numDist.update( value );
  
  				} else {
  
  					String value = this.getNominalCondition( attribute, item );
  					log.debug( "Handling nominal case for [ {} | {} ]", value, "class=" + clazz );
  
  					//
  					// adapt the nominal distribution for this attribute
  					//
  					Distribution<String> nomDist = (Distribution<String>) distributions.get( clazz );
  					if( nomDist == null ){
  						nomDist = this.createNominalDistribution();
  						log.debug( "Creating new nominal distribution model for attribute {}, {}", attribute, "class=" + clazz );
  						distributions.put( clazz, nomDist );
  					}
  					nomDist.update( value );
  				}
  			}
  		}
  	}
focal_method.class_method_signature: NaiveBayes.learn(Data item)
focal_method.full_signature: @SuppressWarnings("unchecked") @Override public void learn(Data item)
focal_method.identifier: learn
focal_method.invocations: keySet startsWith get warn toString get debug isDebugEnabled debug getElements getElements debug getCount keySet equalsIgnoreCase update get equals getClass debug get createNumericalDistribution debug put update getNominalCondition debug get createNominalDistribution debug put update
focal_method.modifiers: @SuppressWarnings("unchecked") @Override public
focal_method.parameters: (Data item)
focal_method.return: void
focal_method.signature: void learn(Data item)