fuzzyclust.models.FuzzyCRegression#

class fuzzyclust.models.FuzzyCRegression(n_clusters=2, m=2.0, fit_intercept=True, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#

Bases: BaseFuzzyClusterer

Fuzzy c-regression models (FCRM): clusters are regression hyperplanes.

Instead of a point prototype, every cluster is a linear model \(y = \mathbf{a}_i^T\mathbf{x} + b_i\) and the “distance” of a sample \(\mathbf{z}_k=[\mathbf{x}_k^T\,y_k]^T\) to the cluster is its squared residual. FCRM therefore solves the switching regression problem: data generated by several unknown linear laws, mixed, without knowing which sample belongs to which law [1]. The hyperplanes may cross each other, a situation in which clustering of the input–output points with point prototypes (FCM, GK) fails.

Parameters:
n_clustersint, default=2

Number of regression models \(c\).

mfloat, default=2.0

Fuzziness exponent \(m>1\).

fit_interceptbool, default=True
tolfloat, default=1e-4
max_iterint, default=300
init{“random”, “kmeans++”} or ndarray, default=”random”

"random" draws a random fuzzy partition (Hathaway & Bezdek); "kmeans++" seeds point prototypes in the input space; an array is an initial partition (n_samples, n_clusters) or initial centers in the input space.

n_initint, default=1

Number of random restarts; the run with the lowest final objective \(J\) is kept (the switching-regression functional has many local minima, several restarts are recommended).

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
coef_ndarray of shape (n_clusters, n_features)

Slopes \(\mathbf{a}_i\).

intercept_ndarray of shape (n_clusters,)

Offsets \(b_i\).

local_models_ndarray of shape (n_clusters, n_features + 1)

\(\boldsymbol\theta_i=[\mathbf{a}_i^T\, b_i]^T\).

cluster_centers_ndarray of shape (n_clusters, n_features)

Membership-weighted means of the inputs of every cluster (the “middle” of the operating region of the local model).

membership_ndarray of shape (n_samples, n_clusters)
labels_ndarray of shape (n_samples,)
distances_ndarray of shape (n_samples, n_clusters)

Absolute residuals \(|y_k - \mathbf{a}_i^T\mathbf{x}_k - b_i|\) at convergence.

objective_, objective_history_, n_iter_

See BaseFuzzyClusterer.

Notes

The objective is the c-means functional with the residual distance

\[J = \sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}^m E_{ik}(\boldsymbol\theta_i),\qquad E_{ik} = \big(y_k - [\mathbf{x}_k^T\,1]\,\boldsymbol\theta_i\big)^2,\]

minimized by alternating the weighted least-squares update of the models

\[\boldsymbol\theta_i = (\mathbf{X}_e^T\boldsymbol\Phi_i\mathbf{X}_e)^{-1} \mathbf{X}_e^T\boldsymbol\Phi_i\mathbf{y},\qquad \boldsymbol\Phi_i=\operatorname{diag}(\mu_{i1}^m,\dots,\mu_{iN}^m),\]

and the FCM membership update \(\mu_{ik}=1/\sum_j (E_{ik}/E_{jk})^{1/(m-1)}\).

Because the distance needs the output, membership of new data can only be evaluated for input–output pairs: predict_proba() takes (X, y). predict() returns the outputs of all local models, an array of shape (n_samples, n_clusters): a switching regression model does not tell which law a new input obeys. To obtain one prediction per sample use TakagiSugeno, whose antecedents partition the input space, or the hinging-hyperplane construction of HingingHyperplaneTree.

References

[1]

R. J. Hathaway, J. C. Bezdek, “Switching regression models and fuzzy clustering”, IEEE Trans. Fuzzy Systems, 1(3), 195–204, 1993.

Examples

>>> from fuzzyclust.models import FuzzyCRegression, make_switching_lines
>>> X, y, lab = make_switching_lines(n_samples=200, random_state=0)
>>> fcrm = FuzzyCRegression(n_clusters=2, random_state=0).fit(X, y)
>>> fcrm.coef_.shape, fcrm.intercept_.shape
((2, 1), (2,))
>>> fcrm.predict(X).shape
(200, 2)
fit(X, y=None)[source]#

Fit the \(c\) regression models to the pairs (X, y).

Parameters:
Xarray_like of shape (n_samples, n_features)
yarray_like of shape (n_samples,)

Required (None raises a ValueError).

Returns:
selfobject
fit_predict(X, y=None, **kwargs)[source]#

Fit and return the hard labels of the training pairs.

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 of shape (n_samples, n_features)

Input samples.

yarray_like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

predict(X)[source]#

Outputs of all local models, (n_samples, n_clusters) (see Notes).

predict_labels(X, y)[source]#

Hard assignment of the pairs (X, y) to the regression model with the smallest residual.

predict_proba(X, y=None)[source]#

Memberships of the pairs (X, y) in the \(c\) regression models.

Returns an array of shape (n_samples, n_clusters).

score(X, y)[source]#

Negative objective \(-J\) of the pairs (X, y).

transform(X, y=None)[source]#

Absolute residuals \(|y_k-\hat y_{ik}|\) of the pairs (X, y) w.r.t. every model.

Examples using fuzzyclust.models.FuzzyCRegression#

Fuzzy c-regression models: switching regression with crossing lines

Fuzzy c-regression models: switching regression with crossing lines

Hinging-hyperplane regression tree identified by fuzzy c-regression

Hinging-hyperplane regression tree identified by fuzzy c-regression