22# pylint: disable=missing-docstring
33
44from unittest import TestCase
5- import os
65import pickle
76
87import numpy as np
@@ -214,11 +213,6 @@ def test_euclidean_distance_many_examples(self):
214213 np .testing .assert_almost_equal (self .dist (self .iris [:2 ], self .iris [:3 ]),
215214 np .array ([[0. , 0.53851648 , 0.50990195 ],
216215 [0.53851648 , 0. , 0.3 ]]))
217- np .testing .assert_almost_equal (self .dist (self .iris [:2 ], self .iris [:2 ], axis = 0 ),
218- np .array ([[0. , 2.48394847 , 5.09313263 , 6.78969808 ],
219- [2.48394847 , 0. , 2.64007576 , 4.327817 ],
220- [5.09313263 , 2.64007576 , 0. , 1.69705627 ],
221- [6.78969808 , 4.327817 , 1.69705627 , 0. ]]))
222216
223217 def test_euclidean_distance_sparse (self ):
224218 np .testing .assert_almost_equal (self .dist (self .sparse ),
@@ -281,11 +275,6 @@ def test_manhattan_distance_many_examples(self):
281275 np .testing .assert_almost_equal (self .dist (self .iris [:2 ], self .iris [:3 ]),
282276 np .array ([[0. , 0.7 , 0.8 ],
283277 [0.7 , 0. , 0.5 ]]))
284- np .testing .assert_almost_equal (self .dist (self .iris [:2 ], self .iris [:2 ], axis = 0 ),
285- np .array ([[0. , 3.5 , 7.2 , 9.6 ],
286- [3.5 , 0. , 3.7 , 6.1 ],
287- [7.2 , 3.7 , 0. , 2.4 ],
288- [9.6 , 6.1 , 2.4 , 0. ]]))
289278
290279 def test_manhattan_distance_sparse (self ):
291280 np .testing .assert_almost_equal (self .dist (self .sparse ),
@@ -347,11 +336,6 @@ def test_cosine_distance_many_examples(self):
347336 np .testing .assert_almost_equal (self .dist (self .iris [:2 ], self .iris [:3 ]),
348337 np .array ([[0.0 , 1.42083650e-03 , 1.26527175e-05 ],
349338 [1.42083650e-03 , 0.0 , 1.20854727e-03 ]]))
350- np .testing .assert_almost_equal (self .dist (self .iris [:2 ], self .iris [:2 ], axis = 0 ),
351- np .array ([[0.0 , 1.61124231e-03 , 1.99940020e-04 , 1.99940020e-04 ],
352- [1.61124231e-03 , 0.0 , 2.94551450e-03 , 2.94551450e-03 ],
353- [1.99940020e-04 , 2.94551450e-03 , 0.0 , 0.0 ],
354- [1.99940020e-04 , 2.94551450e-03 , 0.0 , 0.0 ]]))
355339
356340 def test_cosine_distance_sparse (self ):
357341 np .testing .assert_almost_equal (self .dist (self .sparse ),
@@ -413,10 +397,6 @@ def test_jaccard_distance_many_examples(self):
413397 np .testing .assert_almost_equal (self .dist (self .titanic [:2 ], self .titanic [:3 ]),
414398 np .array ([[0. , 0. , 0.5 ],
415399 [0. , 0. , 0.5 ]]))
416- np .testing .assert_almost_equal (self .dist (self .titanic , self .titanic , axis = 0 ),
417- np .array ([[0. , 1. , 0.5 ],
418- [1. , np .nan , 1. ],
419- [0.5 , 1. , 0. ]]))
420400
421401 def test_jaccard_distance_numpy (self ):
422402 np .testing .assert_almost_equal (self .dist (self .titanic [0 ].x , self .titanic [2 ].x , axis = 1 ), np .array ([[0.5 ]]))
@@ -771,14 +751,6 @@ def test_iris(self):
771751 self .assertEqual (metric (tab ).shape , (150 , 150 ))
772752 self .assertEqual (metric (tab [0 ], tab [1 ]).shape , (1 , 1 ))
773753
774- def test_axis (self ):
775- mah = MahalanobisDistance (self .x , axis = 1 )
776- self .assertEqual (mah (self .x , self .x ).shape , (self .n , self .n ))
777- x = self .x .T
778- mah = MahalanobisDistance (x , axis = 0 )
779- self .assertRaises (AssertionError , mah , x , axis = 1 )
780- self .assertEqual (mah (x , x ).shape , (self .n , self .n ))
781-
782754 def test_dimensions (self ):
783755 x = Table ('iris' )[:20 ].X
784756 xt = Table ('iris' )[:20 ].X .T
@@ -787,17 +759,6 @@ def test_dimensions(self):
787759 mah = MahalanobisDistance (xt )
788760 mah (xt [0 ], xt [1 ])
789761
790- def test_global_is_borked (self ):
791- """
792- Test that the global state retaining non-safe Mahalanobis instance
793- raises RuntimeErrors on all invocations
794- """
795- from Orange .distance import Mahalanobis
796- with self .assertRaises (RuntimeError ):
797- Mahalanobis .fit (self .x )
798- with self .assertRaises (RuntimeError ):
799- Mahalanobis (self .x )
800-
801762
802763class TestDistances (TestCase ):
803764 @classmethod
0 commit comments