Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG] Fix test class to be runnable by pytest #9860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions sklearn/neighbors/tests/test_dist_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,39 @@ def dist_func(x1, x2, p):
return np.sum((x1 - x2) ** p) ** (1. / p)


class TestMetrics:
def __init__(self, n1=20, n2=25, d=4, zero_frac=0.5,
rseed=0, dtype=np.float64):
rng = check_random_state(rseed)
self.X1 = rng.random_sample((n1, d)).astype(dtype)
self.X2 = rng.random_sample((n2, d)).astype(dtype)

# make boolean arrays: ones and zeros
self.X1_bool = self.X1.round(0)
self.X2_bool = self.X2.round(0)

V = rng.random_sample((d, d))
VI = np.dot(V, V.T)

self.metrics = {'euclidean': {},
'cityblock': {},
'minkowski': dict(p=(1, 1.5, 2, 3)),
'chebyshev': {},
'seuclidean': dict(V=(rng.random_sample(d),)),
'wminkowski': dict(p=(1, 1.5, 3),
w=(rng.random_sample(d),)),
'mahalanobis': dict(VI=(VI,)),
'hamming': {},
'canberra': {},
'braycurtis': {}}

self.bool_metrics = ['matching', 'jaccard', 'dice',
'kulsinski', 'rogerstanimoto', 'russellrao',
'sokalmichener', 'sokalsneath']
class TestMetrics(object):
n1 = 20
n2 = 25
d = 4
zero_frac = 0.5
rseed = 0
dtype = np.float64
rng = check_random_state(rseed)
X1 = rng.random_sample((n1, d)).astype(dtype)
X2 = rng.random_sample((n2, d)).astype(dtype)

# make boolean arrays: ones and zeros
X1_bool = X1.round(0)
X2_bool = X2.round(0)

V = rng.random_sample((d, d))
VI = np.dot(V, V.T)

metrics = {'euclidean': {},
'cityblock': {},
'minkowski': dict(p=(1, 1.5, 2, 3)),
'chebyshev': {},
'seuclidean': dict(V=(rng.random_sample(d),)),
'wminkowski': dict(p=(1, 1.5, 3),
w=(rng.random_sample(d),)),
'mahalanobis': dict(VI=(VI,)),
'hamming': {},
'canberra': {},
'braycurtis': {}}

bool_metrics = ['matching', 'jaccard', 'dice',
'kulsinski', 'rogerstanimoto', 'russellrao',
'sokalmichener', 'sokalsneath']

def test_cdist(self):
for metric, argdict in self.metrics.items():
Expand Down