Complexity API Reference
Complete API reference for complexity measures.
ComplexityMeasures
Main class for calculating complexity measures.
fairsample.complexity.ComplexityMeasures
User-friendly wrapper for ComplexityMetrics with all complexity measures.
This class provides easy access to all complexity measures with options to: - Get all measures at once - Get specific categories (feature/instance/structural/multiresolution) - Get specific measures by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
Feature matrix |
required |
y
|
array-like of shape (n_samples,)
|
Target vector |
required |
distance_func
|
str
|
Distance function to use |
"default"
|
Example
cm = ComplexityMeasures(X, y)
Get all measures
all_measures = cm.get_all_complexity_measures()
Get specific category
feature_measures = cm.get_all_complexity_measures(measures='feature')
Get specific measures
selected = cm.get_all_complexity_measures(measures=['N3', 'F1', 'N1'])
Quick analysis
basic = cm.analyze_overlap()
Source code in fairsample/complexity/measures.py
1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 | |
__init__(X, y, distance_func='default')
Initialize complexity measures calculator.
Source code in fairsample/complexity/measures.py
analyze_overlap(measures='basic')
Quick overlap analysis using essential measures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measures
|
str
|
Level of analysis: - 'basic': Essential measures (N3, N1, N2, F1, F2) - 'standard': Common measures - 'all': All available measures |
'basic'
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
dict
|
Dictionary containing complexity measures |
Source code in fairsample/complexity/measures.py
get_all_complexity_measures(k=5, imb=False, measures='all')
Get all available complexity measures in a structured format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of neighbors for k-NN based measures |
5
|
imb
|
bool
|
Whether to return class-specific values for imbalanced analysis |
False
|
measures
|
str or list
|
Which measures to calculate: - 'all': All available measures - 'basic': Essential measures (N3, N1, N2, F1, F2) - 'feature': Only feature overlap measures - 'instance': Only instance overlap measures - 'structural': Only structural overlap measures - 'multiresolution': Only multiresolution measures - list: Specific measure names (e.g., ['N3', 'F1', 'N1']) |
'all'
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
dict
|
Structured dictionary with all complexity measures |
Source code in fairsample/complexity/measures.py
1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 | |
Usage
from fairsample.complexity import ComplexityMeasures
# Create analyzer
cm = ComplexityMeasures(X, y)
# Get basic overlap measures
basic = cm.analyze_overlap()
# Get all measures
all_measures = cm.get_all_complexity_measures(measures='all')
# Get specific category
feature = cm.get_all_complexity_measures(measures='feature')
# Get specific measures
selected = cm.get_all_complexity_measures(measures=['N3', 'F1'])
Individual Measures
Feature Overlap
# F1 - Maximum Fisher's Discriminant Ratio
f1 = cm.calculate_F1()
# F1v - Directional-vector maximum Fisher's discriminant ratio
f1v = cm.calculate_F1v()
# F2 - Volume of overlapping region
f2 = cm.calculate_F2()
# F3 - Maximum individual feature efficiency
f3 = cm.calculate_F3()
# F4 - Collective feature efficiency
f4 = cm.calculate_F4()
# Input Noise
noise = cm.calculate_input_noise()
Instance Overlap
# N3 - Error rate of nearest neighbor
n3 = cm.calculate_N3()
# N4 - Non-linearity of nearest neighbor
n4 = cm.calculate_N4()
# kDN - k-Disagreeing neighbors
kdn = cm.calculate_kDN(k=5)
# CM - Class imbalance metric
cm_score = cm.calculate_CM()
# R-value - Overlap region size
r_value = cm.calculate_R_value()
# D3 - Disjunct class percentage
d3 = cm.calculate_D3()
# SI - Silhouette index
si = cm.calculate_SI()
# Borderline - Borderline instance ratio
borderline = cm.calculate_borderline()
# Degree of overlap
overlap = cm.calculate_degree_of_overlap()
Structural
# N1 - Fraction of borderline points
n1 = cm.calculate_N1()
# N2 - Ratio of intra/extra class nearest neighbor distance
n2 = cm.calculate_N2()
# T1 - Fraction of hyperspheres covering data
t1 = cm.calculate_T1()
# DBC - Distance-based complexity
dbc = cm.calculate_DBC()
# LSC - Local set cardinality
lsc = cm.calculate_LSC()
# Clust - Clustering measure
clust = cm.calculate_Clust()
# NSG - Number of spanning graphs
nsg = cm.calculate_NSG()
# ICSV - Inter-class to intra-class similarity variance
icsv = cm.calculate_ICSV()
# ONB - Overlap of neighborhoods between classes
onb = cm.calculate_ONB()
Multiresolution
# Purity
purity = cm.calculate_purity()
# Neighbourhood Separability
ns = cm.calculate_neighbourhood_separability()
# MRCA - Multiresolution complexity analysis
mrca = cm.calculate_MRCA()
# C1 - Entropy of class proportions
c1 = cm.calculate_C1()
# C2 - Imbalance ratio
c2 = cm.calculate_C2()
Utility Functions
compare_pre_post_overlap
Compare complexity before and after resampling.
from fairsample.complexity import compare_pre_post_overlap
comparison = compare_pre_post_overlap(
X_before, y_before,
X_after, y_after,
measures='basic'
)
print(comparison['before'])
print(comparison['after'])
print(comparison['improvements'])
Measure Categories
Use these strings with get_all_complexity_measures():
'all'- All 40+ measures'basic'- Quick subset (N3, F1, N1, T1, imbalance_ratio)'feature'- Feature overlap measures'instance'- Instance overlap measures'structural'- Structural measures'multiresolution'- Multiresolution measures['N3', 'F1', ...]- List of specific measures