---
title: "PredictorFunction"
language: "en"
type: "Symbol"
summary: "PredictorFunction[...] represents a function generated by Predict that predicts numerical values from data."
keywords: 
- Predictor Function
- Prediction Function
- Predict
- Prediction
- Regression
- Statistical Machine Learning
- Machine Learning
canonical_url: "https://reference.wolfram.com/language/ref/PredictorFunction.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Supervised Machine Learning"
    link: "https://reference.wolfram.com/language/guide/SupervisedMachineLearning.en.md"
  - 
    title: "Scientific Models"
    link: "https://reference.wolfram.com/language/guide/ScientificModels.en.md"
  - 
    title: "Nonparametric Statistical Distributions"
    link: "https://reference.wolfram.com/language/guide/NonparametricStatisticalDistributions.en.md"
related_functions: 
  - 
    title: "Predict"
    link: "https://reference.wolfram.com/language/ref/Predict.en.md"
  - 
    title: "PredictorMeasurements"
    link: "https://reference.wolfram.com/language/ref/PredictorMeasurements.en.md"
  - 
    title: "Information"
    link: "https://reference.wolfram.com/language/ref/Information.en.md"
  - 
    title: "SequencePredictorFunction"
    link: "https://reference.wolfram.com/language/ref/SequencePredictorFunction.en.md"
  - 
    title: "ClassifierFunction"
    link: "https://reference.wolfram.com/language/ref/ClassifierFunction.en.md"
  - 
    title: "NearestFunction"
    link: "https://reference.wolfram.com/language/ref/NearestFunction.en.md"
  - 
    title: "DimensionReducerFunction"
    link: "https://reference.wolfram.com/language/ref/DimensionReducerFunction.en.md"
  - 
    title: "BayesianMinimizationObject"
    link: "https://reference.wolfram.com/language/ref/BayesianMinimizationObject.en.md"
---
# PredictorFunction

PredictorFunction[…] represents a function generated by Predict that predicts numerical values from data.

## Details and Options

* ``PredictorFunction`` works like ``Function``.

* ``PredictorFunction[…][data]`` attempts to predict the value associated with ``data``.

* ``PredictorFunction[…][{data1, data2, …}]`` attempts to predict all the ``datai``.

* ``PredictorFunction[…][data, prop]`` gives the specified property of the prediction associated with ``data``.

* Possible properties applicable to all methods include:

|                |                                                                        |
| -------------- | ---------------------------------------------------------------------- |
| "Decision"     | best prediction according to the distribution and the utility function |
| "Distribution" | distribution of value conditioned on input                             |
| "SHAPValues"   | Shapley additive feature explanations for each example                 |
| "Properties"   | list of all properties available                                       |

* ``"SHAPValues"`` assesses the contribution of features by comparing predictions with different sets of features removed and then synthesized. The option ``MissingValueSynthesis`` can be used to specify how the missing features are synthesized. SHAP explanations are given as deviation from the training output mean. ``"SHAPValues" -> n`` can be used to control the number of samples used for the numeric estimations of SHAP explanations.

* ``PredictorFunction[…][data, …, opts]`` specifies that the predictor should use the options ``opts`` when applied to ``data``.

* Possible options are:

|                         |           |                                                               |
| ----------------------- | --------- | ------------------------------------------------------------- |
| IndeterminateThreshold  | Automatic | below what probability density to return Indeterminate        |
| PerformanceGoal         | Automatic | which aspect of performance to optimize                       |
| MissingValueSynthesis   | Automatic | how to synthesize missing values                              |
| RecalibrationFunction   | Automatic | how to post-process predicted value                           |
| TargetDevice            | "CPU"     | the target device on which to perform training                |
| UtilityFunction         | Automatic | utility expressed as a function of actual and predicted value |

* A ``PredictorFunction[…]`` trained in an older version of the Wolfram Language will still work in the current version.

* ``Predict[FittedModel[…]]`` can be used to convert a fitted model into a ``PredictorFunction[…]``.

* ``Predict[PredictorFunction[…], opts]`` can be used to update the values of ``PerformanceGoal``, ``IndeterminateThreshold``, ``UtilityFunction`` or ``FeatureExtractor`` of the classifier.

