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

Allow different sorters to work with Vis Object #350

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

jinimukh
Copy link
Member

@jinimukh jinimukh commented Apr 9, 2021

Overview

This PR introduces a way to incorporate different sorters for Vis Objects. Currently, this only includes interestingness and alphabetical sorts, but later on, we can extend this class.

Changes

-- add sorters.py in utils
-- add lux.config.sorter in config
-- add tests in test_config

Example Output

TBD

@codecov
Copy link

codecov bot commented Apr 9, 2021

Codecov Report

Merging #350 (d08c17c) into master (623e5f3) will increase coverage by 0.30%.
The diff coverage is 91.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #350      +/-   ##
==========================================
+ Coverage   65.94%   66.24%   +0.30%     
==========================================
  Files          55       56       +1     
  Lines        4416     4468      +52     
==========================================
+ Hits         2912     2960      +48     
- Misses       1504     1508       +4     
Impacted Files Coverage Δ
lux/utils/orderings.py 84.61% <84.61%> (ø)
lux/_config/config.py 77.27% <100.00%> (+1.72%) ⬆️
lux/action/correlation.py 86.66% <100.00%> (ø)
lux/action/enhance.py 100.00% <100.00%> (ø)
lux/action/filter.py 91.66% <100.00%> (ø)
lux/action/temporal.py 96.61% <100.00%> (ø)
lux/action/univariate.py 89.13% <100.00%> (ø)
lux/vis/VisList.py 51.04% <100.00%> (-0.26%) ⬇️
lux/vislib/altair/ScatterChart.py 96.96% <0.00%> (+3.03%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 623e5f3...d08c17c. Read the comment docs.

@@ -6,6 +6,7 @@
from typing import Any, Callable, Dict, Iterable, List, Optional, Union
import lux
import warnings
from lux.utils.sorters import Sorter
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename Sorter to something more specific? Currently, the sorter actually doesn't perform any sorting, but just returns the sort key, e.g. interestingness score, or sort key for alphabetical sorting.

@@ -83,6 +85,23 @@ def sort(self, flag: Union[str]):
stacklevel=2,
)

@property
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if sort makes sense as a global option, since it is more common to do one type of sorting for an action, but a different sort mechanism for another action.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added two implementations -- one global ordering (this could be useful for sorting by attribute name or something really general that you want to standardize across all actions) and an action-wise ordering dictionary. If no ordering is defined for the specific action, then we fallback to the global ordering.

Copy link
Member

Choose a reason for hiding this comment

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

This sounds great, let's add some docs that explain the two different types of ways to specify sorting!

lux/vis/VisList.py Show resolved Hide resolved
lux/utils/sorters.py Outdated Show resolved Hide resolved
for vis in df.recommendation["Correlation"]:
assert vis.get_attr_by_channel("y")[0].attribute <= string
string = vis.get_attr_by_channel("y")[0].attribute
lux.config.sorter = "interestingness"
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference between sorter and ordering?

return Ordering.interestingness
elif value == "title":
return Ordering.title
elif value == "x_attr":
Copy link
Member

Choose a reason for hiding this comment

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

can we make "title", "x_attr" and "y_attr" more readable? e.g.) "alphabetical_by_x", "alphabetical_by_y", "alphabetical_by_title"

@@ -83,6 +85,23 @@ def sort(self, flag: Union[str]):
stacklevel=2,
)

@property
Copy link
Member

Choose a reason for hiding this comment

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

This sounds great, let's add some docs that explain the two different types of ways to specify sorting!

def test_ordering_actions(global_var):
lux.config.topk = 5

lux.config.ordering_actions["correlation"] = "x_attr"
Copy link
Member

Choose a reason for hiding this comment

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

The keys to "ordering_actions" is lowercase, would it break if the users specify uppercase ["Correlation"] instead?

return self._ordering

@ordering.setter
def ordering(self, value):
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename all ordering as ranking? We should avoid the word sorter in places where it might be unclear what it is referring it.

@@ -17,6 +17,7 @@
import pandas as pd
import time
from lux.vis.VisList import VisList
from lux.utils.orderings import Ordering
Copy link
Member

Choose a reason for hiding this comment

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

Change orderings to ranking or sorter, it is more clear if we are consistent across the terminology used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll go for ranking because sort order (i.e. ascending/descending) uses "sort".

Copy link
Member

Choose a reason for hiding this comment

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

ok!

)

for vis in df.recommendation["Correlation"]:
assert (
Copy link
Member

Choose a reason for hiding this comment

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

For every assert, we should add the error message to be thrown if the assertion does not pass.

def sort_by_multiple(collection, desc):
collection.sort(key=lambda x: (x.get_attr_by_channel("x")[0].attribute, x.get_attr_by_channel("y")[0].attribute), reverse=False)
lux.config.ordering = sort_by_multiple

Copy link
Member

Choose a reason for hiding this comment

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

We didn't explain how lux.config.ordering can be used in the default case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants