Package mdp :: Package nodes :: Class RANSACRegressorScikitsLearnNode
[hide private]
[frames] | no frames]

Class RANSACRegressorScikitsLearnNode



RANSAC (RANdom SAmple Consensus) algorithm.

This node has been automatically generated by wrapping the ``sklearn.linear_model.ransac.RANSACRegressor`` class
from the ``sklearn`` library.  The wrapped instance can be accessed
through the ``scikits_alg`` attribute.

RANSAC is an iterative algorithm for the robust estimation of parameters
from a subset of inliers from the complete data set. More information can
be found in the general documentation of linear models.

A detailed description of the algorithm can be found in the documentation
of the ``linear_model`` sub-package.

Read more in the :ref:`User Guide <ransac_regression>`.

**Parameters**

base_estimator : object, optional
    Base estimator object which implements the following methods:


     * `fit(X, y)`: Fit model to given training data and target values.
     * `score(X, y)`: Returns the mean accuracy on the given test data,
       which is used for the stop criterion defined by `stop_score`.
       Additionally, the score is used to decide which of two equally
       large consensus sets is chosen as the better one.

    If `base_estimator` is None, then
    ``base_estimator=sklearn.linear_model.LinearRegression()`` is used for
    target values of dtype float.

    Note that the current implementation only supports regression
    estimators.

min_samples : int (>= 1) or float ([0, 1]), optional
    Minimum number of samples chosen randomly from original data. Treated
    as an absolute number of samples for `min_samples >= 1`, treated as a
    relative number `ceil(min_samples * X.shape[0]`) for
    `min_samples < 1`. This is typically chosen as the minimal number of
    samples necessary to estimate the given `base_estimator`. By default a
    ``sklearn.linear_model.LinearRegression()`` estimator is assumed and
    `min_samples` is chosen as ``X.shape[1] + 1``.

residual_threshold : float, optional
    Maximum residual for a data sample to be classified as an inlier.
    By default the threshold is chosen as the MAD (median absolute
    deviation) of the target values `y`.

is_data_valid : callable, optional
    This function is called with the randomly selected data before the
    model is fitted to it: `is_data_valid(X, y)`. If its return value is
    False the current randomly chosen sub-sample is skipped.

is_model_valid : callable, optional
    This function is called with the estimated model and the randomly
    selected data: `is_model_valid(model, X, y)`. If its return value is
    False the current randomly chosen sub-sample is skipped.
    Rejecting samples with this function is computationally costlier than
    with `is_data_valid`. `is_model_valid` should therefore only be used if
    the estimated model is needed for making the rejection decision.

max_trials : int, optional
    Maximum number of iterations for random sample selection.

stop_n_inliers : int, optional
    Stop iteration if at least this number of inliers are found.

stop_score : float, optional
    Stop iteration if score is greater equal than this threshold.

stop_probability : float in range [0, 1], optional
    RANSAC iteration stops if at least one outlier-free set of the training
    data is sampled in RANSAC. This requires to generate at least N
    samples (iterations)::


        N >= log(1 - probability) / log(1 - e**m)

    where the probability (confidence) is typically set to high value such
    as 0.99 (the default) and e is the current fraction of inliers w.r.t.
    the total number of samples.

residual_metric : callable, optional
    Metric to reduce the dimensionality of the residuals to 1 for
    multi-dimensional target values ``y.shape[1] > 1``. By default the sum
    of absolute differences is used::


        lambda dy: np.sum(np.abs(dy), axis=1)

random_state : integer or numpy.RandomState, optional
    The generator used to initialize the centers. If an integer is
    given, it fixes the seed. Defaults to the global numpy random
    number generator.

**Attributes**

``estimator_`` : object
    Best fitted model (copy of the `base_estimator` object).

``n_trials_`` : int
    Number of random selection trials until one of the stop criteria is
    met. It is always ``<= max_trials``.

``inlier_mask_`` : bool array of shape [n_samples]
    Boolean mask of inliers classified as ``True``.

**References**

.. [1] http://en.wikipedia.org/wiki/RANSAC
.. [2] http://www.cs.columbia.edu/~belhumeur/courses/compPhoto/ransac.pdf
.. [3] http://www.bmva.org/bmvc/2009/Papers/Paper355/Paper355.pdf

Instance Methods [hide private]
 
__init__(self, input_dim=None, output_dim=None, dtype=None, **kwargs)
RANSAC (RANdom SAmple Consensus) algorithm.
 
