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,BaseEstimatorSupervised 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 assklearn.tree.DecisionTreeClassifiercan 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_sets
int, 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_threshold
float, 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 ofruspini_partition()(shape,merge_thresholdand the clustering parameters are then ignored).- drop_singlebool, default=False
Drop features whose partition collapsed to a single set (“don’t care” variables).
- m
float, default=2.0 - tol
float, default=1e-4 - max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarray, default=”kmeans++” Initialization of the supervised clustering.
- random_state
int,RandomStateinstanceorNone, default=None
- n_sets
- Attributes:
- partitions_
listofdict One partition per input feature (see
supervised_fuzzy_partition()).- classifier_
fittedSupervisedFuzzyClassifierorNone The supervised clustering (
Noneformethod="ruspini").- n_sets_
ndarrayofshape(n_features,) Number of sets per feature after merging.
- active_features_
ndarrayofint Features kept by
transform.- n_iter_
int Iterations of the supervised clustering (0 for
method="ruspini").
- partitions_
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
featureongrid(for plotting),(len(grid), n_sets_j).
- 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, likesklearn.preprocessing.KBinsDiscretizerwith 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