diff --git a/fsvm/_fuzzy_svc.py b/fsvm/_fuzzy_svc.py index c56e65e..0d59343 100644 --- a/fsvm/_fuzzy_svc.py +++ b/fsvm/_fuzzy_svc.py @@ -59,9 +59,9 @@ class FuzzySVC(ClassifierMixin, BaseEstimator): This parameter is only used when `membership_decay='exponential'`. balanced : bool, default=True - Set the parameter C of class i to r_i*C for FuzzySVC. If `True`, the - membership of each sample will be scaled by the number r_i expressing - its ratio to the number of samples of the majority class as in [1]_. + Whether to use the values of y to automatically adjust weights + inversely proportional to class frequencies in the input data as + ``n_samples / (n_classes * np.bincount(y))``. C : float, default=1.0 Regularization parameter. The strength of the regularization is @@ -327,8 +327,7 @@ def fit(self, X, y): self.y_ = y y_ = column_or_1d(y, warn=True) - classes, y_, counts = np.unique(y, return_inverse=True, return_counts=True) - class_imbalance = self.__calculate_class_imbalance(y, classes, counts) + classes, y_ = np.unique(y_, return_inverse=True) svc_args = { "C": self.C, @@ -340,7 +339,7 @@ def fit(self, X, y): "probability": self.probability, "tol": self.tol, "cache_size": self.cache_size, - "class_weight": class_imbalance, + "class_weight": "balanced" if self.balanced else None, "verbose": self.verbose, "max_iter": self.max_iter, "decision_function_shape": self.decision_function_shape, @@ -415,20 +414,6 @@ def predict(self, X): return self.svc_.predict(X) - def __calculate_class_imbalance(self, y, classes, counts): - class_imbalance = None - - if self.balanced: - class_imbalance = {} - majority_class_count = np.amax(counts) - - for class_label in set(y): - idx = np.where(classes == class_label)[0][0] - - class_imbalance[class_label] = counts[idx] / majority_class_count - - return class_imbalance - def __calculate_membership_degree(self): if self.membership_decay == "exponential": membership = 2 / (1 + np.exp(self.beta * self.distance_))