Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
or treat == Continuize.RemoveMultinomial
and len(var.values) > 2
):
return []
if treat == Continuize.AsOrdinal:
new_var = ContinuousVariable(
var.name, compute_value=Identity(var), sparse=var.sparse
)
return [new_var]
if treat == Continuize.AsNormalizedOrdinal:
n_values = max(1, len(var.values))
if self.zero_based:
return [
ContinuousVariable(
var.name,
compute_value=Normalizer(var, 0, 1 / (n_values - 1)),
sparse=var.sparse,
)
]
else:
return [
ContinuousVariable(
var.name,
compute_value=Normalizer(
var, (n_values - 1) / 2, 2 / (n_values - 1)
),
sparse=var.sparse,
)
]
new_vars = []
if treat == Continuize.Indicators:
def normalize_by_span(self, dist, var):
dma, dmi = dist.max(), dist.min()
diff = dma - dmi
if diff < 1e-15:
diff = 1
if self.zero_based:
return ContinuousVariable(
var.name, compute_value=Norm(var, dmi, 1 / diff), sparse=var.sparse
)
else:
return ContinuousVariable(
var.name,
compute_value=Norm(var, (dma + dmi) / 2, 2 / diff),
sparse=var.sparse,
)
dist = distribution.get_distribution(data, var)
if self.center != self.NoCentering:
c = self.center(dist)
dist[0, :] -= c
else:
c = 0
if self.scale != self.NoScaling:
s = self.scale(dist)
if s < 1e-15:
s = 1
else:
s = 1
factor = 1 / s
transformed_var = var.copy(
compute_value=transformation.Normalizer(var, c, factor)
)
if s != 1:
transformed_var.number_of_decimals = 3
return transformed_var
def normalize_by_span(self, dist, var):
dma, dmi = dist.max(), dist.min()
diff = dma - dmi
if diff < 1e-15:
diff = 1
if self.zero_based:
return ContinuousVariable(
var.name, compute_value=Norm(var, dmi, 1 / diff), sparse=var.sparse
)
else:
return ContinuousVariable(
var.name,
compute_value=Norm(var, (dma + dmi) / 2, 2 / diff),
sparse=var.sparse,
)
return [new_var]
if treat == Continuize.AsNormalizedOrdinal:
n_values = max(1, len(var.values))
if self.zero_based:
return [
ContinuousVariable(
var.name,
compute_value=Normalizer(var, 0, 1 / (n_values - 1)),
sparse=var.sparse,
)
]
else:
return [
ContinuousVariable(
var.name,
compute_value=Normalizer(
var, (n_values - 1) / 2, 2 / (n_values - 1)
),
sparse=var.sparse,
)
]
new_vars = []
if treat == Continuize.Indicators:
base = -1
elif treat in (Continuize.FirstAsBase, Continuize.RemoveMultinomial):
base = max(var.base_value, 0)
else:
base = dists[var_ptr].modus()
ind_class = [Indicator1, Indicator][self.zero_based]
for i, val in enumerate(var.values):
if i == base:
def normalize_by_sd(self, dist, var):
avg, sd = (dist.mean(), dist.standard_deviation()) if dist.size else (0, 1)
if sd == 0:
sd = 1
return ContinuousVariable(
var.name, compute_value=Norm(var, avg, 1 / sd), sparse=var.sparse
)