* In ``Predict[PredictorFunction[…], FeatureExtractor -> fe]``, the ``FeatureExtractorFunction[…]`` ``fe`` will be prepended to the existing feature extractor.

* ``Information[PredictorFunction[…]]`` generates an information panel about the classifier and its estimated performances.

* ``Information[PredictorFunction[…], prop]`` can be used to obtain specific properties.

* ``Information`` of a ``PredictorFunction[…]`` may include the following properties:

|                          |                                                            |
| ------------------------ | ---------------------------------------------------------- |
| "BatchEvaluationTime"    | marginal time to predict one example when a batch is given |
| "EvaluationTime"         | time needed to predict one example                         |
| "ExampleNumber"          | number of training examples                                |
| "FeatureTypes"           | feature types of the predictor input                       |
| "FunctionMemory"         | memory needed to store the predictor                       |
| "FunctionProperties"     | all prediction properties available for this predictor     |
| "IndeterminateThreshold" | value of IndeterminateThreshold used by the predictor      |
| "LearningCurve"          | performance as function of training set size               |
| "MaxTrainingMemory"      | maximum memory used during training                        |
| "MeanCrossEntropy"       | estimated mean cross entropy of the predictor              |
| "Method"                 | value of Method used by the predictor                      |
| "MethodDescription"      | summary of the method                                      |
| "MethodOption"           | full method option to be reused in a new training          |
| "MethodParameters"       | parameter settings of the method                           |
| "Properties"             | all information properties available for this predictor    |
| "StandardDeviation"      | estimated standard deviation of the predictor              |
| "FeatureExtractor"       | feature extractor as FeatureExtractorFunction              |
| "TrainingLabelMean"      | mean label value seen during training                      |
| "TrainingTime"           | time used by Predict to generate the predictor             |
| "UtilityFunction"        | value of UtilityFunction used by the predictor             |

* ``Information`` properties also include all method suboptions.

---

## Examples (15)

### Basic Examples (2)

Train a ``PredictorFunction`` :

```wl
In[1]:=
trainingData = {1.1 -> 1, 2.2 -> 2.5, 3.3 -> 3, 4.2 -> 5.8, 6.7 -> 9.8};
p = Predict[trainingData]

Out[1]=
PredictorFunction[Association["ExampleNumber" -> 5, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]], 
       "Output" -> As ... " -> DateObject[{2018, 11, 29, 15, 22, 
       2.912121`7.216784404770749}, "Instant", "Gregorian", -8.], "ProcessorCount" -> 4, 
    "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, 
    "Evaluations" -> {}]]]
```

Use the trained ``PredictorFunction`` to predict an output, given some feature:

```wl
In[2]:= p[1.4]

Out[2]= 1.10459
```

Predict multiple examples:

```wl
In[3]:= p[{3.4, 6.6, 8.2}]

Out[3]= {4.2566, 9.29981, 11.8214}
```

Calculate the probability distribution of the predicted value:

```wl
In[4]:= Plot[PDF[p[1.4, "Distribution"], x], {x, -5, 5}, PlotRange -> All, Frame -> True]

Out[4]= [image]
```

---

Generate a ``PredictorFunction`` using multiple features:

```wl
In[1]:=
p = Predict[{
	{1.5, 2.2} -> 1.2, {3.2, 3.5} -> 2.7, {5.3, 19.1} -> 4.2, {7.7, 20.3} -> 5.5}]

Out[1]=
PredictorFunction[Association["ExampleNumber" -> 4, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "NumericalVector", 
           "Lengt ...   "Date" -> DateObject[{2018, 11, 29, 15, 22, 9.60375`7.735015832901325}, "Instant", "Gregorian", 
      -8.], "ProcessorCount" -> 4, "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", 
    "SystemWordLength" -> 64, "Evaluations" -> {}]]]
```

Use the function on a new example:

```wl
In[2]:= p[{1.5, 2.2}]

Out[2]= 2.58093
```

Predict an example that has missing features:

```wl
In[3]:= p[{5.6, Missing[]}]

