Skip to main content

Draw Logistic Regression Plots in Python

Project description

Run Pytest Coverage Code style: black DOI PyPI version

lorepy: Logistic Regression Plots for Python

Logistic Regression plots are used to plot the distribution of a categorical dependent variable in function of a continuous independent variable.

LoRePlot example on Iris Dataset

Installation

Lorepy can be installed using pip using the command below.

pip install lorepy

Usage

Data needs to be provided as a DataFrame and the columns for the x (independent continuous) and y (dependant categorical) variables need to be defined. Here the iris dataset is loaded and converted to an appropriate DataFrame. Once the data is in shape it can be plotted using a single line of code loreplot(data=iris_df, x="sepal width (cm)", y="species").

from lorepy import loreplot

from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
import pandas as pd

iris_obj = load_iris()
iris_df = pd.DataFrame(iris_obj.data, columns=iris_obj.feature_names)

iris_df["species"] = [iris_obj.target_names[s] for s in iris_obj.target]

loreplot(data=iris_df, x="sepal width (cm)", y="species")

plt.show()

Options

While lorepy has very few customizations, it is possible to pass arguments through to Pandas' DataFrame.plot.area and Matplotlib's pyplot.scatter to change the aesthetics of the plots.

Disable sample dots

Dots indicating where samples are located can be en-/disabled using the add_dots argument.

loreplot(data=iris_df, x="sepal width (cm)", y="species", add_dots=False)
plt.show()

LoRePlot dots can be disabled

Custom styles

Additional keyword arguments are passed to Pandas' DataFrame.plot.area. This can be used, among other things, to define a custom colormap. For more options to customize these plots consult Pandas' documentation.

from matplotlib.colors import ListedColormap

colormap=ListedColormap(['red', 'green', 'blue'])

loreplot(data=iris_df, x="sepal width (cm)", y="species", colormap=colormap)
plt.show()

LoRePlot custom colors

Using scatter_kws arguments for pyplot.scatter can be set to change the appearance of the sample markers.

scatter_options = {
    's': 20,                  # Marker size
    'alpha': 1,               # Fully opaque
    'color': 'black',         # Set color to black
    'marker': 'x'             # Set style to crosses
}

loreplot(data=iris_df, x="sepal width (cm)", y="species", scatter_kws=scatter_options)
plt.show()

LoRePlot custom markers

You can use LoRePlots in subplots as you would expect.

fig, ax = plt.subplots(1,2, sharex=False, sharey=True)
loreplot(data=iris_df, x="sepal width (cm)", y="species", ax=ax[0])
loreplot(data=iris_df, x="petal width (cm)", y="species", ax=ax[1])

ax[0].get_legend().remove()
ax[0].set_title("Sepal Width")
ax[1].set_title("Petal Width")

plt.savefig('./docs/img/loreplot_subplot.png', dpi=150)
plt.show()

LoRePlot in subplots

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

lorepy-0.1.1-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page