_execute(self, x)
 
_get_supported_dtypes(self)
Return the list of dtypes supported by this node. The types can be specified in any format allowed by numpy.dtype.
 
_stop_training(self, **kwargs)
Concatenate the collected data in a single array.
 
execute(self, x)
Predict using the estimated model.
 
stop_training(self, **kwargs)
Fit estimator using RANSAC algorithm.

Inherited from unreachable.newobject: __long__, __native__, __nonzero__, __unicode__, next

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

    Inherited from Cumulator
 
_train(self, *args)
Collect all input data in a list.
 
train(self, *args)
Collect all input data in a list.
    Inherited from Node
 
__add__(self, other)
 
__call__(self, x, *args, **kwargs)
Calling an instance of Node is equivalent to calling its execute method.
 
__repr__(self)
repr(x)
 
__str__(self)
str(x)
 
_check_input(self, x)
 
_check_output(self, y)
 
_check_train_args(self, x, *args, **kwargs)
 
_get_train_seq(self)
 
_if_training_stop_training(self)
 
_inverse(self, x)
 
_pre_execution_checks(self, x)
This method contains all pre-execution checks.
 
_pre_inversion_checks(self, y)
This method contains all pre-inversion checks.
 
_refcast(self, x)
Helper function to cast arrays to the internal dtype.
 
_set_dtype(self, t)
 
_set_input_dim(self, n)
 
_set_output_dim(self, n)
 
copy(self, protocol=None)
Return a deep copy of the node.
 
get_current_train_phase(self)
Return the index of the current training phase.
 
get_dtype(self)
Return dtype.
 
get_input_dim(self)
Return input dimensions.
 
get_output_dim(self)
Return output dimensions.
 
get_remaining_train_phase(self)
Return the number of training phases still to accomplish.
 
get_supported_dtypes(self)
Return dtypes supported by the node as a list of dtype objects.
 
has_multiple_training_phases(self)
Return True if the node has multiple training phases.
 
inverse(self, y, *args, **kwargs)
Invert y.
 
is_training(self)
Return True if the node is in the training phase, False otherwise.
 
save(self, filename, protocol=-1)
Save a pickled serialization of the node to filename. If filename is None, return a string.
 
set_dtype(self, t)
Set internal structures' dtype.
 
set_input_dim(self, n)
Set input dimensions.
 
set_output_dim(self, n)
Set output dimensions.
Static Methods [hide private]
 
is_invertible()
Return True if the node can be inverted, False otherwise.
 
is_trainable()
Return True if the node can be trained, False otherwise.
Properties [hide private]

Inherited from object: __class__

    Inherited from Node
  _train_seq
List of tuples:
  dtype
dtype
  input_dim
Input dimensions
  output_dim
Output dimensions
  supported_dtypes
Supported dtypes
Method Details [hide private]

__init__(self, input_dim=None, output_dim=None, dtype=None, **kwargs)
(Constructor)

 

RANSAC (RANdom SAmple Consensus) algorithm.

This node has been automatically generated by wrapping the ``sklearn.linear_model.ransac.RANSACRegressor`` class
from the ``sklearn`` library.  The wrapped instance can be accessed
through the ``scikits_alg`` attribute.

RANSAC is an iterative algorithm for the robust estimation of parameters
from a subset of inliers from the complete data set. More information can
be found in the general documentation of linear models.

A detailed description of the algorithm can be found in the documentation
of the ``linear_model`` sub-package.

Read more in the :ref:`User Guide <ransac_regression>`.

**Parameters**

base_estimator : object, optional
    Base estimator object which implements the following methods:


     * `fit(X, y)`: Fit model to given training data and target values.
     * `score(X, y)`: Returns the mean accuracy on the given test data,
       which is used for the stop criterion defined by `stop_score`.
       Additionally, the score is used to decide which of two equally
       large consensus sets is chosen as the better one.

    If `base_estimator` is None, then
    ``base_estimator=sklearn.linear_model.LinearRegression()`` is used for
    target values of dtype float.

    Note that the current implementation only supports regression
    estimators.

min_samples : int (>= 1) or float ([0, 1]), optional
    Minimum number of samples chosen randomly from original data. Treated
    as an absolute number of samples for `min_samples >= 1`, treated as a
    relative number `ceil(min_samples * X.shape[0]`) for
    `min_samples < 1`. This is typically chosen as the minimal number of
    samples necessary to estimate the given `base_estimator`. By default a
    ``sklearn.linear_model.LinearRegression()`` estimator is assumed and
    `min_samples` is chosen as ``X.shape[1] + 1``.