Out[3]= 3.7522
```

Obtain general information about the predictor:

```wl
In[4]:= Information[p]

Out[4]=
|     |
| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| "Predictor information" |
| \|                           \|                                           \| \| ------------------ ...                   \| \|  "Training time"          \| Quantity[833., "Milliseconds"]            \| |
```

### Scope (6)

Train a ``PredictorFunction`` on textual data:

```wl
In[1]:= p = Predict[{"this is large" -> 7., "this is small" -> -5., "this is tiny and small" -> -10, "this is medium or large" -> 4., "this is large and big" -> 15., "this is small and little" -> -8.}]

Out[1]= PredictorFunction[…]
```

Predict the values of new examples:

```wl
In[2]:= p[{"How large is it?", "Is it small or medium?"}]

Out[2]= {7., 4.}
```

---

Train a ``PredictorFunction`` to recognize the frequency of ``SawtoothWave`` sounds:

```wl
In[1]:=
p = Predict[{Sound[SampledSoundFunction[Function[{Play`Time39}, Block[{t = 0. + 0.000125*Play`Time39}, 
    (SawtoothWave[324.45795035524935*t] - 0.5001160510727303)*2.0031463158766147]], 2400, 8000]] -> 324, Sound[SampledSoundFunction[Function[{Play`Time40}, Block[{t = 0. + 0.000125*Play`Time40}, 
    (SawtoothWave[226.36058426333676*t] - 0.5010053417184481)*2.0069343605226013]], 2400, 8000]] -> 226, Sound[SampledSoundFunction[Function[{Play`Time41}, Block[{t = 0. + 0.000125*Play`Time41}, 
    (SawtoothWave[315.7789342382401*t] - 0.5049934194652432)*2.020583866475329]], 2400, 8000]] -> 316, Sound[SampledSoundFunction[Function[{Play`Time42}, Block[{t = 0. + 0.000125*Play`Time42}, 
    (SawtoothWave[327.59406235471874*t] - 0.49904376688894914)*2.0074978690687044]], 2400, 8000]] -> 328, Sound[SampledSoundFunction[Function[{Play`Time52}, Block[{t = 0. + 0.000125*Play`Time52}, 
    (SawtoothWave[273.0283558209228*t] - 0.4999736167215616)*2.0066458385060892]], 2400, 8000]] -> 273}]

Out[1]= PredictorFunction[…]
```

Predict the values of new examples:

```wl
In[2]:=
test = {Sound[SampledSoundFunction[Function[{Play`Time56}, Block[{t = 0. + 0.000125*Play`Time56}, 
    (SawtoothWave[244.15080360431867*t] - 0.500059985761311)*2.0041296772661803]], 2400, 8000]] -> 244, Sound[SampledSoundFunction[Function[{Play`Time62}, Block[{t = 0. + 0.000125*Play`Time62}, 
    (SawtoothWave[291.9708009764995*t] - 0.5036494453307649)*2.014705247404505]], 2400, 8000]] -> 292};

In[3]:= p[test[[All, 1]]]

Out[3]= {300.5, 300.5}
```

---

Train a ``PredictorFunction`` :

```wl
In[1]:= p = Predict[{1.2, 2, 3.5, 4, 5.2} -> {2.3, 1.2, 5.5, 7.7, 9.9}]

Out[1]= PredictorFunction[…]
```

Generate a ``PredictorMeasurementsObject`` of the function applied to a test set:

```wl
In[2]:= pm = PredictorMeasurements[p, {1.4 -> 2.5, 4.5 -> 8.6, 5.4 -> 10.2, 3.3 -> 3}]

Out[2]= PredictorMeasurementsObject[…]
```

Get the standard deviation of the residuals of the function on the test set:

```wl
In[3]:= pm["StandardDeviation"]

Out[3]= 0.926495
```

Visualize the scatter plot of the test values as a function of the predicted values:

```wl
In[4]:= pm["ComparisonPlot"]

Out[4]= [image]
```

---

Generate a predictor function whose input is an association:

```wl
In[1]:=
p = Predict[{
	<|"variable1" -> 1.2, "variable2" -> 3.1|> -> 0.3, 
	<|"variable1" -> 6.8, "variable2" -> 5.8|> -> 2.3, 
	<|"variable1" -> 8.3|> -> 4.1}]

