The classifier we'll build won't take long, just five steps:
- 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; }
- Define the Awake method for initialization:
void Awake() { attrCountPositive = new List<bool>(); attrCountNegative = new List<bool>(); }
- Implement the function for updating the classifier:
public void UpdateClassifier(bool[] attributes, NBCLabel label) { if (label == NBCLabel.POSITIVE) { numExamplesPositive++; attrCountPositive.AddRange(attributes); ...