residual_threshold : float, optional
    Maximum residual for a data sample to be classified as an inlier.
    By default the threshold is chosen as the MAD (median absolute
    deviation) of the target values `y`.

is_data_valid : callable, optional
    This function is called with the randomly selected data before the
    model is fitted to it: `is_data_valid(X, y)`. If its return value is
    False the current randomly chosen sub-sample is skipped.

is_model_valid : callable, optional
    This function is called with the estimated model and the randomly
    selected data: `is_model_valid(model, X, y)`. If its return value is
    False the current randomly chosen sub-sample is skipped.
    Rejecting samples with this function is computationally costlier than
    with `is_data_valid`. `is_model_valid` should therefore only be used if
    the estimated model is needed for making the rejection decision.

max_trials : int, optional
    Maximum number of iterations for random sample selection.

stop_n_inliers : int, optional
    Stop iteration if at least this number of inliers are found.

stop_score : float, optional
    Stop iteration if score is greater equal than this threshold.

stop_probability : float in range [0, 1], optional
    RANSAC iteration stops if at least one outlier-free set of the training
    data is sampled in RANSAC. This requires to generate at least N
    samples (iterations)::


        N >= log(1 - probability) / log(1 - e**m)

    where the probability (confidence) is typically set to high value such
    as 0.99 (the default) and e is the current fraction of inliers w.r.t.
    the total number of samples.

residual_metric : callable, optional
    Metric to reduce the dimensionality of the residuals to 1 for
    multi-dimensional target values ``y.shape[1] > 1``. By default the sum
    of absolute differences is used::


        lambda dy: np.sum(np.abs(dy), axis=1)

random_state : integer or numpy.RandomState, optional
    The generator used to initialize the centers. If an integer is
    given, it fixes the seed. Defaults to the global numpy random
    number generator.

**Attributes**

``estimator_`` : object
    Best fitted model (copy of the `base_estimator` object).

``n_trials_`` : int
    Number of random selection trials until one of the stop criteria is
    met. It is always ``<= max_trials``.

``inlier_mask_`` : bool array of shape [n_samples]
    Boolean mask of inliers classified as ``True``.

**References**

.. [1] http://en.wikipedia.org/wiki/RANSAC
.. [2] http://www.cs.columbia.edu/~belhumeur/courses/compPhoto/ransac.pdf
.. [3] http://www.bmva.org/bmvc/2009/Papers/Paper355/Paper355.pdf

Overrides: object.__init__

_execute(self, x)

 
Overrides: Node._execute

_get_supported_dtypes(self)

 
Return the list of dtypes supported by this node. The types can be specified in any format allowed by numpy.dtype.
Overrides: Node._get_supported_dtypes

_stop_training(self, **kwargs)

 
Concatenate the collected data in a single array.
Overrides: Node._stop_training

execute(self, x)

 

Predict using the estimated model.

This node has been automatically generated by wrapping the sklearn.linear_model.ransac.RANSACRegressor class from the sklearn library. The wrapped instance can be accessed through the scikits_alg attribute.

This is a wrapper for estimator_.predict(X).

Parameters

X : numpy array of shape [n_samples, n_features]

Returns

y : array, shape = [n_samples] or [n_samples, n_targets]
Returns predicted values.
Overrides: Node.execute

is_invertible()
Static Method

 
Return True if the node can be inverted, False otherwise.
Overrides: Node.is_invertible
(inherited documentation)

is_trainable()
Static Method

 
Return True if the node can be trained, False otherwise.
Overrides: Node.is_trainable

stop_training(self, **kwargs)

 

Fit estimator using RANSAC algorithm.

This node has been automatically generated by wrapping the sklearn.linear_model.ransac.RANSACRegressor class from the sklearn library. The wrapped instance can be accessed through the scikits_alg attribute.

Parameters

X : array-like or sparse matrix, shape [n_samples, n_features]
Training data.
y : array-like, shape = [n_samples] or [n_samples, n_targets]
Target values.

Raises

ValueError
If no valid consensus set could be found. This occurs if is_data_valid and is_model_valid return False for all max_trials randomly chosen sub-samples.
Overrides: Node.stop_training