Out[1]= PredictorFunction[…]
```

Use the function on an example:

```wl
In[2]:= p[<|"variable1" -> 4.5, "variable2" -> 5.5|>]

Out[2]= 2.23333
```

Predict examples containing missing features:

```wl
In[3]:= p[{<|"variable1" -> 3.1|>, <|"variable2" -> 4.6|>, <||>}]

Out[3]= {2.23333, 2.80626, 2.25835}
```

---

Construct a ``Dataset`` with a list of associations:

```wl
In[1]:=
d = Dataset[{<|"age" -> 32, "height" -> 160, "gender" -> "female"|>, 
	<|"height" -> 183, "age" -> 41, "gender" -> "female"|>, 
	<|"height" -> 123, "age" -> 30, "gender" -> "female"|>, 
	<|"height" -> 175, "age" -> 21, "gender" -> "male"|>, 
	<|"height" -> 150, "age" -> 11, "gender" -> "male"|>, 
	<|"age" -> 52, "height" -> 164, "gender" -> "female"|>}]

Out[1]= Dataset[<>]
```

Train a ``PredictorFunction`` to predict the feature ``"age"`` as function of the other features:

```wl
In[2]:= p = Predict[d -> "age"]

Out[2]= PredictorFunction[…]
```

Once the ``PredictorFunction`` is trained, any input format can be used. Predict an example formatted as an association:

```wl
In[3]:= p[<|"height" -> 120, "gender" -> "female"|>]

Out[3]= 29.3218
```

Find out the order of the features, and classify an example formatted as a list:

```wl
In[4]:= Information[p, FeatureNames]

Out[4]= {"height", "gender"}

In[5]:= p[{120, "female"}]

Out[5]= 29.3218
```

Classify examples in a ``Dataset`` :

```wl
In[6]:= dnew = Dataset[{<|"height" -> 120, "gender" -> "female"|>, <|"height" -> 150, "gender" -> "male"|>, <|"height" -> 80, "gender" -> "female"|>}]

Out[6]= Dataset[<>]

In[7]:= p[dnew]

Out[7]= {29.3218, 12.8573, 19.265}
```

---

Load a dataset of wine quality as a function of the wines' physical properties:

```wl
In[1]:= wine = ResourceData["Sample Data: Wine Quality"];
```

Train a predictor to estimate wine quality:

```wl
In[2]:=
p = Predict[wine -> "WineQuality"]
x = KeyDrop[wine, "WineQuality"];

Out[2]= PredictorFunction[«1»]
```

Examine an example bottle:

```wl
In[3]:= bottle = Last[x]

Out[3]=
Dataset[Association["FixedAcidity" -> 6., "VolatileAcidity" -> 0.21, "CitricAcid" -> 0.38, 
  "ResidualSugar" -> 0.8, "Chlorides" -> 0.02, "FreeSulfurDioxide" -> 22., 
  "TotalSulfurDioxide" -> 98., "Density" -> 0.98941, "PH" -> 3.26, "Sulphates" -> 0.32, 
  "Alcohol" -> 11.8]]
```

Predict the example bottle's quality:

```wl
In[4]:= predictedquality = p[bottle]

Out[4]= 6.09044
```

Calculate how much higher or lower this bottle's predicted quality is than the mean:

```wl
In[5]:=
meanquality = Information[p, "TrainingLabelMean"];
predictedquality - meanquality

Out[5]= 0.212532
```

Get an estimation for how much each feature impacted the predictor's output for this bottle:

```wl
In[6]:= impacts = p[bottle, "SHAPValues"]

Out[6]= <|"FixedAcidity" -> 0.0372977, "VolatileAcidity" -> -0.0115963, "CitricAcid" -> 0.0337296, "ResidualSugar" -> -0.207066, "Chlorides" -> 0.0929426, "FreeSulfurDioxide" -> 0.108215, "TotalSulfurDioxide" -> 0.0501292, "Density" -> 0.0744508, "PH" -> 0.0327222, "Sulphates" -> -0.0379025, "Alcohol" -> 0.0396088|>
```

Visualize these feature impacts:

```wl
In[7]:= BarChart[Sort[impacts], ChartLabels -> Placed[Automatic, After], ImageSize -> Medium, BarOrigin -> Left, PlotLabel -> "Impact of Feature on Prediction"]

