robust-mixed-dist 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robust_mixed_dist-0.1.7/LICENSE +19 -0
- robust_mixed_dist-0.1.7/PKG-INFO +44 -0
- robust_mixed_dist-0.1.7/README.md +16 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist/__init__.py +0 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist/binary.py +110 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist/mixed.py +776 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist/multiclass.py +57 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist/quantitative.py +666 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist.egg-info/PKG-INFO +44 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist.egg-info/SOURCES.txt +13 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist.egg-info/dependency_links.txt +1 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist.egg-info/requires.txt +4 -0
- robust_mixed_dist-0.1.7/robust_mixed_dist.egg-info/top_level.txt +1 -0
- robust_mixed_dist-0.1.7/setup.cfg +4 -0
- robust_mixed_dist-0.1.7/setup.py +23 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: robust-mixed-dist
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: Compute statistical robust distances for mixed data.
|
|
5
|
+
Home-page: https://github.com/FabioScielzoOrtiz/robust_mixed_dist-package
|
|
6
|
+
Author: Fabio Scielzo Ortiz
|
|
7
|
+
Author-email: fabio.scielzoortiz@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: polars
|
|
15
|
+
Requires-Dist: numpy
|
|
16
|
+
Requires-Dist: pandas
|
|
17
|
+
Requires-Dist: scipy
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: classifier
|
|
21
|
+
Dynamic: description
|
|
22
|
+
Dynamic: description-content-type
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
Dynamic: summary
|
|
28
|
+
|
|
29
|
+
# robust-mixed-dist
|
|
30
|
+
|
|
31
|
+
Data scientists address real-world problems using multivariate and heterogeneous
|
|
32
|
+
datasets, characterized by multiple variables of different natures. Selecting a suitable
|
|
33
|
+
distance function between units is crucial, as many statistical techniques and machine
|
|
34
|
+
learning algorithms depend on this concept. Traditional distances, such as Euclidean
|
|
35
|
+
or Manhattan, are unsuitable for mixed-type data, and although Gower distance was
|
|
36
|
+
designed to handle this kind of data, it may lead to suboptimal results in the presence
|
|
37
|
+
of outlying units or underlying correlation structure.
|
|
38
|
+
|
|
39
|
+
In the paper ***Grané , Aurea; Scielzo-Ortiz, Fabio. “On generalized Gower distance for mixed-type data: extensive simulation study and new software tools”. SORT-Statistics and Operations Research Transactions, pp. 213-44, doi:10.57645/20.8080.02.28.*** robust distances for mixed-type data are defined and explored, namely **robust generalized Gower** and **robust related metric scaling**. In addition, the new Python package `robust-mixed-dist` is developed, which enables to
|
|
40
|
+
compute these robust proposals as well as classical ones.
|
|
41
|
+
|
|
42
|
+
The package is located in Python Package Index (PyPI), the standard repository of packages for the Python programming language: https://pypi.org/project/robust_mixed_dist/
|
|
43
|
+
|
|
44
|
+
**Package documentation** can be found here: https://fabioscielzoortiz.github.io/robust-mixed-dist-docu/intro.html
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# robust-mixed-dist
|
|
2
|
+
|
|
3
|
+
Data scientists address real-world problems using multivariate and heterogeneous
|
|
4
|
+
datasets, characterized by multiple variables of different natures. Selecting a suitable
|
|
5
|
+
distance function between units is crucial, as many statistical techniques and machine
|
|
6
|
+
learning algorithms depend on this concept. Traditional distances, such as Euclidean
|
|
7
|
+
or Manhattan, are unsuitable for mixed-type data, and although Gower distance was
|
|
8
|
+
designed to handle this kind of data, it may lead to suboptimal results in the presence
|
|
9
|
+
of outlying units or underlying correlation structure.
|
|
10
|
+
|
|
11
|
+
In the paper ***Grané , Aurea; Scielzo-Ortiz, Fabio. “On generalized Gower distance for mixed-type data: extensive simulation study and new software tools”. SORT-Statistics and Operations Research Transactions, pp. 213-44, doi:10.57645/20.8080.02.28.*** robust distances for mixed-type data are defined and explored, namely **robust generalized Gower** and **robust related metric scaling**. In addition, the new Python package `robust-mixed-dist` is developed, which enables to
|
|
12
|
+
compute these robust proposals as well as classical ones.
|
|
13
|
+
|
|
14
|
+
The package is located in Python Package Index (PyPI), the standard repository of packages for the Python programming language: https://pypi.org/project/robust_mixed_dist/
|
|
15
|
+
|
|
16
|
+
**Package documentation** can be found here: https://fabioscielzoortiz.github.io/robust-mixed-dist-docu/intro.html
|
|
File without changes
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import polars as pl
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from scipy.spatial import distance
|
|
4
|
+
from scipy.spatial.distance import pdist, squareform
|
|
5
|
+
|
|
6
|
+
################################################################################
|
|
7
|
+
|
|
8
|
+
def sokal_dist_matrix(X):
|
|
9
|
+
"""
|
|
10
|
+
Calculates the Sokal distance matrix for a data matrix `X` using SciPy.
|
|
11
|
+
|
|
12
|
+
Parameters (inputs)
|
|
13
|
+
----------
|
|
14
|
+
X: a pandas/polars DataFrame or a NumPy array. It represents a data matrix.
|
|
15
|
+
|
|
16
|
+
Returns (outputs)
|
|
17
|
+
-------
|
|
18
|
+
M: the Sokal distance matrix between the rows of X.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
if isinstance(X, pl.DataFrame):
|
|
22
|
+
X = X.to_numpy()
|
|
23
|
+
if isinstance(X, pd.DataFrame):
|
|
24
|
+
X = X.to_numpy()
|
|
25
|
+
|
|
26
|
+
# Compute the pairwise distances using pdist and convert to a square form.
|
|
27
|
+
M = squareform(pdist(X, metric='sokalmichener'))
|
|
28
|
+
|
|
29
|
+
return M
|
|
30
|
+
|
|
31
|
+
################################################################################
|
|
32
|
+
|
|
33
|
+
def sokal_dist(xi, xr) :
|
|
34
|
+
"""
|
|
35
|
+
Calculates the Sokal distance between a pair of vectors.
|
|
36
|
+
|
|
37
|
+
Parameters (inputs)
|
|
38
|
+
----------
|
|
39
|
+
xi, xr: a pair of quantitative vectors. They represent a couple of statistical observations.
|
|
40
|
+
|
|
41
|
+
Returns (outputs)
|
|
42
|
+
-------
|
|
43
|
+
The Sokal distance between the observations `xi` and `xr`.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
if isinstance(xi, (pl.DataFrame, pd.DataFrame)) :
|
|
47
|
+
xi = xi.to_numpy().flatten()
|
|
48
|
+
elif isinstance(xi, (pd.Series, pl.Series)) :
|
|
49
|
+
xi = xi.to_numpy()
|
|
50
|
+
if isinstance(xr, (pl.DataFrame, pd.DataFrame)) :
|
|
51
|
+
xr = xr.to_numpy().flatten()
|
|
52
|
+
elif isinstance(xr, (pd.Series, pl.Series)) :
|
|
53
|
+
xr = xr.to_numpy()
|
|
54
|
+
|
|
55
|
+
return distance.sokalmichener(xi, xr)
|
|
56
|
+
|
|
57
|
+
################################################################################
|
|
58
|
+
|
|
59
|
+
def jaccard_dist_matrix(X):
|
|
60
|
+
"""
|
|
61
|
+
Calculates the Jaccard distance matrix for a data matrix `X` using SciPy.
|
|
62
|
+
|
|
63
|
+
Parameters (inputs)
|
|
64
|
+
----------
|
|
65
|
+
X: a pandas/polars DataFrame or a NumPy array. It represents a data matrix.
|
|
66
|
+
|
|
67
|
+
Returns (outputs)
|
|
68
|
+
-------
|
|
69
|
+
M: the Jaccard distance matrix between the rows of X.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
if isinstance(X, pl.DataFrame):
|
|
73
|
+
X = X.to_numpy()
|
|
74
|
+
if isinstance(X, pd.DataFrame):
|
|
75
|
+
X = X.to_numpy()
|
|
76
|
+
|
|
77
|
+
# Compute the pairwise distances using pdist and convert to a square form.
|
|
78
|
+
M = squareform(pdist(X, metric='jaccard'))
|
|
79
|
+
|
|
80
|
+
return M
|
|
81
|
+
|
|
82
|
+
################################################################################
|
|
83
|
+
|
|
84
|
+
def jaccard_dist(xi, xr) :
|
|
85
|
+
"""
|
|
86
|
+
Calculates the Jaccard distance between a pair of vectors.
|
|
87
|
+
|
|
88
|
+
Parameters (inputs)
|
|
89
|
+
----------
|
|
90
|
+
xi, xr: a pair of quantitative vectors. They represent a couple of statistical observations.
|
|
91
|
+
|
|
92
|
+
Returns (outputs)
|
|
93
|
+
-------
|
|
94
|
+
The Jaccard distance between the observations `xi` and `xr`.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
if isinstance(xi, (pl.DataFrame, pd.DataFrame)) :
|
|
98
|
+
xi = xi.to_numpy().flatten()
|
|
99
|
+
elif isinstance(xi, (pd.Series, pl.Series)) :
|
|
100
|
+
xi = xi.to_numpy()
|
|
101
|
+
if isinstance(xr, (pl.DataFrame, pd.DataFrame)) :
|
|
102
|
+
xr = xr.to_numpy().flatten()
|
|
103
|
+
elif isinstance(xr, (pd.Series, pl.Series)) :
|
|
104
|
+
xr = xr.to_numpy()
|
|
105
|
+
|
|
106
|
+
return distance.jaccard(xi, xr)
|
|
107
|
+
|
|
108
|
+
################################################################################
|
|
109
|
+
|
|
110
|
+
|