({{, (RefLink[PredictorFunction, paclet:ref/PredictorFunction])[…] 
represents a function generated by (RefLink[Predict, paclet:ref/Predict]) that predicts numerical values from data.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[PredictorFunction, paclet:ref/PredictorFunction]) works like (RefLink[Function, paclet:ref/Function]).

(RefLink[PredictorFunction, paclet:ref/PredictorFunction])[…][data] attempts to predict the value associated with data.

(RefLink[PredictorFunction, paclet:ref/PredictorFunction])[…][{(Subscript[data, 1]),(Subscript[data, 2]),…}] attempts to predict all the (Subscript[data, i]).

(RefLink[PredictorFunction, paclet:ref/PredictorFunction])[…][data,prop] gives the specified property of the prediction associated with data.

Possible properties applicable to all methods include:

(RefLink[PredictorFunction, paclet:ref/PredictorFunction])[…][data,…,opts] specifies that the predictor should use the options opts when applied to data.

Possible options are:

(RefLink[Predict, paclet:ref/Predict])[PredictorFunction[…],opts] can be used to update the values of (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal]), (RefLink[IndeterminateThreshold, paclet:ref/IndeterminateThreshold]), (RefLink[UtilityFunction, paclet:ref/UtilityFunction]) or (RefLink[FeatureExtractor, paclet:ref/FeatureExtractor]) of the classifier.

In (RefLink[Predict, paclet:ref/Predict])[(RefLink[PredictorFunction, paclet:ref/PredictorFunction])[…],FeatureExtractor->fe], the (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction])[…] fe will be prepended to the existing feature extractor.

(RefLink[Information, paclet:ref/Information])[PredictorFunction[…]] generates an information panel about the classifier and its estimated performances.

(RefLink[Information, paclet:ref/Information])[PredictorFunction[…],prop] can be used to obtain specific properties.

(RefLink[Information, paclet:ref/Information]) of a (RefLink[PredictorFunction, paclet:ref/PredictorFunction])[…] may include the following properties:

(RefLink[Information, paclet:ref/Information]) properties also include all method suboptions.

OpenersPrimaryExamplesSection(Spacer1)Examples  (11)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Train a (RefLink[PredictorFunction, paclet:ref/PredictorFunction]):

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

Use the trained (RefLink[PredictorFunction, paclet:ref/PredictorFunction]) to predict an output, given some feature:

p[1.4]

Predict multiple examples:

p[{3.4,6.6,8.2}]

Calculate the probability distribution of the predicted value:

Plot[PDF[p[1.4,"Distribution"],x],{x,-5,5},PlotRange-> All,Frame-> True]

Generate a (RefLink[PredictorFunction, paclet:ref/PredictorFunction]) using multiple features:

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}]

Use the function on a new example:

p[{1.5,2.2}]

Predict an example that has missing features:

p[{5.6,Missing[]}]

Obtain general information about the predictor:

Information[p]

OpenersExampleSection1(Spacer1)Scope  (5)

Train a (RefLink[PredictorFunction, paclet:ref/PredictorFunction]) on textual data:

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.}]

Predict the values of new examples:

p[{"How large is it?", "Is it small or medium?"}]

Train a (RefLink[PredictorFunction, paclet:ref/PredictorFunction]) to recognize the frequency of (RefLink[SawtoothWave, paclet:ref/SawtoothWave]) sounds:

p=Predict[{->324,->226,->316,->328,->273}]

Predict the values of new examples:

test={->244,->292};

p[test[[All,1]]]

Train a (RefLink[PredictorFunction, paclet:ref/PredictorFunction]):

p=Predict[{1.2,2,3.5,4,5.2}->{2.3,1.2,5.5,7.7,9.9}]

Generate a (RefLink[PredictorMeasurementsObject, paclet:ref/PredictorMeasurementsObject]) of the function applied to a test set:

pm=PredictorMeasurements[p,{1.4->2.5,4.5->8.6,5.4->10.2,3.3-> 3}]

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

pm["StandardDeviation"]

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

pm["ComparisonPlot"]