Out[7]= [image]
```

Confirm that the Shapley values fully explain the predicted quality:

```wl
In[8]:=
Total[impacts]
meanquality + Total[impacts] == predictedquality

Out[8]= 0.212532

Out[8]= True
```

Learn a distribution of the data that treats each feature as independent:

```wl
In[9]:= dist = LearnDistribution[x, Method -> {"Multinormal", "CovarianceType" -> "Diagonal"}]

Out[9]=
LearnedDistribution[Association["ExampleNumber" -> 4898, 
  "Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
    Association["Input" -> Association["FixedAcidity" -> Association["Type" -> "Numerical"], 
       "VolatileAcidity" -> Asso ... n["Quantiles" -> CompressedData["«620»"], 
     "LeftBoundary" -> -1.411857857101751, "LeftScale" -> 0.38626310063157926, 
     "LeftTailNorm" -> 0.022]], "Entropy" -> Around[5.471660028467438, 0.16096729925003606], 
  "EntropySampleSize" -> 500]]
```

Estimate SHAP value feature importance for 100 bottles of wine, using 5 samples for each estimation:

```wl
In[10]:=
winebottles = RandomSample[x, 100];
shaps = p[winebottles, "SHAPValues" -> 5, MissingValueSynthesis -> dist];

Out[10]= {28.7542, Null}
```

Calculate how important each feature is to the model:

```wl
In[11]:= importance = Mean[Abs[shaps]]

Out[11]= <|"FixedAcidity" -> 0.0402703, "VolatileAcidity" -> 0.124879, "CitricAcid" -> 0.0549411, "ResidualSugar" -> 0.0675542, "Chlorides" -> 0.0801382, "FreeSulfurDioxide" -> 0.0849935, "TotalSulfurDioxide" -> 0.0604899, "Density" -> 0.0853172, "PH" -> 0.051762, "Sulphates" -> 0.0377501, "Alcohol" -> 0.288131|>
```

Visualize the model's feature importance:

```wl
In[12]:= BarChart[Sort[importance], ChartLabels -> Placed[Automatic, After], ImageSize -> Medium, BarOrigin -> Left, PlotLabel -> "Average Feature Impact"]

Out[12]= [image]
```

Visualize a nonlinear relationship between a feature's value and its impact on the model's prediction:

```wl
In[13]:= ListPlot[Thread[{Normal[winebottles][[All, "TotalSulfurDioxide"]], shaps[[All, "TotalSulfurDioxide"]]}], AxesLabel -> {"Feature Value", "Feature Impact"}, PlotMarkers -> Automatic]

Out[13]= [image]
```

### Options (7)

#### IndeterminateThreshold (1)

Train a ``PredictorFunction`` :

```wl
In[1]:= p = Predict[{1 -> 0.3, 2 -> 1.4, 3 -> 4.5, 4 -> 6.8}]

Out[1]=
PredictorFunction[Association["ExampleNumber" -> 4, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]], 
       "Output" -> As ... " -> DateObject[{2018, 11, 29, 15, 22, 
       36.946019`8.32014262858112}, "Instant", "Gregorian", -8.], "ProcessorCount" -> 4, 
    "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, 
    "Evaluations" -> {}]]]
```

Visualize the probability density for a given example:

```wl
In[2]:=
example = 2.2;
pdf = PDF[p[example, "Distribution"]]

Out[2]= Function[\[FormalX], 0.651111 E^-1.33187 (-2.58099 + \[FormalX])^2]

In[3]:= Plot[pdf[x], {x, 0, 6}, PlotRange -> All]

Out[3]= [image]
```

The value with the highest probability density is predicted:

```wl
In[4]:= p[example]

Out[4]= 2.58099
```

No prediction is made if the maximum probability density is below a specified threshold:

```wl
In[5]:= p[example, IndeterminateThreshold -> 0.7]

Out[5]= Indeterminate
```

Update the value of the threshold permanently:

```wl
In[6]:= p2 = Predict[p, IndeterminateThreshold -> 0.7]

Out[6]=
PredictorFunction[Association["ExampleNumber" -> 4, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]], 
       "Output" -> As ... " -> DateObject[{2018, 11, 29, 15, 22, 
       36.946019`8.32014262858112}, "Instant", "Gregorian", -8.], "ProcessorCount" -> 4, 
    "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, 
    "Evaluations" -> {}]]]

