Learning from Actions and Sequences

Semi-supervised Learning

© Wolfram Research, Inc.

Outline

The case for semi-supervised/active learning

ActiveClassification

ActivePrediction

SequencePredict

Why Semi-supervised Learning

Attempt to use both labeled and unlabeled data for training

Labeling data is expensive or time-consuming—requires domain expertise

Unlabeled data much easier to obtain

Idea is to start with a small set of labeled data and then augment training set with unlabeled samples to improve performance

Why Active Learning

Algorithm is allowed to query the user to label a subset of unlabeled instances.

Iterative—learner requests user to label a select few samples in each iteration; repeated till convergence

By selecting carefully, only a small amount of unlabeled data needs to be labeled to get very good performance

Query strategies: uncertainty sampling, query by committee, randomized sampling, information-based sampling, etc.

Active Classification and Active Prediction

ActiveClassification and ActivePrediction build classifiers and predictors by actively sampling a space

Used to optimize all sorts of meta-algorithms that are built into the Wolfram Language

Syntax

ActiveClassification[f,spacespec], ActivePrediction[f,spacespec]

The best classification/prediction model obtained can be found by using the function f to determine the classes/values for configurations in spacespec.

spacespec: define four types of domains for the function

List of configurations: {(Subscript[conf, 1]), (Subscript[conf, 2]), ...}

Geometric region reg: ConstantRegionQ[reg] must yield True

Configuration generator sampler: sampler[], such that it outputs a configuration to which f can be applied

Initial configuration(s): {(Subscript[conf, 1]), (Subscript[conf, 2]), ...} together with a neighborhood configuration generator {(Subscript[conf, 1]), (Subscript[conf, 2]), ...} → neighborsampler, such that neighborsampler[(Subscript[conf, i])] outputs a configuration to which f can be applied

Configurations conf can be of any type accepted by Classify/Predict: numerical, nominal (categorical), text, sound, images, etc.

function f: arbitrary function—explicit or blackbox

ActivePrediction: f[conf] must yield a real number

ActiveClassification: f[conf] interpreted as a class/label

No symbolic evaluation of f

Output

Output in the form of an “object” that has lots of information

Can query the object for many properties prop

ActiveClassificationObject[...][prop], 
ActivePredictionObject[...][prop]

Active Classification Example

Titanic dataset: Classify the Survival Status of a Passenger

A “Titanic oracle” to determine whether a passenger survived or not:

titanicdataset = RandomSample[ExampleData[{"MachineLearning", "Titanic"}, "TrainingData"]];

RandomSample[titanicdataset,5] //Column

titanicOracle[configuration_]:= titanicdataset[[First[Flatten[Position[titanicdataset[[All,1]],configuration]]],2]]

titanicOracle[{"2nd",23.`,"male"}]

A configuration generator (random sampler for training data) that provides the domain of the oracle function:

samplertitanic[]:= RandomChoice[titanicdataset][[1]];

titanicOracle[samplertitanic[]]

Use ActiveClassification to construct a classifier:

acTitanic= ActiveClassification[titanicOracle,samplertitanic]

Query for the properties of the ActiveClassification object obtained:

acTitanic["Properties"]

Query for the “TrainingHistory”:

acTitanic["TrainingHistory"]

Query for the “ClassifierFunction”:

acT= acTitanic["ClassifierFunction"]

Visualize the “LearningCurve”

acTitanic["LearningCurve"]

Construct a test set and check the “ConfusionMatrixPlot” of the resulting classifier:

titanicTestset = RandomSample[ExampleData[{"MachineLearning", "Titanic"}, "TestData"], 100];
acM= ClassifierMeasurements[acT, titanicTestset];
acM["ConfusionMatrixPlot"]

Active Prediction Example

LogLikelihood Function Predictor

Load Fisher's Iris dataset and divide it into a training set and a test set:

sample=RandomSample[ExampleData[{"MachineLearning","FisherIris"},"Data"]];
trainingsample=sample[[1;;100]];
testsample=sample[[101;;]];

Construct a loglikelihood function that trains a classifier on the training sample and then gives the loglikelihood rate on the test sample for a given choice of the hyperparameters:

f[{l1_,l2_}]:= Module[
	{class},  class = Classify[trainingsample,Method->{"LogisticRegression","L1Regularization"->Exp[l1],"L2Regularization"->Exp[l2]}];
	ClassifierMeasurements[class,testsample,"LogLikelihood"]
];

reg=Rectangle[{-3.,-3.},{3.,3.}];

Train a prediction object to find a predictor for the loglikelihood function over a rectangular domain:

apo=ActivePrediction[f,reg]

Obtain the predictor:

p=apo["PredictorFunction"]

Obtain the coordinates of the explored configurations and their values:

configurations=Join[Normal[apo["EvaluationHistory"][[#,"Configuration"]]], {Normal[apo["EvaluationHistory"][[#,"Value"]]]}]&/@Range[Length[apo["EvaluationHistory"]]];

Visualize the prediction of the predictor together with the explored configurations:

Show[Plot3D[p[{x,y}],{x,-3,3},{y,-3,3},Exclusions->False],ListPointPlot3D[configurations,PlotStyle->{Red,PointSize[Medium]}]]

Sequence Prediction Example

Example of Generative Learning

Train a sequence predictor on a set of sequences

sp=SequencePredict[{{,},{,,},{,,},{,}}]

Predict the next element of a new sequence:

sp[{,}]

Obtain the probabilities of the next element given the sequence:

sp[{,},"Probabilities"]

Predict the most likely following sequence:

sp[{,},"NextSequence"-> 2]

Generate artificial text in the style of a book

text=ExampleData[{"Text","AliceInWonderland"}];

Train a sequence predictor on this book:

spchar=SequencePredict[{text}]

Sample a random string in the book style:

spchar[{"you"},"RandomNextElement"->20]

Train another sequence predictor, interpreting strings as word sequences rather than character sequences:

spword=SequencePredict[{text},FeatureExtractor-> "SegmentedWords"]

Complete the preceding string with 10 consecutive words (spaces and punctuation marks are considered as words):

spword["you","RandomNextElement"->10]

Thank You