Skip to main content

Phi_K correlation analyzer library

Project description

Phi_K is a practical correlation constant that works consistently between categorical, ordinal and interval variables. It is based on several refinements to Pearson’s hypothesis test of independence of two variables. Essentially, the contingency test statistic of two variables is interpreted as coming from a rotated bi-variate normal distribution, where the tilt is interpreted as Phi_K.

The combined features of Phi_K form an advantage over existing coefficients. First, it works consistently between categorical, ordinal and interval variables. Second, it captures non-linear dependency. Third, it reverts to the Pearson correlation coefficient in case of a bi-variate normal input distribution. These are useful features when studying the correlation matrix of variables with mixed types.

For details on the methodology behind the calculations, please see our publication. Emphasis is paid to the proper evaluation of statistical significance of correlations and to the interpretation of variable relationships in a contingency table, in particular in case of low statistics samples. The presented algorithms are easy to use and available through this public Python library.

Example notebooks

Static link

Google Colab link

basic tutorial

basic on colab

advanced tutorial (detailed configuration)

advanced on colab

spark tutorial

no spark available

Documentation

The entire Phi_K documentation including tutorials can be found at read-the-docs. See the tutorials for detailed examples on how to run the code with pandas. We also have one example on how calculate the Phi_K correlation matrix for a spark dataframe.

Check it out

The Phi_K library requires Python >= 3.7 and is pip friendly. To get started, simply do:

$ pip install phik

or check out the code from out GitHub repository:

$ git clone https://github.com/KaveIO/PhiK.git
$ pip install -e PhiK/

where in this example the code is installed in edit mode (option -e).

You can now use the package in Python with:

import phik

Congratulations, you are now ready to use the PhiK correlation analyzer library!

Quick run

As a quick example, you can do:

import pandas as pd
import phik
from phik import resources, report

# open fake car insurance data
df = pd.read_csv( resources.fixture('fake_insurance_data.csv.gz') )
df.head()

# Pearson's correlation matrix between numeric variables (pandas functionality)
df.corr()

# get the phi_k correlation matrix between all variables
df.phik_matrix()

# get global correlations based on phi_k correlation matrix
df.global_phik()

# get the significance matrix (expressed as one-sided Z)
# of the hypothesis test of each variable-pair dependency
df.significance_matrix()

# contingency table of two columns
cols = ['mileage','car_size']
df[cols].hist2d()

# normalized residuals of contingency test applied to cols
df[cols].outlier_significance_matrix()

# show the normalized residuals of each variable-pair
df.outlier_significance_matrices()

# generate a phik correlation report and save as test.pdf
report.correlation_report(df, pdf_file_name='test.pdf')

For all available examples, please see the tutorials at read-the-docs.

Contact and support

Please note that support is (only) provided on a best-effort basis.

Project details


Download files

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

Source Distribution

