Naive Bayes
Naive Bayes is a model based on Bayes' Theorem, which uses probabilities to perform classifications. It assumes that the features of the data are independent of each other, which simplifies calculations and makes the model fast and efficient. Although this assumption of independence is not always true, Naive Bayes performs well in many practical problems, such as text classification and spam filtering. Its performance is particularly notable in applications where data can be interpreted probabilistically.
The model training is fast, and after training, the dataset is not required to make predictions. It is possible to save and import the finalized training in an extremely lightweight file.
EXAMPLE OF USE
CLASSES AND METHODS GUIDE
TGaussianNaiveBayes
FDataset : TAIDatasetClassification; : access the current database contained in the model.
procedure ClearDataset; : cleans the dataset.
constructor Create; : creates a new object to be trained.
constructor Create(aTrainedFile : String); overload; : creates the object by loading the structure from an already trained file.
procedure Train(aTrainingData : String; aHasHeader : Boolean = True); overload; : performs the training with the provided data.
aTrainingData : CSV file path.
aHasHeader : indicates whether the file has a header.
procedure Train(aTrainingData : TDataSet); overload; : performs the training and generates the nodes based on the provided data.
aTrainingData : TDataSet object that contains the data that will be used for training.
function Predict(aSample: TArray<Double>; aInputNormalized : Boolean = False): String; : predicts the best category for the sample.
aSample : sample to be analyzed.
aInputNormalized : it should be set to true only if the input data has already been normalized outside the component (which should be done using the range saved in the object).
procedure LoadFromFile(const FileName: string); : loads the trained file.
procedure SaveToFile(const FileName: string); : saves the trained file.
Last updated