In[7]:= p2[example]

Out[7]= Indeterminate
```

#### MissingValueSynthesis (1)

Train a predictor with two input features:

```wl
In[1]:=
x = {{1, 3}, {2, 4}, {3, 5}, {4, 4}, {5, 8}, {6, 9}, {7, 4}, {8, 6}, {9, 12}};
y = {2, 4, 5, 4, 6, 7, 4, 5, 9};
p = Predict[x -> y]

Out[1]=
PredictorFunction[Association["ExampleNumber" -> 9, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"], 
         "f2" -> Assoc ...   "Date" -> DateObject[{2021, 4, 9, 18, 22, 24.415184`8.140234984217171}, "Instant", "Gregorian", 
      -4.], "ProcessorCount" -> 6, "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", 
    "SystemWordLength" -> 64, "Evaluations" -> {}]]]
```

Get the prediction for an example that has a missing value:

```wl
In[2]:= p[{5, Missing[]}]

Out[2]= 5.10907
```

Set the missing value synthesis to replace missing variables with their most likely value given known values (which is the default behavior):

```wl
In[3]:= p[{5, Missing[]}, MissingValueSynthesis -> "ModeFinding"]

Out[3]= 5.10907
```

Replace missing variables with random samples conditioned on known values:

```wl
In[4]:= p[{5, Missing[]}, MissingValueSynthesis -> "RandomSampling"]

Out[4]= 3.70258
```

Averaging over many random imputations is usually the best strategy and allows obtaining the uncertainty caused by the imputation:

```wl
In[5]:= MeanAround[Table[p[{5, Missing[]}, MissingValueSynthesis -> "RandomSampling"], 100]]

Out[5]= Around[5.009737917054653, 0.1275219937576369]
```

Specify a learning method during training to control how the distribution of data is learned:

```wl
In[6]:= p = Predict[x -> y, MissingValueSynthesis -> "KernelDensityEstimation"]

Out[6]=
PredictorFunction[Association["ExampleNumber" -> 9, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"], 
         "f2" -> Assoc ...    "Date" -> DateObject[{2021, 4, 9, 18, 23, 57.39158`8.511423154725838}, "Instant", "Gregorian", 
      -4.], "ProcessorCount" -> 6, "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", 
    "SystemWordLength" -> 64, "Evaluations" -> {}]]]
```

Predict an example with missing values using the ``"KernelDensityEstimation"`` distribution to condition values:

```wl
In[7]:= p[{5, Missing[]}]

Out[7]= 4.61036
```

Provide an existing ``LearnedDistribution`` at training to use it when imputing missing values during training and later evaluations:

```wl
In[8]:=
dist = LearnDistribution[x, Method -> "Multinormal"];
p = Predict[x -> y, MissingValueSynthesis -> dist]
p[{5, Missing[]}]

