sumplot
provides some very simple functionality to discretise, summarise and plot variables.
The example below uses the diabetes data and will summarise the variables s1
, s2
and s3
by age
and bmi
which are both discretised according to specific quantiles.
from sklearn.datasets import load_diabetes
from sumnplot.discretisation import QuantileDiscretiser
from sumnplot.summary import ColumnSummariser
from sumnplot.plot.matplotlib import plot_summarised_variable_2way
X, y = load_diabetes(return_X_y=True, as_frame=True)
X["s1"] = X["s1"] - X["s1"].min()
two_way_summary = ColumnSummariser._summarise_column(
df=X,
to_summarise_columns=["s1", "s2", "s3"],
to_summarise_columns_labels=["obs", "p1", "p2"],
to_summarise_divide_column="s1",
by_column=QuantileDiscretiser(
variable="age", quantiles=(0, 0.25, 0.5, 0.75, 1.0)
),
second_by_column=QuantileDiscretiser(
variable="bmi", quantiles=(0, 0.33, 0.66, 1.0)
),
)
plot_summarised_variable_2way(
two_way_summary,
axis_right=0,
axis_left=[1, 2],
bar_type="stacked",
bars_percent=True,
)
The easiest way to get sumnplot
is directly from pypi using;
pip install sumnplot
Documentation can be found at readthedocs.
For information on how to build the documentation locally see the docs README.
There are various example notebooks demonstrating how to use the package in the demo folder in the repo.
To open the example notebooks in binder click here or click on the launch binder
shield above and then click on the directory button in the side bar to the left to navigate to the specific notebook.
sumnplot
uses flit as the package build tool.
To install sumnplot
for development, use the following commands from the root directory;
pip install "flit>=3.2,<4"
flit install
The default deps
flag for flit
is all
so this will install all of the libraries required for testing and creating the docs.
To install sumnplot
in editable mode (i.e. the equivalent of pip install . -e
) use the symlink
flag;
flit install --symlink
See the flit docs for all the command line options for flit
.