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

Class BirchScikitsLearnNode



Implements the Birch clustering algorithm.

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

Every new sample is inserted into the root of the Clustering Feature
Tree. It is then clubbed together with the subcluster that has the
centroid closest to the new sample. This is done recursively till it
ends up at the subcluster of the leaf of the tree has the closest centroid.

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

**Parameters**

threshold : float, default 0.5
    The radius of the subcluster obtained by merging a new sample and the
    closest subcluster should be lesser than the threshold. Otherwise a new
    subcluster is started.

branching_factor : int, default 50
    Maximum number of CF subclusters in each node. If a new samples enters
    such that the number of subclusters exceed the branching_factor then
    the node has to be split. The corresponding parent also has to be
    split and if the number of subclusters in the parent is greater than
    the branching factor, then it has to be split recursively.

n_clusters : int, instance of sklearn.cluster model, default None
    Number of clusters after the final clustering step, which treats the
    subclusters from the leaves as new samples. By default, this final
    clustering step is not performed and the subclusters are returned
    as they are. If a model is provided, the model is fit treating
    the subclusters as new samples and the initial data is mapped to the
    label of the closest subcluster. If an int is provided, the model
    fit is AgglomerativeClustering with n_clusters set to the int.

compute_labels : bool, default True
    Whether or not to compute labels for each fit.

copy : bool, default True
    Whether or not to make a copy of the given data. If set to False,
    the initial data will be overwritten.

**Attributes**

``root_`` : _CFNode
    Root of the CFTree.

``dummy_leaf_`` : _CFNode
    Start pointer to all the leaves.

``subcluster_centers_`` : ndarray,
    Centroids of all subclusters read directly from the leaves.

``subcluster_labels_`` : ndarray,
    Labels assigned to the centroids of the subclusters after
    they are clustered globally.

``labels_`` : ndarray, shape (n_samples,)
    Array of labels assigned to the input data.
    if partial_fit is used instead of fit, they are assigned to the
    last batch of data.

**Examples**

>>> from sklearn.cluster import Birch
>>> X = [[0, 1], [0.3, 1], [-0.3, 1], [0, -1], [0.3, -1], [-0.3, -1]]
>>> brc = Birch(branching_factor=50, n_clusters=None, threshold=0.5,
... compute_labels=True)
>>> brc.fit(X)
Birch(branching_factor=50, compute_labels=True, copy=True, n_clusters=None,
   threshold=0.5)
>>> brc.predict(X)
array([0, 0, 0, 1, 1, 1])

**References**

* Tian Zhang, Raghu Ramakrishnan, Maron Livny
  BIRCH: An efficient data clustering method for large databases.
  http://www.cs.sfu.ca/CourseCentral/459/han/papers/zhang96.pdf

* Roberto Perdisci
  JBirch - Java implementation of BIRCH clustering algorithm
  https://code.google.com/p/jbirch/

Instance Methods [hide private]
 
__init__(self, input_dim=None, output_dim=None, dtype=None, **kwargs)
Implements the Birch clustering 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)
Transform X into subcluster centroids dimension.
 
stop_training(self, **kwargs)
Build a CF Tree for the input data.

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)

 

Implements the Birch clustering algorithm.

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

Every new sample is inserted into the root of the Clustering Feature
Tree. It is then clubbed together with the subcluster that has the
centroid closest to the new sample. This is done recursively till it
ends up at the subcluster of the leaf of the tree has the closest centroid.

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

**Parameters**

threshold : float, default 0.5
    The radius of the subcluster obtained by merging a new sample and the
    closest subcluster should be lesser than the threshold. Otherwise a new
    subcluster is started.

branching_factor : int, default 50
    Maximum number of CF subclusters in each node. If a new samples enters
    such that the number of subclusters exceed the branching_factor then
    the node has to be split. The corresponding parent also has to be
    split and if the number of subclusters in the parent is greater than
    the branching factor, then it has to be split recursively.

n_clusters : int, instance of sklearn.cluster model, default None
    Number of clusters after the final clustering step, which treats the
    subclusters from the leaves as new samples. By default, this final
    clustering step is not performed and the subclusters are returned
    as they are. If a model is provided, the model is fit treating
    the subclusters as new samples and the initial data is mapped to the
    label of the closest subcluster. If an int is provided, the model
    fit is AgglomerativeClustering with n_clusters set to the int.

compute_labels : bool, default True
    Whether or not to compute labels for each fit.

copy : bool, default True
    Whether or not to make a copy of the given data. If set to False,
    the initial data will be overwritten.

**Attributes**

``root_`` : _CFNode
    Root of the CFTree.

``dummy_leaf_`` : _CFNode
    Start pointer to all the leaves.

``subcluster_centers_`` : ndarray,
    Centroids of all subclusters read directly from the leaves.

``subcluster_labels_`` : ndarray,
    Labels assigned to the centroids of the subclusters after
    they are clustered globally.

``labels_`` : ndarray, shape (n_samples,)
    Array of labels assigned to the input data.
    if partial_fit is used instead of fit, they are assigned to the
    last batch of data.

**Examples**

>>> from sklearn.cluster import Birch
>>> X = [[0, 1], [0.3, 1], [-0.3, 1], [0, -1], [0.3, -1], [-0.3, -1]]
>>> brc = Birch(branching_factor=50, n_clusters=None, threshold=0.5,
... compute_labels=True)
>>> brc.fit(X)
Birch(branching_factor=50, compute_labels=True, copy=True, n_clusters=None,
   threshold=0.5)
>>> brc.predict(X)
array([0, 0, 0, 1, 1, 1])

**References**

* Tian Zhang, Raghu Ramakrishnan, Maron Livny
  BIRCH: An efficient data clustering method for large databases.
  http://www.cs.sfu.ca/CourseCentral/459/han/papers/zhang96.pdf

* Roberto Perdisci
  JBirch - Java implementation of BIRCH clustering algorithm
  https://code.google.com/p/jbirch/

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)

 

Transform X into subcluster centroids dimension.

This node has been automatically generated by wrapping the sklearn.cluster.birch.Birch class from the sklearn library. The wrapped instance can be accessed through the scikits_alg attribute.

Each dimension represents the distance from the sample point to each cluster centroid.

Parameters

X : {array-like, sparse matrix}, shape (n_samples, n_features)
Input data.

Returns

X_trans : {array-like, sparse matrix}, shape (n_samples, n_clusters)
Transformed data.
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)

 

Build a CF Tree for the input data.

This node has been automatically generated by wrapping the sklearn.cluster.birch.Birch class from the sklearn library. The wrapped instance can be accessed through the scikits_alg attribute.

Parameters

X : {array-like, sparse matrix}, shape (n_samples, n_features)
Input data.
Overrides: Node.stop_training