somlearn
.SOM¶
-
class
somlearn.
SOM
(n_columns=5, n_rows=5, initialcodebook=None, kerneltype=0, maptype='planar', gridtype='rectangular', compactsupport=True, neighborhood='gaussian', std_coeff=0.5, random_state=None, verbose=0)[source]¶ Class to fit and visualize a Self-Organizing Map (SOM).
The implementation uses SOM from Somoclu.
Read more in the User Guide.
Parameters: - n_columns : int, optional (default=5)
The number of columns in the map.
- n_rows : int, optional (default=5)
The number of rows in the map.
- initialcodebook : 2D numpy.array of float32, str or None, optional (default=None)
Define the codebook to start the training. If
initialcodebook='pca'
then the codebook is initialized from the first subspace spanned by the first two eigenvectors of the correlation matrix.- kerneltype : int, optional (default=0)
Specify which kernel to use. If
kerneltype=0
use dense CPU kernel. Else ifkerneltype=1
use dense GPU kernel if compiled with it.- maptype : str, optional (default=’planar’)
Specify the map topology. If
maptype='planar'
use planar map. Else ifmaptype='toroid'
use toroid map.- gridtype : str, optional (default=’rectangular’)
Specify the grid form of the nodes. If
gridtype='rectangular'
use rectangular neurons. Else ifgridtype='hexagonal'
use hexagonal neurons.- compactsupport : bool, optional (default=True)
Cut off map updates beyond the training radius with the Gaussian neighborhood.
- neighborhood : str, optional (default=’gaussian’)
Specify the neighborhood. If
neighborhood='gaussian'
use Gaussian neighborhood. Else if neighborhood=’bubble’` use bubble neighborhood function.- std_coeff : float, optional (default=0.5)
Set the coefficient in the Gaussian neighborhood
.
- random_state : int, RandomState instance or None, optional (default=None)
Control the randomization of the algorithm by specifying the codebook initalization. It is ignored when
initialcodebook
is notNone
.- If int,
random_state
is the seed used by the random number generator. - If
RandomState
instance, random_state is the random number generator. - If
None
, the random number generator is theRandomState
instance used bynp.random
.
- If int,
- verbose : int, optional (default=0)
Specify verbosity level (0, 1, or 2).
-
__init__
(self, n_columns=5, n_rows=5, initialcodebook=None, kerneltype=0, maptype='planar', gridtype='rectangular', compactsupport=True, neighborhood='gaussian', std_coeff=0.5, random_state=None, verbose=0)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
fit
(self, X, y=None, **fit_params)[source]¶ Train the self-organizing map.
Parameters: - X : array-like or sparse matrix, shape=(n_samples, n_features)
Training instances to cluster.
- y : Ignored
-
fit_predict
(self, X, y=None, **fit_params)[source]¶ Train the self-organizing map and assign a cluster label to each sample.
Parameters: - X : {array-like, sparse matrix}, shape = [n_samples, n_features]
New data to transform.
- u : Ignored
Returns: - labels : array, shape [n_samples,]
Index of the cluster each sample belongs to.
-
get_params
(self, deep=True)¶ Get parameters for this estimator.
Parameters: - deep : boolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns: - params : mapping of string to any
Parameter names mapped to their values.
-
set_params
(self, **params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.Returns: - self