Python API

This section includes information for using the pure Python API of bob.learn.linear.

Classes

Database specifications for an evaluation protocol based on the Iris Flower databases from Fisher’s original work.

rr.database.split_data(data, subset, splits)[source]

Returns the data for a given protocol

rr.database.get(protocol, subset, classes=['setosa', 'versicolor', 'virginica'], variables=['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width'])[source]

Returns the data subset given a particular protocol

Parameters

protocol (string): one of the valid protocols supported by this interface

subset (string): one of ‘train’ or ‘test’

classes (list of string): a list of strings containing the names of the
classes from which you want to have the data from
variables (list of strings): a list of strings containg the names of the
variables (features) you want to have data from

Returns:

data (numpy.ndarray): The data for all the classes and variables nicely
packed into one numpy 3D array. One depth represents the data for one class, one row is one example, one column a given feature.

A simple pre-processing that applies Z-normalization to the input features

rr.preprocessor.estimate_norm(X)[source]

Estimates the mean and standard deviation from a data set

Parameters:

X (numpy.ndarray): A 2D numpy ndarray in which the rows represent examples
while the columns, features of the data you want to estimate normalization parameters on

Returns:

numpy.ndarray: A 1D numpy ndarray containing the estimated mean over
dimension 1 (columns) of the input data X
numpy.ndarray: A 1D numpy ndarray containing the estimated unbiased
standard deviation over dimension 1 (columns) of the input data X
rr.preprocessor.normalize(X, norm)[source]

Applies the given norm to the input data set

Parameters:

X (numpy.ndarray): A 3D numpy ndarray in which the rows represent examples
while the columns, features of the data set you want to normalize. Every depth corresponds to data for a particular class
norm (tuple): A tuple containing two 1D numpy ndarrays corresponding to the
normalization parameters extracted with estimated_norm() above.

Returns:

numpy.ndarray: A 3D numpy ndarray with the same dimensions as the input
array X, but with its values normalized according to the norm input.
rr.algorithm.make_labels(X)[source]

Helper function that generates a single 1D numpy.ndarray with labels which are good targets for stock logistic regression.

Parameters:

X (numpy.ndarray): The input data matrix. This must be a numpy.ndarray
with 3 dimensions or an iterable containing 2 numpy.ndarrays with 2 dimensions each. Each correspond to the data for one of the two classes, every row corresponds to one example of the data set, every column, one different feature.

Returns:

numpy.ndarray: With a single dimension, containing suitable labels for all
rows and for all classes defined in X (depth).
rr.algorithm.add_bias(X)[source]

Helper function to add a bias column to the input array X

Parameters:

X (numpy.ndarray): The input data matrix. This must be a numpy.ndarray
with 2 dimension wheres every row corresponds to one example of the data set, every column, one different feature.

Returns:

numpy.ndarray: The same input matrix X with an added (prefix) column of
ones.
class rr.algorithm.MultiClassMachine(machines)[source]

A class to handle all run-time aspects for Multiclass Log. Regression

Parameters:

machines (iterable): An iterable over any number of machines that will be
stored.
predict(X)[source]

Predicts the class of each row of X

Parameters:

X (numpy.ndarray): The input data matrix. This must be a numpy.ndarray
with 3 dimensions or an iterable containing 2 numpy.ndarrays with 2 dimensions each. Each correspond to the data for one of the two classes, every row corresponds to one example of the data set, every column, one different feature.

Returns:

numpy.ndarray: A 1D numpy.ndarray with as many entries as rows in the
input 2D array X, representing g(x), the class predictions for the current machine.
class rr.algorithm.MultiClassTrainer(regularizer=0.0)[source]

A class to handle all training aspects for Multiclass Log. Regression

Parameters:

regularizer (float): A regularization parameter
train(X)[source]

Trains multiple logistic regression classifiers to handle the multiclass problem posed by X

X (numpy.ndarray): The input data matrix. This must be a numpy.ndarray
with 3 dimensions or an iterable containing 2 numpy.ndarrays with 2 dimensions each. Each correspond to the data for one of the input classes, every row corresponds to one example of the data set, every column, one different feature.

Returns:

Machine: A trained multiclass machine.
rr.analysis.CER(prediction, true_labels)[source]

Calculates the classification error rate for an N-class classification problem

Parameters:

prediction (numpy.ndarray): A 1D numpy.ndarray containing your
prediction
true_labels (numpy.ndarray): A 1D numpy.ndarray
containing the ground truth labels for the input array, organized in the same order.

Table Of Contents

Previous topic

Documentation Tests

This Page