A tool to display categories and subcategories based on hand-crafted predicates
Project description
Simple categorisation
Define categories and sub-categories with predicates, and categorise lists of items based on these categories:
cat = Categoriser()
# The category of items that are < 0.5
cat.add("x < 0.5", lambda x: x < 0.5)
# Items over 1
over_1 = cat.add("x >= 1", lambda x: x >= 1)
# Items between 1.1 and 1.2, as a subcategory of items over 1
over_1.add("1.2 > x >= 1.1", lambda x: 1.2 > x >= 1.1)
over_1.add("x > 1.2", lambda x: x >= 1.2)
result = cat.categorise_list([0.01, 0.6, 1.001, 1.05, 1.1, 1.2, 3])
summarised = result.summarise()
print(summarised)
This should show something along the lines of:
{
"categories": [
{"category_name": "x < 0.5", "matches": 1},
{
"category_name": "x >= 1", "matches": 5,
"categories": [
{"category_name": "1.2 > x >= 1.1", "matches": 1},
{"category_name": "x > 1.2", "matches": 2},
{"unmatched_items": 2}
]
},
{"unmatched_items": 1}
]
}
It is possible to obtain a Sankey diagram with plotly for the same example.
First, install plotly
pip install plotly
Then:
parameters = result.plotly_sankey(top_label="Top")
import plotly.graph_objects as go
fig = go.Figure(data=[go.Sankey(parameters)])
fig.update_layout(title_text="Example Sankey Diagram", font_size=20)
fig.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for simple-categorisation-0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ada655087a0902c33bb142764fd3c447ab50be7a92130f8a39ad47ec7659cb50 |
|
MD5 | c0c8adfbf046ab75be90f1d96650ba2a |
|
BLAKE2b-256 | 3b805058273f874e83c2c7b2cf6d74a84724c4703da47a29d6611966a7578e82 |
Close
Hashes for simple_categorisation-0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4974aad28bf8d927a6406e2dd16168d773362f4721988b37523c7d8247021d97 |
|
MD5 | a850374b9e741aa2fa409beac49cbe69 |
|
BLAKE2b-256 | c508882dddfb01e7f17102c2efc8868644a15fe8234da27a002d4f052d6df1da |