Most estimators have the ability to be trained with data. These estimators are called Learners and require training before they are can make predictions. Training is the process of feeding data to the learner so that it can form a generalized internal function that maps future unknown samples to good predictions.
To train a learner pass it a training dataset:
public train(Dataset $training) : void
Example
$estimator->train($dataset);
Note: Calling the
train()
method on an already trained learner will erase the previous training. If you would like to train a model incrementally, refer to the Online interface.
Return whether or not the learner has been trained:
public trained() : bool
Example
var_dump($estimator->trained());
bool(true)
Predict a single sample and return the result:
public predictSample(array $sample) : mixed
Example
use Rubix\ML\Datasets\Unlabeled;
// Import samples
$dataset = new Unlabeled($samples);
$prediction = $estimator->predictSample($dataset[2]); // Predict the third sample in dataset
var_dump($prediction);
string(3) "cat"