1# Inference
2Inference is the process of making predictions using an [Estimator](estimator.md). You can think of an estimator *inferring* the outcome of a sample given the input features and the estimator's hidden state obtained during training. Once a learner has been trained it can perform inference on any number of samples.
3
4!!! note
5    As of version 0.3.0, single sample inference methods have been marked internal. As such, you should not rely on their API in your systems. Instead, use the associated dataset inference method with a dataset object containing a single sample.
6
7## Estimator Types
8There are 4 base estimator types to consider in Rubix ML and each type outputs a prediction specific to its type. Meta-estimators are *polymorphic* in the sense that they take on the type of the base estimator they wrap.
9
10| Estimator Type | Prediction | Data Type | Example |
11|---|---|---|---|
12| Classifier | Class label | String | 'cat', 'positive' |
13| Regressor | Number | Integer or Float | 42, 1.348957 |
14| Clusterer | Cluster number | Integer | 0, 15 |
15| Anomaly Detector | 1 for an anomaly or 0 otherwise | Integer | 0, 1 |
16
17## Making Predictions
18All estimators implement the [Estimator](estimator.md) interface which provides the `predict()` method. The `predict()` method takes a dataset of unknown samples and returns their predictions from the model in an array.
19
20!!! note
21    The inference samples must contain the same number and order of feature columns as the samples used to train the learner.
22
23```php
24$predictions = $estimator->predict($dataset);
25
26var_dump($predictions);
27```
28
29```sh
30array(3) {
31  [0]=>
32  string(3) "cat"
33  [1]=>
34  string(3) "dog"
35  [2]=>
36  string(4) "frog"
37}
38```
39
40## Estimation of Probabilities
41Sometimes, you may want to know how *certain* the model is about a particular outcome. Classifiers and clusterers that implement the [Probabilistic](probabilistic.md) interface have the `proba()` method that computes the joint probability estimates for each class or cluster number as shown in the example below.
42
43```php
44$probabilities = $estimator->proba($dataset);
45
46var_dump($probabilities);
47```
48
49```sh
50array(2) {
51	[0] => array(2) {
52		['monster'] => 0.975,
53		['not monster'] => 0.025,
54	}
55	[1] => array(2) {
56		['monster'] => 0.2,
57		['not monster'] => 0.8,
58	}
59}
60```
61
62## Anomaly Scores
63Anomaly detectors that implement the [Scoring](scoring.md) interface can output the anomaly scores assigned to the samples in a dataset. Anomaly scores are useful for attaining the degree of anomalousness for a sample relative to other samples. Higher anomaly scores equate to greater abnormality whereas low scores are typical of normal samples.
64
65```php
66$scores = $estimator->score($dataset);
67
68var_dump($scores);
69```
70
71```sh
72array(3) {
73  [0]=> float(0.35033859096744)
74  [1]=> float(0.40992076925443)
75  [2]=> float(1.68163357834096)
76}
77```
78