Out[8]=
PredictorFunction[Association["ExampleNumber" -> 9, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"], 
         "f2" -> Assoc ...    "Date" -> DateObject[{2021, 4, 9, 18, 24, 46.087906`8.41616195305408}, "Instant", "Gregorian", 
      -4.], "ProcessorCount" -> 6, "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", 
    "SystemWordLength" -> 64, "Evaluations" -> {}]]]

Out[8]= 5.10798
```

Specify an existing ``LearnedDistribution`` to synthesize missing values for an individual evaluation:

```wl
In[9]:=
dist2 = LearnDistribution[x, Method -> "KernelDensityEstimation"];
p[{5, Missing[]}, MissingValueSynthesis -> dist2]

Out[9]= 4.58529
```

Control both the learning method and the evaluation strategy by passing an association at training:

```wl
In[10]:=
p = Predict[x -> y, MissingValueSynthesis -> 
	<|"LearningMethod" -> "Multinormal", "EvaluationStrategy" -> "RandomSampling"|>];
p[{5, Missing[]}]

Out[10]= 3.24898
```

#### RecalibrationFunction (2)

Train a predictor:

```wl
In[1]:= p = Predict[{1 -> 1.3, 2 -> 2.4, 3 -> 4.4, 4 -> 5.1, 6 -> 7.3}]

Out[1]=
PredictorFunction[Association["ExampleNumber" -> 5, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]], 
       "Output" -> As ... "Date" -> DateObject[{2021, 4, 2, 12, 7, 
       54.066566`8.4855037609736}, "Instant", "Gregorian", 2.], "ProcessorCount" -> 4, 
    "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, 
    "Evaluations" -> {}]]]
```

Compute the prediction:

```wl
In[2]:= p[3.4]

Out[2]= 4.4
```

Compute the predictive distribution:

```wl
In[3]:= p[3.4, "Distribution"]

