fuzzyclust.base.BaseFuzzyClusterer#
- class fuzzyclust.base.BaseFuzzyClusterer(n_clusters=3, m=2.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#
Bases:
ClusterMixin,TransformerMixin,BaseEstimator,ABCAbstract base of the prototype-based clustering algorithms.
- Parameters:
- n_clusters
int, default=3 Number of clusters \(c\).
- m
float, default=2.0 Fuzziness (weighting) exponent \(m>1\). Larger values give fuzzier partitions; \(m\to 1\) approaches a hard partition.
- tol
float, default=1e-4 Termination tolerance \(\epsilon\) on \(\max_{ik} |\mu_{ik}^{(l)} - \mu_{ik}^{(l-1)}|\).
- max_iter
int, default=300 Maximum number of alternating-optimization iterations.
- init{“random”, “kmeans++”}
orndarray, default=”random” Initialization.
"random"draws random prototypes inside the bounding box of the data and derives the initial partition from them (MATLAB toolbox behavior)."kmeans++"uses the k-means++ seeding. An array of shape(n_clusters, n_features)is used as initial prototypes, an array of shape(n_samples, n_clusters)as initial partition.- n_init
int, default=1 Number of random restarts. The alternating optimization converges to a local optimum of \(J\); with
n_init > 1the run with the lowest final objective is kept (ignored wheninitis an array).- random_state
int,RandomStateinstanceorNone, default=None Controls the random initialization.
- verbose
int, default=0 Print the objective at every iteration when
> 0.
- n_clusters
- Attributes:
- cluster_centers_
ndarrayofshape(n_clusters,n_features) Prototypes \(\mathbf{v}_i\).
- membership_
ndarrayofshape(n_samples,n_clusters) Fuzzy partition \(\mathbf{U}^T\) (rows sum to one).
- labels_
ndarrayofshape(n_samples,) Hard labels,
membership_.argmax(axis=1).- distances_
ndarrayofshape(n_samples,n_clusters) Distances \(D_{ik}\) of the training samples to the prototypes at convergence (algorithm specific norm).
- objective_
float Final value of the objective \(J\).
- objective_history_
ndarrayofshape(n_iter_,) \(J\) after every iteration.
- n_iter_
int Number of iterations run.
- n_features_in_
int - feature_names_in_
ndarrayofshape(n_features_in_,) Defined when
Xhas feature names (e.g. apandas.DataFrame).
- cluster_centers_
- fit(X, y=None)[source]#
Compute the clustering.
- Parameters:
- Xarray_like
ofshape(n_samples,n_features) Training data.
pandas.DataFrameinput is accepted and its column names are stored infeature_names_in_.- y
Ignored Present for API consistency.
- Xarray_like
- Returns:
- self
object Fitted estimator.
- self
- fit_transform(X, y=None, **fit_params)[source]#
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
- Xarray_like
ofshape(n_samples,n_features) Input samples.
- yarray_like
ofshape(n_samples,)or(n_samples,n_outputs), default=None Target values (None for unsupervised transformations).
- **fit_params
dict Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.
- Xarray_like
- Returns:
- predict(X)[source]#
Hard cluster labels of (new) samples (argmax of
predict_proba()).
- predict_proba(X)[source]#
Membership degrees of (new) samples in the fitted clusters.
Equivalent to
clustevalof the MATLAB toolbox: the distances to the fitted prototypes (with their fitted norms) are converted into memberships with the algorithm’s own membership formula.- Returns:
- U
ndarrayofshape(n_samples,n_clusters)
- U