How to do it...

The classifier we'll build won't take long, just five steps:

  1. Create the class and its member variables:
using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
 
public class NaiveBayesClassifier : MonoBehaviour 
{ 
    public int numAttributes; 
    public int numExamplesPositive; 
    public int numExamplesNegative; 
 
    public List<bool> attrCountPositive; 
    public List<bool> attrCountNegative; 
} 
  1. Define the Awake method for initialization:
void Awake() 
{ 
    attrCountPositive = new List<bool>(); 
    attrCountNegative = new List<bool>(); 
} 
  1. Implement the function for updating the classifier:
public void UpdateClassifier(bool[] attributes, NBCLabel label) { if (label == NBCLabel.POSITIVE) { numExamplesPositive++; attrCountPositive.AddRange(attributes); ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.