fuzzyclust.models.FuzzyPartitionDiscretizer#

class fuzzyclust.models.FuzzyPartitionDiscretizer(n_sets=3, shape='trapezoid', merge_threshold=0.8, encode='crisp', method='supervised', drop_single=False, m=2.0, tol=0.0001, max_iter=300, init='kmeans++', random_state=None)[source]#

Bases: TransformerMixin, BaseEstimator

Supervised fuzzy discretization of continuous features.

A transformer that replaces every continuous feature by the fuzzy sets of a partition obtained with supervised_fuzzy_partition(). The output is either the membership of the sample in every set (encode="membership") or the index of the set with the highest membership (encode="crisp", one integer per feature, sets ordered from small to large values), which is the a-priori discretization that ID3-type decision-tree learners such as sklearn.tree.DecisionTreeClassifier can be trained on. Because the partition is derived from a classifier, the cut points are placed where the classes change, in contrast to equal-width or equal-frequency binning [1].

Parameters:
n_setsint, default=3

Number of rules of the supervised clustering = initial number of sets per feature (merging may reduce it).

shape{“gaussian”, “trapezoid”, “triangle”}, default=”trapezoid”
merge_thresholdfloat, default=0.8

Similarity threshold of set merging (1.0: no merging).

encode{“crisp”, “membership”}, default=”crisp”

"crisp" returns one float column per feature holding the index of the set with the highest membership; "membership" returns the memberships in every set.

method{“supervised”, “ruspini”}, default=”supervised”

"supervised" derives the sets from supervised fuzzy clustering (supervised_fuzzy_partition()); "ruspini" is the unsupervised, equidistant triangular baseline of ruspini_partition() (shape, merge_threshold and the clustering parameters are then ignored).

drop_singlebool, default=False

Drop features whose partition collapsed to a single set (“don’t care” variables).

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

Initialization of the supervised clustering.

random_stateint, RandomState instance or None, default=None
Attributes:
partitions_list of dict

One partition per input feature (see supervised_fuzzy_partition()).

classifier_fitted SupervisedFuzzyClassifier or None

The supervised clustering (None for method="ruspini").

n_sets_ndarray of shape (n_features,)

Number of sets per feature after merging.

active_features_ndarray of int

Features kept by transform.

n_iter_int

Iterations of the supervised clustering (0 for method="ruspini").

References

[1]

J. Abonyi, “Supervised fuzzy clustering based initialization of fuzzy partitions for decision tree induction”, 2010.

Examples

>>> from fuzzyclust.datasets import load_iris
>>> from fuzzyclust.models import FuzzyPartitionDiscretizer
>>> iris = load_iris()
>>> disc = FuzzyPartitionDiscretizer(n_sets=3, random_state=0).fit(iris.data, iris.target)
>>> disc.transform(iris.data).shape
(150, 4)
>>> bool(disc.set_params(encode="membership").transform(iris.data).shape[1] == disc.n_sets_.sum())
True
evaluate(feature, grid)[source]#

Memberships of the sets of feature on grid (for plotting), (len(grid), n_sets_j).

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

Derive the per-feature fuzzy partitions from the labeled data.

membership(X)[source]#

Memberships in the sets of every active feature: list of arrays (n_samples, n_sets_j).

transform(X)[source]#

Encode the features.

Returns (n_samples, n_active) set indices (as floats, like sklearn.preprocessing.KBinsDiscretizer with ordinal encoding) or (n_samples, sum n_sets_j) memberships.

Examples using fuzzyclust.models.FuzzyPartitionDiscretizer#

Supervised fuzzy partitions as a priori discretization for decision trees

Supervised fuzzy partitions as a priori discretization for decision trees