Out[3]= NormalDistribution[4.4, 1.28374]
```

Temporarily set a recalibration function to apply to the prediction:

```wl
In[4]:= p[3.4, RecalibrationFunction -> (.5# + 0.1&)]

Out[4]= 2.3
```

Compute the predictive distribution with this new recalibration:

```wl
In[5]:= p[3.4, "Distribution", RecalibrationFunction -> (.5# + 0.1&)]

Out[5]= NormalDistribution[2.3, 0.641872]
```

---

Load the Boston Homes dataset:

```wl
In[1]:=
training = RandomSample[ResourceData["Sample Data: Boston Homes", "TrainingData"]];
test = ResourceData["Sample Data: Boston Homes", "TestData"];
```

Train a predictor with model calibration:

```wl
In[2]:= p = Predict[training, Method -> "RandomForest", RecalibrationFunction -> All]

Out[2]= PredictorFunction[«1»]
```

Visualize the comparison plot on a test set:

```wl
In[3]:= PredictorMeasurements[p, test, "ComparisonPlot"]

Out[3]= [image]
```

Remove the recalibration function from the predictor:

```wl
In[4]:= p2 = Predict[p, RecalibrationFunction -> None]

Out[4]= PredictorFunction[«1»]
```

Visualize the new comparison plot:

```wl
In[5]:= PredictorMeasurements[p2, test, "ComparisonPlot"]

Out[5]= [image]
```

#### TargetDevice (1)

Train a predictor using a neural network:

```wl
In[1]:=
trainingData = RandomReal[1, {2000, 4}] -> RandomReal[1, 2000];
predictor = Predict[trainingData, Method -> "NeuralNetwork", TargetDevice -> "GPU"]
```

Evaluate the resulting predictor on system's default GPU and look at its ``AbsoluteTiming`` :

```wl
In[2]:=
n = 10000
AbsoluteTiming[predictor[RandomReal[1, {n, 4}], TargetDevice -> "GPU"];]
```

Compare the previous timing with the one achieved by using the default CPU computation:

```wl
In[3]:= AbsoluteTiming[predictor[RandomReal[1, {n, 4}]];]
```

#### UtilityFunction (1)

Train a predictor function:

```wl
In[1]:= trainingset = {1 -> 1.1, 2 -> 5.5, 3 -> 6.1, 4 -> 7.7, 5 -> 9.2};

In[2]:= p = Predict[trainingset]

Out[2]=
PredictorFunction[Association["ExampleNumber" -> 5, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]], 
       "Output" -> As ...  -> DateObject[{2018, 11, 29, 15, 23, 
       31.487384`8.250711561266273}, "Instant", "Gregorian", -8.], "ProcessorCount" -> 4, 
    "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, 
    "Evaluations" -> {}]]]
```

Visualize the probability density for a given example:

```wl
In[3]:=
example = 2.6;
pdf = PDF[p[example, "Distribution"]]

Out[3]= Function[\[FormalX], 0.370489 E^-0.431222 (-5.19097 + \[FormalX])^2]

In[4]:= Plot[pdf[x], {x, 1, 12}, PlotRange -> All]

Out[4]= [image]
```

By default, the value with the highest probability density is predicted:

```wl
In[5]:= p[example]

Out[5]= 5.19097
```

Define a utility function that penalizes the predicted value's being smaller than the actual value:

```wl
In[6]:= utility[a_, p_] := -Piecewise[{{Exp[p - a], a < p}, {Exp[2 * (a - p)], a ≥ p}}]
```

Plot this function for a given actual value:

```wl
In[7]:= Plot[utility[0, p], {p, -1, 2}]

Out[7]= [image]
```

The predictor decision is now changed despite the probability density's being unchanged:

```wl
In[8]:= p[example, UtilityFunction -> utility]

Out[8]= 5.99991
```

Update the value of the utility function permanently:

```wl
In[9]:= p2 = Predict[p, UtilityFunction -> utility]

Out[9]=
PredictorFunction[Association["ExampleNumber" -> 5, 
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"]], 
       "Output" -> As ...  -> DateObject[{2018, 11, 29, 15, 23, 
       31.487384`8.250711561266273}, "Instant", "Gregorian", -8.], "ProcessorCount" -> 4, 
    "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, 
    "Evaluations" -> {}]]]

In[10]:= p2[example]

Out[10]= 5.91158
```

#### PerformanceGoal (1)

Obtain the built-in ``PredictorFunction`` ``"NameAge"`` :

```wl
In[1]:= p = Predict["NameAge"]

Out[1]=
PredictorFunction[Association[
  "Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
      Association["Output" -> Association["FirstName" -> Association["Type" -> "Text", 
           "Weights" -> 1]], "Preprocessor ... hod" -> "NameAge", "Processor" -> 
     MachineLearning`PackageScope`Preprocessor["Identity"]], "ExampleNumber" -> Missing[], 
  "Prior" -> Automatic, "Utility" -> (DiracDelta[#2 - #1] & ), "Threshold" -> 0.015, 
  "PerformanceGoal" -> Automatic]]
```

Set a custom utility function to use with this predictor:

```wl
In[2]:= utility[a_, p_] := -Piecewise[{{Exp[p - a], a < p}, {Exp[3 * (a - p)], a ≥ p}}]
```

Compute the time required to use an example with this utility function:

```wl
In[3]:= AbsoluteTiming[p["Bob", UtilityFunction -> utility]]

Out[3]= {2.36019, 74.5149}
```

Use ``PerformanceGoal`` to use a faster but less accurate result:

```wl
In[4]:= AbsoluteTiming[p["Bob", UtilityFunction -> utility, PerformanceGoal -> "Speed"]]

Out[4]= {0.071446, 73.1318}
```

## See Also

* [`Predict`](https://reference.wolfram.com/language/ref/Predict.en.md)
* [`PredictorMeasurements`](https://reference.wolfram.com/language/ref/PredictorMeasurements.en.md)
* [`Information`](https://reference.wolfram.com/language/ref/Information.en.md)
* [`SequencePredictorFunction`](https://reference.wolfram.com/language/ref/SequencePredictorFunction.en.md)
* [`ClassifierFunction`](https://reference.wolfram.com/language/ref/ClassifierFunction.en.md)
* [`NearestFunction`](https://reference.wolfram.com/language/ref/NearestFunction.en.md)
* [`DimensionReducerFunction`](https://reference.wolfram.com/language/ref/DimensionReducerFunction.en.md)
* [`BayesianMinimizationObject`](https://reference.wolfram.com/language/ref/BayesianMinimizationObject.en.md)

## Related Guides

* [Supervised Machine Learning](https://reference.wolfram.com/language/guide/SupervisedMachineLearning.en.md)
* [Scientific Models](https://reference.wolfram.com/language/guide/ScientificModels.en.md)
* [Nonparametric Statistical Distributions](https://reference.wolfram.com/language/guide/NonparametricStatisticalDistributions.en.md)

## History

* [Introduced in 2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) \| [Updated in 2018 (11.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn113.en.md) ▪ [2019 (12.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn120.en.md) ▪ [2021 (12.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn123.en.md)