Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] OWContinuize: Fix treatment of continuous features. #4806

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Orange/widgets/data/owcontinuize.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,23 @@ def one_hot_coding(var):

def continuize_domain(data,
multinomial_treatment=Continuize.Indicators,
continuous_treatment=Continuize.Leave,
continuous_treatment=OWContinuize.Normalize.Leave,
class_treatment=Continuize.Leave):
domain = data.domain
def needs_dist(var, mtreat, ctreat):
"Does the `var` need a distribution given specified flags"
if var.is_discrete:
return mtreat == Continuize.FrequentAsBase
elif var.is_continuous:
return ctreat != Continuize.Leave
return ctreat != OWContinuize.Normalize.Leave
else:
raise ValueError

# Compute the column indices which need a distribution.
attr_needs_dist = [needs_dist(var, multinomial_treatment,
continuous_treatment)
for var in domain.attributes]
cls_needs_dist = [needs_dist(var, class_treatment, Continuize.Leave)
cls_needs_dist = [needs_dist(var, class_treatment, OWContinuize.Normalize.Leave)
for var in domain.class_vars]

columns = [i for i, needs in enumerate(attr_needs_dist + cls_needs_dist)
Expand All @@ -242,7 +242,7 @@ def needs_dist(var, mtreat, ctreat):
for var, needs_dist in zip(domain.attributes, attr_needs_dist)]
newclass = [continuize_var(var,
next(dist_iter) if needs_dist else None,
class_treatment, Continuize.Remove)
Copy link
Contributor Author

@thocevar thocevar May 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find a reason for this Continuize.Remove.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't hurt to give the value explicitly, either...

class_treatment, OWContinuize.Normalize.Leave)
for var, needs_dist in zip(domain.class_vars, cls_needs_dist)]

newattrs = reduce(list.__iadd__, newattrs, [])
Expand All @@ -253,13 +253,13 @@ def needs_dist(var, mtreat, ctreat):
def continuize_var(var,
data_or_dist=None,
multinomial_treatment=Continuize.Indicators,
continuous_treatment=Continuize.Leave):
continuous_treatment=OWContinuize.Normalize.Leave):
def continuize_continuous():
dist = _ensure_dist(var, data_or_dist)
dist = _ensure_dist(var, data_or_dist) if continuous_treatment != OWContinuize.Normalize.Leave else None
treatments = [lambda var, _: var,
normalize_by_sd, center_to_mean, divide_by_sd,
normalize_to_11, normalize_to_01]
if dist.shape[1] == 0:
if dist is not None and dist.shape[1] == 0:
return [var]
new_var = treatments[continuous_treatment](var, dist)
return [new_var]
Expand Down Expand Up @@ -365,7 +365,7 @@ def normalize_by_span(var, dist, zero_based=True):
class DomainContinuizer(Reprable):
def __init__(self,
multinomial_treatment=Continuize.Indicators,
continuous_treatment=Continuize.Leave,
continuous_treatment=OWContinuize.Normalize.Leave,
class_treatment=Continuize.Leave):
self.multinomial_treatment = multinomial_treatment
self.continuous_treatment = continuous_treatment
Expand Down
5 changes: 5 additions & 0 deletions Orange/widgets/data/tests/test_owcontinuize.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def test_summary(self):
output_sum.assert_called_once()
self.assertEqual(output_sum.call_args[0][0].brief, "")

def test_continuous(self):
table = Table("housing")
self.send_signal(self.widget.Inputs.data, table)
self.widget.unconditional_commit()

def test_one_column_equal_values(self):
"""
No crash on a column with equal values and with selected option
Expand Down