({{, (RefLink[ActiveClassification, paclet:ref/ActiveClassification])[f,{(Subscript[conf, 1]),(Subscript[conf, 2]),…}]
gives an object representing the result of active classification obtained by using the function f to determine classes for the example configurations (Subscript[conf, i]). }, {, (RefLink[ActiveClassification, paclet:ref/ActiveClassification])[f,reg]
generates configurations within the region specified by reg.}, {, (RefLink[ActiveClassification, paclet:ref/ActiveClassification])[f,sampler]
generates configurations by applying the function sampler.}, {, (RefLink[ActiveClassification, paclet:ref/ActiveClassification])[f,{(Subscript[conf, 1]),(Subscript[conf, 2]),…}->nsampler]
applies the function nsampler to successively generate configurations starting from one of the (Subscript[conf, i]).}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[ActiveClassification, paclet:ref/ActiveClassification])[…] returns an (RefLink[ActiveClassificationObject, paclet:ref/ActiveClassificationObject])[…] whose properties can be obtained using (RefLink[ActiveClassificationObject, paclet:ref/ActiveClassificationObject])[…]["prop"].

Possible properties include:

Configurations can be of any form accepted by (RefLink[Classify, paclet:ref/Classify]) (single data element, list of data elements, association of data elements, etc.) and of any type accepted by (RefLink[Classify, paclet:ref/Classify]) (numerical, textual, sounds, images, etc.).

When applied to a configuration conf, the output of the function f is interpreted as a label.

In (RefLink[ActiveClassification, paclet:ref/ActiveClassification])[f,spec], spec defines the domain of the function f. A domain can be defined by a list of configurations, a geometric region or a configuration generator function.

In (RefLink[ActiveClassification, paclet:ref/ActiveClassification])[f,sampler], sampler[] must output a configuration suitable for f to be applied to it.

In (RefLink[ActiveClassification, paclet:ref/ActiveClassification])[f,{(Subscript[conf, 1]),(Subscript[conf, 2]),…}->nsampler], nsampler[conf] must output a configuration.

(RefLink[ActiveClassification, paclet:ref/ActiveClassification]) has the same options as (RefLink[Classify, paclet:ref/Classify]), with the following additions and changes:

Possible settings for (RefLink[Method, paclet:ref/Method]) include:

In the form (RefLink[Method, paclet:ref/Method])->assoc, the association can have elements:

Possible settings for (RefLink[RandomSeeding, paclet:ref/RandomSeeding]) include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (12)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Train an (RefLink[ActiveClassificationObject, paclet:ref/ActiveClassificationObject])[…] to classify whether an integer is greater than 50:

aco=ActiveClassification[#>50&,{2,5,58,74,17,29,66,12,90,77}]

Extract the resulting classifier:

c=aco["ClassifierFunction"]

Classify new examples:

c[{35,57,18,100,173,9}]

Train a classification object with the domain defined by an interval:

aco=ActiveClassification[#>5&,Interval[{0, 10}]]

Extract the classifier:

c=aco["ClassifierFunction"]

Classify new examples:

c[{2,7.2,4,6}]

Train a classification object to classify whether a matrix is positive semidefinite, with the domain defined by a configuration generator:

aco=ActiveClassification[PositiveSemidefiniteMatrixQ, RandomReal[1,{2,2}]&]

Extract the classifier:

c=aco["ClassifierFunction"]

Classify new examples:

matrices=Table[RandomReal[1,{2,2}],3];
c/@matrices

OpenersExampleSection1(Spacer1)Scope  (2)

Define a piecewise function with three possible output values:

f[x_]:=Piecewise[{{-1,x<-0.1},{1,x>0.1}},0];

Train a classification object to classify the possible outputs from the function, with the domain defined by a configuration generator:

aco=ActiveClassification[f,RandomReal[{-3, 3}]&]

Obtain the list of object properties:

aco["Properties"]

Obtain the history of explored configurations:

aco["EvaluationHistory"]

Obtain the classifiers trained during the active classification, along with their properties:

aco["TrainingHistory"]

Obtain the final classifier:

c=aco["ClassifierFunction"]

Obtain the method used to choose configurations to add to the training set:

aco["Method"]

Obtain some other properties:

aco[{"OracleFunction","ClassifierMeasurementsObject"}]

Display the performances of the classifiers trained during active classification:

aco["LearningCurve"]

Display the confusion matrix of the final classifier for a test set:

vals=Table[RandomReal[{-3,3}], 200];
testset=#->f[#]&/@vals;
acM=ClassifierMeasurements[c,testset];
acM["ConfusionMatrixPlot"]

Define a function that checks whether a point belongs to a given region, then define a neighborhood configuration generator:

f[point_]:=RegionMember[Disk[],point];

nsampler[point_]:=point+RandomReal[{-.1,.1},2]

Train a classification object to classify whether a point is a member of a given region:

aco=ActiveClassification[f,{{1.0,0.4},{0.3,1.0}}->nsampler]

Display the confusion matrix of the classifier on a test set:

num=RandomPoint[Rectangle[{0,0},{2., 2.}], 100];
testset=#->f[#]&/@num;
acM=ClassifierMeasurements[aco["ClassifierFunction"], testset];
acM["ConfusionMatrixPlot"]

OpenersExampleSection2(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)InitialEvaluationHistory  (1)

Define a function that checks whether the ASCII character corresponding to an integer is a letter, then define a set of configurations:

f[n_]:=If[LetterQ[FromCharacterCode[n]],True,False];
configset=Range[0,1000];

Construct an initial training set:

evalhist =#->f[#]&/@RandomInteger[{0,1000},30]

Train a classification object to classify whether an integer corresponds to a letter by including the preceding information:

aco=ActiveClassification[f,configset,InitialEvaluationHistory->evalhist]

The examples in the first row in the training history now correspond to the initial training set:

aco["TrainingHistory"]

OpenersExampleSubsection1(Spacer1)MaxIterations  (1)

Train a classification object to classify whether a number in a given interval is positive:

aco=ActiveClassification[Positive,Interval[{-2.,2.}]]

Obtain the number of function evaluations:

aco["TrainingHistory"][[-1]]["# Training Examples"]

Specify the maximum number of iterations:

aco2=ActiveClassification[Positive,Interval[{-2.,2.}],MaxIterations->73]

Check the number of function evaluations now:

aco2["TrainingHistory"][[-1]]["# Training Examples"]

Method  (1)

Define a region composed of a number of subregions, and a function that tells whether the blood pressure corresponding to a point in the region is "Low", "Ideal" or "High":

r1=Rectangle[{40,70},{60,90}];
r2=RegionUnion[Rectangle[{40,90},{60,120}], Rectangle[{60,70},{80,120}]]; 
r3=RegionUnion[Rectangle[{40,120},{80,190}], Rectangle[{80,70},{100,190}]];
reg=RegionUnion[r1, r2, r3];

f[{x_,y_}]:=Which[
RegionMember[r1,{x,y}],"Low", 
RegionMember[r2,{x,y}],"Ideal", 
RegionMember[r3,{x,y}],"High", 
True, "Wrong Input"];

Train a classification object by specifying the method:

aco=ActiveClassification[f,reg,Method->"Randomized"]

The configurations are explored randomly, with the data generating distribution:

Show[ListPlot[aco["EvaluationHistory"][[All,"Configuration"]], PlotRange->{{40,100},{60,200}},Frame->True],RegionPlot[{r1, r2, r3}]]

Specify a different method for active classification:

aco2=ActiveClassification[f,reg,Method->"MaxEntropy"]

The algorithm now prefers to explore configurations near the boundaries where the model is more uncertain:

Show[ListPlot[aco2["EvaluationHistory"][[All,"Configuration"]],PlotRange->{{40,100},{60,200}},PlotStyle->Red,Frame->True], RegionPlot[{r1,r2,r3}]]

Specify the method as an association, choosing the evaluation strategy and the classification method:

aco3=ActiveClassification[f,reg,Method-><|"EvaluationStrategy"->"MaxEntropy", "ClassificationMethod"->"NearestNeighbors"|>]

OpenersExampleSection3(Spacer1)Applications  (3)

OpenersExampleSubsection2(Spacer1)Grade Classifier  (1)

Define a "grade function" that gives a letter grade corresponding to a real score between 0 and 10:

f[n_]:=Piecewise[{{ "F",0≤n≤5.},{"C",5<n≤6.},{"B",6<n≤8.}, { "A",8<n≤9.} ,{ "A+",9<n≤10.}}];

Train a classification object to classify letter grades, with the domain specified by a configuration generator:

aco=ActiveClassification[f,RandomReal[{0.,10.}]&]

Obtain the classifier:

c = aco["ClassifierFunction"]

Display the confusion matrix of the classifier on a test set:

realscores=RandomReal[{0, 10}, 70];
testset=#->f[#]&/@realscores;
acM=ClassifierMeasurements[c, testset];
acM["ConfusionMatrixPlot"]

OpenersExampleSubsection3(Spacer1)Region Member Classifier  (1)

Construct a geometric region corresponding to the map of the USA:

regUSA=DiscretizeGraphics[CountryData["USA","Polygon"]]

Define a function that tells whether a point lies inside this region:

f[point_]:=RegionMember[regUSA,point];

Train a classification object for this function:

aco=ActiveClassification[f,Rectangle[{-150,20},{-50,60}],MaxIterations->1500]

Obtain the corresponding classifier:

c=aco["ClassifierFunction"]

Plot the configurations explored during training. The density is higher close to the region boundary:

configurations=aco["EvaluationHistory"][[All,"Configuration"]];

Show[MeshRegion[regUSA],ListPlot[configurations,PlotStyle->Gray]]

Visualize the classification region:

ContourPlot[c[{x,y},"Probability"->True],{x,-150,-50},{y,20,60},ContourShading-> {Gray, Yellow, Orange, Lighter[Green]},AspectRatio->1/2,Contours->3,PlotLegends->Automatic]

OpenersExampleSubsection4(Spacer1)Program Choice Classifier  (1)

Define two programs to compute the (RefLink[ManhattanDistance, paclet:ref/ManhattanDistance]) between two elements:

prog1[l1_,l2_]:=Outer[ManhattanDistance,l1,l2,1];
prog2[l1_,l2_]:=Transpose[(Total/@Transpose[Abs[Transpose[l1]-#]])&/@l2];

Define a function that selects the program that more quickly computes the (RefLink[ManhattanDistance, paclet:ref/ManhattanDistance]) between two elements constructed from the three integers:

f[{n1_,n2_,d_}]:=Module[{list1,list2},
list1=RandomReal[1,{n1,d}];
list2=RandomReal[1,{n2,d}];
If[ First[AbsoluteTiming[prog1[list1,list2]]]>First[AbsoluteTiming[prog2[list1,list2]]],"Program2","Program1"]
];

Set the domain of the function via a configuration generator:

sampler[]:={RandomInteger[{1,100}],RandomInteger[{1,100}],RandomInteger[{1,100}]};

Train a classification object to classify which program is faster:

aco=ActiveClassification[f,sampler]

Obtain the classifier:

c=aco["ClassifierFunction"]

Display the accuracy and confusion matrix of the classifier on a test set:

testset=Module[{r}, 
r=Table[sampler[],1000];
#->f[#]&/@r];
acM=ClassifierMeasurements[c,testset];
acM["Accuracy","Uncertainty"->True] 
acM["ConfusionMatrixPlot"]

OpenersExampleSection4(Spacer1)Possible Issues  (1)

Specifying the domain of the function via a neighborhood configuration generator requires care.

Define a function that checks whether a point belongs to the unit rectangle, then define a neighborhood configuration generator:

f=RegionMember[Rectangle[],#]&;
nsampler[pt_]:=pt+RandomReal[{-.005,.0005},2];

Active classification may not work properly if the initial configuration and neighborhood configuration generator are not chosen properly:

aco=ActiveClassification[f,{{0.5, 0.5}}->nsampler]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Classify, paclet:ref/Classify])  ▪  (RefLink[ActiveClassificationObject, paclet:ref/ActiveClassificationObject])  ▪  (RefLink[BayesianMinimization, paclet:ref/BayesianMinimization])  ▪  (RefLink[BayesianMaximization, paclet:ref/BayesianMaximization])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Machine Learning, paclet:guide/MachineLearning])}})}})