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:
BaseFuzzyClustererFuzzy 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_clusters
int, default=2 Number of regression models \(c\).
- m
float, default=2.0 Fuzziness exponent \(m>1\).
- fit_interceptbool, default=True
- tol
float, default=1e-4 - max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarray, 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_init
int, 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_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- coef_
ndarrayofshape(n_clusters,n_features) Slopes \(\mathbf{a}_i\).
- intercept_
ndarrayofshape(n_clusters,) Offsets \(b_i\).
- local_models_
ndarrayofshape(n_clusters,n_features+ 1) \(\boldsymbol\theta_i=[\mathbf{a}_i^T\, b_i]^T\).
- cluster_centers_
ndarrayofshape(n_clusters,n_features) Membership-weighted means of the inputs of every cluster (the “middle” of the operating region of the local model).
- membership_
ndarrayofshape(n_samples,n_clusters) - labels_
ndarrayofshape(n_samples,) - distances_
ndarrayofshape(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.
- coef_
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 useTakagiSugeno, whose antecedents partition the input space, or the hinging-hyperplane construction ofHingingHyperplaneTree.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
ofshape(n_samples,n_features) - yarray_like
ofshape(n_samples,) Required (
Noneraises aValueError).
- Xarray_like
- Returns:
- self
object
- 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_labels(X, y)[source]#
Hard assignment of the pairs
(X, y)to the regression model with the smallest residual.
Examples using fuzzyclust.models.FuzzyCRegression#
Fuzzy c-regression models: switching regression with crossing lines
Hinging-hyperplane regression tree identified by fuzzy c-regression