Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Whether to center the scaled distance measures. If False, the min distance for each feature
except for the feature with the highest raw max distance will be the lower bound of the
feature range, but the upper bound will be below the max feature range.
update_feature_range
Update feature range with scaled values.
"""
if self.model:
preds = np.argmax(self.predict.predict(train_data), axis=1) # type: ignore
else:
preds = np.argmax(self.predict(train_data), axis=1)
self.cat_vars_ord = None
if self.is_cat: # compute distance metrics for categorical variables
if self.ohe: # convert OHE to ordinal encoding
train_data_ord, self.cat_vars_ord = ohe_to_ord(train_data, self.cat_vars)
else:
train_data_ord, self.cat_vars_ord = train_data, self.cat_vars
# bin numerical features to compute the pairwise distance matrices
cat_keys = list(self.cat_vars_ord.keys())
n_ord = train_data_ord.shape[1]
if d_type in ['abdm', 'abdm-mvdm'] and len(cat_keys) != n_ord:
fnames = [str(_) for _ in range(n_ord)]
disc = Discretizer(train_data_ord, cat_keys, fnames, percentiles=disc_perc)
train_data_bin = disc.discretize(train_data_ord)
cat_vars_bin = {k: len(disc.names[k]) for k in range(n_ord) if k not in cat_keys}
else:
train_data_bin = train_data_ord
cat_vars_bin = {}
if d_type not in ['abdm', 'mvdm', 'abdm-mvdm']:
if not isinstance(x, (float, int, np.int64)):
x = np.copy(x)
x[y] += self.kappa
x = np.argmax(x)
return x != y
# define target classes for prototype if not specified yet
if target_class is None:
target_class = list(range(self.classes))
target_class.remove(np.argmax(Y, axis=1))
if verbose:
print('Predicted class: {}'.format(np.argmax(Y, axis=1)))
print('Target classes: {}'.format(target_class))
if self.is_cat and self.ohe: # map categorical to numerical data
X_ord = ohe_to_ord(X, self.cat_vars)[0]
X_num = ord_to_num(X_ord, self.d_abs)
elif self.is_cat:
X_num = ord_to_num(X, self.d_abs)
else:
X_num = X
# find closest prototype in the target class list
dist_proto = {}
if self.enc_model:
X_enc = self.enc.predict(X)
class_dict = self.class_proto if k is None else self.class_enc
for c, v in class_dict.items():
if c not in target_class:
continue