Generate a predictor function whose input is an association:

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

Use the function on an example:

p[<|"variable1"->4.5,"variable2"->5.5|>]

Predict examples containing missing features:

p[{<|"variable1"->3.1|>, <|"variable2"->4.6|> , <||>}]

Construct a (RefLink[Dataset, paclet:ref/Dataset]) with a list of associations:

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"|>}]

Train a (RefLink[PredictorFunction, paclet:ref/PredictorFunction]) to predict the feature "age" as function of the other features:

p=Predict[d->"age"]

Once the (RefLink[PredictorFunction, paclet:ref/PredictorFunction]) is trained, any input format can be used. Predict an example formatted as an association:

p[<|"height"->120,"gender"->"female"|>]

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

PredictorInformation[p, FeatureNames]

p[{120,"female"}]

Classify examples in a (RefLink[Dataset, paclet:ref/Dataset]):

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

p[dnew]

OpenersExampleSection2(Spacer1)Options  (4)

OpenersExampleSubsection0(Spacer1)IndeterminateThreshold  (1)

Train a (RefLink[PredictorFunction, paclet:ref/PredictorFunction]):

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

Visualize the probability density for a given example:

example=2.2;
pdf=PDF[p[example,"Distribution"]]

Plot[pdf[x],{x,0,6},PlotRange->All]

The value with the highest probability density is predicted:

p[example]

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

p[example,IndeterminateThreshold->0.7]

Update the value of the threshold permanently:

p2=Predict[p,IndeterminateThreshold->0.7]

p2[example]

OpenersExampleSubsection1(Spacer1)TargetDevice  (1)

Train a predictor using a neural network:

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 (RefLink[AbsoluteTiming, paclet:ref/AbsoluteTiming]):

n = 10000
AbsoluteTiming[predictor[RandomReal[1,{n,4}],TargetDevice->"GPU"];]

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

AbsoluteTiming[predictor[RandomReal[1,{n,4}]];]

OpenersExampleSubsection2(Spacer1)UtilityFunction  (1)

Train a predictor function:

trainingset={1->1.1,2->5.5,3->6.1,4->7.7,5->9.2};

p=Predict[trainingset]

Visualize the probability density for a given example:

example=2.6;
pdf=PDF[p[example,"Distribution"]]

Plot[pdf[x],{x,1,12},PlotRange->All]

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

p[example]

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

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

Plot this function for a given actual value:

Plot[utility[0,p], {p,-1,2}]

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

p[example,UtilityFunction->utility]

Update the value of the utility function permanently:

p2=Predict[p,UtilityFunction->utility]

p2[example]

OpenersExampleSubsection3(Spacer1)PerformanceGoal  (1)

Obtain the built-in (RefLink[PredictorFunction, paclet:ref/PredictorFunction]) "NameAge":

p=Predict["NameAge"]

Set a custom utility function to use with this predictor:

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:

AbsoluteTiming[p["Bob", UtilityFunction->utility]]

Use (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal]) to use a faster but less accurate result:

AbsoluteTiming[p["Bob",UtilityFunction->utility,PerformanceGoal->"Speed"]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Predict, paclet:ref/Predict])  ▪  (RefLink[PredictorMeasurements, paclet:ref/PredictorMeasurements])  ▪  (RefLink[Information, paclet:ref/Information])  ▪  (RefLink[SequencePredictorFunction, paclet:ref/SequencePredictorFunction])  ▪  (RefLink[ClassifierFunction, paclet:ref/ClassifierFunction])  ▪  (RefLink[NearestFunction, paclet:ref/NearestFunction])  ▪  (RefLink[DimensionReducerFunction, paclet:ref/DimensionReducerFunction])  ▪  (RefLink[BayesianMinimizationObject, paclet:ref/BayesianMinimizationObject])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Machine Learning, paclet:guide/MachineLearning])}, {▪(RefLinkPlain[Scientific Models, paclet:guide/ScientificModels])}, {▪(RefLinkPlain[Nonparametric Statistical Distributions, paclet:guide/NonparametricStatisticalDistributions])}})}})