Bundle Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.
GaussianNaiveBayes
Gaussian naive Bayes for continuous features and integer class labels. Per class and feature it fits a mean and variance, then classifies by maximum log-joint probability (log prior + sum of log Gaussian likelihoods). Variances are floored for numerical stability.
Example
X := [[1.0], [1.2], [8.0], [8.2]];
y := [[0.0], [0.0], [1.0], [1.0]];
gnb := GaussianNaiveBayes->New();
gnb->Fit(X, y);
classes := gnb->PredictClass([[1.1], [7.9]]); # [0, 1]Operations
Fit #
Fits per-class feature means/variances and class priors. Class labels are the integer values 0..C-1 in the target column; every class in the range must appear at least once.
method : public : Fit(X:Float[,], y:Float[,]) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix (rows=samples, cols=features) |
| y | Float | class labels (integer values stored as Float, rows x 1) |
Return
| Type | Description |
|---|---|
| Bool | true if fitting succeeded |
GetNumClasses #
Gets the number of classes seen at fit time.
method : public : GetNumClasses() ~ IntReturn
| Type | Description |
|---|---|
| Int | class count |
IsFitted #
Whether the model has been fitted.
method : public : IsFitted() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if fitted |
Load # function
Loads a fitted model from a file.
function : Load(filename:String) ~ GaussianNaiveBayesParameters
| Name | Type | Description |
|---|---|---|
| filename | String | file to load from |
Return
| Type | Description |
|---|---|
| GaussianNaiveBayes | fitted model, or Nil on failure |
Predict #
Computes the log-joint probability of each class for every row.
method : public : Predict(X:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix |
Return
| Type | Description |
|---|---|
| Float | rows x classes matrix of log-joint scores, or Nil if not fitted |
PredictClass #
Predicts the most likely class for every row.
method : public : PredictClass(X:Float[,]) ~ Int[]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix |
Return
| Type | Description |
|---|---|
| Int | per-row class ids, or Nil if not fitted |