phik-0.12.1.tar.gz (600.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

phik-0.12.1-cp310-cp310-win_amd64.whl (701.2 kB view details)

Uploaded CPython 3.10Windows x86-64

phik-0.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (734.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

phik-0.12.1-cp310-cp310-macosx_10_13_x86_64.whl (692.1 kB view details)

Uploaded CPython 3.10macOS 10.13+ x86-64

phik-0.12.1-cp39-cp39-win_amd64.whl (683.2 kB view details)

Uploaded CPython 3.9Windows x86-64

phik-0.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (706.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

phik-0.12.1-cp39-cp39-macosx_10_13_x86_64.whl (673.8 kB view details)

Uploaded CPython 3.9macOS 10.13+ x86-64

phik-0.12.1-cp38-cp38-win_amd64.whl (674.7 kB view details)

Uploaded CPython 3.8Windows x86-64

phik-0.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (693.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

phik-0.12.1-cp38-cp38-macosx_10_13_x86_64.whl (665.0 kB view details)

Uploaded CPython 3.8macOS 10.13+ x86-64

phik-0.12.1-cp37-cp37m-win_amd64.whl (670.9 kB view details)

Uploaded CPython 3.7mWindows x86-64

phik-0.12.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (687.8 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

phik-0.12.1-cp37-cp37m-macosx_10_13_x86_64.whl (660.3 kB view details)

Uploaded CPython 3.7mmacOS 10.13+ x86-64

File details

Details for the file phik-0.12.1.tar.gz.

File metadata

  • Download URL: phik-0.12.1.tar.gz
  • Upload date:
  • Size: 600.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1.tar.gz
Algorithm Hash digest
SHA256 63cf160c8950ec46da7a33165deef57f27d29f24b83cf4dd028aa0cb97b73af6
MD5 e06e72e07242216bf73c0bef6581c890
BLAKE2b-256 029c812ffada4a026ad20ad30318897b46ce3cc46e2eec61a3d9d1cf6699f79a

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: phik-0.12.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 701.2 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bffcf7c1a3746413cd240adc07c917d477e8c2b3326b5fed75467282f13e3471
MD5 d1e4f5147dd4d9e27bee0521c019a586
BLAKE2b-256 199ab2c6544f25a94b906cbba9a42a8acca1a67faceca48c46b36718c73d8f00

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: phik-0.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 734.6 kB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb9a4f9f8ecb0211510e9b9edf1175b66407b66be7bc2df9425a7a89f645c14d
MD5 6236f50b64ac75d2131d12d9daec3350
BLAKE2b-256 5f3f27cfdf72e5adf0f822fd2b57fddf9a6fa62a8c5d04db4612398d0e3700e6

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp310-cp310-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: phik-0.12.1-cp310-cp310-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 692.1 kB
  • Tags: CPython 3.10, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 7de13f1d71dc98f73deef0ddf0115e44348f93185f72e4984308f0158f8370d8
MD5 ae98c83eda050423557ae653bbed2755
BLAKE2b-256 e90c8c2892cb64a7a435385fe782416cab41524794d7a7b5e8ac3fc80fb1e594

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: phik-0.12.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 683.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e7e66758a7b7d68fb56a2dd25d2b938ac52377c18ea862edc32ae12e26e88a8b
MD5 6d756489c70bb5266b25674b733f76cd
BLAKE2b-256 ad0dd501a0d46e589392c63f37abbcb0b5e6faa84b8280c60498c959071cc911

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: phik-0.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 706.8 kB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe7fbd4aa4c9d6b1463d5e6c2ee0edf82572b8458177bd16ad0f32ae367ae8a2
MD5 92296597634ca14457e6cb239020d011
BLAKE2b-256 c736c3ec9172e9f08a57d5d5ee895f1e9116042fc6c8c0e5499832782ab1eba2

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp39-cp39-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: phik-0.12.1-cp39-cp39-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 673.8 kB
  • Tags: CPython 3.9, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 f24808eb604408e3c726b145ae6e62297fd3923ccdfde55a3cab4192ea6988bd
MD5 b56b84d466fe8565e1cacc2e8b54e18a
BLAKE2b-256 224fc597567e6199ebdf5d344ec9225da09cd43a5db1d3a5721cbf7fdd7533cb

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: phik-0.12.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 674.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d5d3a4a6d67ff5eb67357d8177a1ae1e3a086940f6094d45204cb8239d929d90
MD5 185ef84ee2da4ce0ff40192498f6d337
BLAKE2b-256 d6d501fd6478872c3e71afdf9d3af65f366b2ee8ae805cd712191bde9edf537f

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: phik-0.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 693.5 kB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1239ece3bd99f3d7fe16e4e653ef8e1d5db25ecaadf18d3a3ddc9ca684e84907
MD5 f189f028e96f2ef499265f96cc04f6ff
BLAKE2b-256 6d5c2730a8b4fb2774198b8f4f62678adbc1a441287f712023270375f70b1824

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp38-cp38-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: phik-0.12.1-cp38-cp38-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 665.0 kB
  • Tags: CPython 3.8, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 32565bc5d288eaf3f55519914eb5954fe3cd384cede91d25c79fb8f7cb46a533
MD5 d90c1da380da9bcf5fd73a8f3d205ce7
BLAKE2b-256 65e54bbf3485e2e8a94fdc0361e2126427cc7b83ab18505a05c40f9c6c00133e

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: phik-0.12.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 670.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 f40664e93dd3bd4b8323120dca8834812be16d09b928dd712bce8d5b785c5a0e
MD5 4addf73e76c833fdaaca75283793d3c2
BLAKE2b-256 f514a9e4a1c2a165b469d28350215a85e7ad39064d76d9286c65e64d1bad80e6

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: phik-0.12.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 687.8 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bdc4dc2027f099a156112957fd65513adcc785b5c942fa37a4243d4d5483ef2d
MD5 b9f057e26aab70f8ffaf49582c73d155
BLAKE2b-256 eb33714fcc57083a013cfbb7af1102fca92ec4b879e2c2b642551536d4643e3e

See more details on using hashes here.

File details

Details for the file phik-0.12.1-cp37-cp37m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: phik-0.12.1-cp37-cp37m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 660.3 kB
  • Tags: CPython 3.7m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for phik-0.12.1-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 e3e9a33277dcdd4369a2b58762cf3de2b10eb3acbd555f15e7a1df8e87337450
MD5 af064f02fb9b1e1fc69d7db741ab3882
BLAKE2b-256 8472b16b2f4f31f378e6b7e1b2caacdda3654286ab461eb7e0e74d9c6133c94e

See more details on using hashes here.

Supported by

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