mincq Package

This documentation was automatically generated using the source code’s included docstrings.

mincq_learner Module

MinCq learning algorithm

Related papers: [1] From PAC-Bayes Bounds to Quadratic Programs for Majority Votes (Laviolette et al., 2011) [2] Risk Bounds for the Majority Vote: From a PAC-Bayesian Analysis to a Learning Algorithm (Germain et al., 2014)

http://graal.ift.ulaval.ca/majorityvote/

class mincq.mincq_learner.MinCqLearner(mu, voters_type, n_stumps_per_attribute=10, kernel='rbf', degree=3, gamma=0.0)[source]

MinCq algorithm learner. See [1, 2]

Parameters:

mu : float

The fixed value of the first moment of the margin.

voters_type : string, optional (default=’kernel’)

Specifies the type of voters. It must be one of ‘kernel’, ‘stumps’.

n_stumps_per_attribute : int, optional (default=10)

Specifies the amount of decision stumps per attribute. It is only significant with ‘stumps’ voters_type.

kernel : string, optional (default=’rbf’)

Specifies the kernel type to be used in the algorithm. It must be one of ‘linear’, ‘poly’, ‘rbf’.

degree : int, optional (default=3)

Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels.

gamma : float, optional (default=0.0)

Kernel coefficient for ‘rbf’ and ‘poly’. If gamma is 0.0 then 1/n_features will be used instead.

Methods

fit(X, y)[source]

Learn a majority vote weights using MinCq.

Parameters:

X : ndarray, shape=(n_samples, n_features)

Training data

y : ndarray, shape=(n_samples,), optional

Training labels

predict(X)[source]

Using previously learned majority vote weights, predict the labels of new data points.

Parameters:

X : ndarray, shape=(n_samples, n_features)

Samples to predict

Returns:

predictions : ndarray, shape=(n_samples,)

The predicted labels

predict_proba(X)[source]

Using previously learned majority vote weights, predict the labels of new data points with a confidence level. The confidence level is the margin of the majority vote.

Parameters:

X : ndarray, shape=(n_samples, n_features)

Samples to predict

Returns:

predictions : ndarray, shape=(n_samples,)

The predicted labels

majority_vote Module

class mincq.majority_vote.MajorityVote(voters, weights=None)[source]

A Majority Vote of real-valued functions.

Parameters:

voters : ndarray of Voter instances

The voters of the majority vote. Each voter must take an example as an input, and output a real value in [-1,1].

weights : ndarray, optional (default: uniform distribution)

The weights associated to each voter.

Attributes

Methods

classification_matrix(X)[source]

Returns the classification matrix of the majority vote.

Parameters:

X : ndarray, shape=(n_samples, n_features)

Input data to classify

Returns:

classification_matrix : ndrray, shape=(n_samples, n_voters)

A matrix that contains the value output by each voter, for each sample.

margin(X)[source]

Returns the margin of the Majority Vote on a list of samples.

Parameters:

X : ndarray, shape=(n_samples, n_features)

Input data to classify.

Returns:

margins : ndarray, shape=(n_samples,), where each value Sis either -1 or 1

The margin of the majority vote for each sample.

vote(X)[source]

Returns the vote of the Majority Vote on a list of samples.

Parameters:

X : ndarray, shape=(n_samples, n_features)

Input data to classify.

Returns:

votes : ndarray, shape=(n_samples,), where each value is either -1 or 1

The vote of the majority vote for each sample.

voters Module

class mincq.voter.BinaryKernelVoter(x, y, kernel_function, **kwargs)[source]

A Binary Kernel Voter, which outputs the value of a kernel function whose first example is fixed a priori. The sign of the output depends on the label (-1 or 1) of the sample on which the kernel voter is based

Parameters:

x : ndarray, shape=(n_features,)

The base sample’s description vector

y : int, -1 or 1

The label of the base sample. Determines if the voter thinks “negative” or “positive”

kernel_function : function

The kernel function takes two samples and returns a similarity value. If the kernel has parameters, they should be set using kwargs parameter

kwargs : keyword arguments (optional)

Additional parameters for the kernel function

Methods

class mincq.voter.DecisionStumpVoter(attribute_index, threshold, direction=1)[source]

Generic Attribute Threshold Binary Classifier

Parameters:

attribute_index : int

The attribute to consider for the classification

threshold : float

The threshold value for classification rule

direction : int (-1 or 1)

Used to reverse classification decision

Methods

class mincq.voter.KernelVotersGenerator(kernel_function, **kwargs)[source]

Utility function to create binary kernel voters for each (x, y) sample.

Parameters:

kernel_function : function

The kernel function takes two samples and returns a similarity value. If the kernel has parameters, they should be set using kwargs parameter

kwargs : keyword arguments (optional)

Additional parameters for the kernel function

Methods

class mincq.voter.StumpsVotersGenerator(n_stumps_per_attribute=10)[source]

Decision Stumps Voters generator.

Parameters:

n_stumps_per_attribute : int, (default=10)

Determines how many decision stumps will be created for each attribute.

Methods

class mincq.voter.Voter[source]

Base class for a voter (function X -> [-1, 1]), where X is an array of samples

Methods

vote(X)[source]

Returns the output of the voter, on a sample list X

Parameters:

X : ndarray, shape=(n_samples, n_features)

Input data to classify

Returns:

votes : ndarray, shape=(n_samples,)

The result the the voter function, for each sample

class mincq.voter.VotersGenerator[source]

Base class to create a set of voters using training samples

Methods

generate(X, y=None, self_complemented=False)[source]

Generates the voters using samples.

Parameters:

X : ndarray, shape=(n_samples, n_features)

Input data on which to base the voters

y : ndarray, shape=(n_samples,), optional

Input labels, usually determines the decision polarity of each voter

self_complemented : bool

Determines if complement voters should be generated or not

Returns:

voters : ndarray

An array of voters