99import scipy .spatial
1010import scipy .stats
1111from scipy .sparse import csr_matrix
12+ from sklearn .exceptions import DataConversionWarning
1213
1314from Orange .data import (Table , Domain , ContinuousVariable ,
1415 DiscreteVariable , StringVariable , Instance )
@@ -58,11 +59,11 @@ def test_deprecated(self):
5859
5960 def test_from_file (self ):
6061 with named_file (
61- """3 axis=0 asymmetric col_labels row_labels
62- ann bert chad
63- danny 0.12 3.45 6.78
64- eve 9.01 2.34 5.67
65- frank 8.90 1.23 4.56""" ) as name :
62+ """3 axis=0 asymmetric col_labels row_labels
63+ ann bert chad
64+ danny 0.12 3.45 6.78
65+ eve 9.01 2.34 5.67
66+ frank 8.90 1.23 4.56""" ) as name :
6667 m = DistMatrix .from_file (name )
6768 np .testing .assert_almost_equal (m , np .array ([[0.12 , 3.45 , 6.78 ],
6869 [9.01 , 2.34 , 5.67 ],
@@ -76,10 +77,10 @@ def test_from_file(self):
7677 self .assertEqual (m .axis , 0 )
7778
7879 with named_file (
79- """3 axis=1 row_labels
80- danny 0.12 3.45 6.78
81- eve 9.01 2.34 5.67
82- frank 8.90""" ) as name :
80+ """3 axis=1 row_labels
81+ danny 0.12 3.45 6.78
82+ eve 9.01 2.34 5.67
83+ frank 8.90""" ) as name :
8384 m = DistMatrix .from_file (name )
8485 np .testing .assert_almost_equal (m , np .array ([[0.12 , 9.01 , 8.90 ],
8586 [9.01 , 2.34 , 0 ],
@@ -499,26 +500,27 @@ def test_jaccard_distance_many_examples(self):
499500 [0. , 0. , 0.5 ]]))
500501
501502 def test_jaccard_distance_numpy (self ):
502- np .testing .assert_almost_equal (
503- self .dist (self .titanic [0 ].x , self .titanic [2 ].x , axis = 1 ),
504- np .array ([[0.5 ]]))
505- np .testing .assert_almost_equal (
506- self .dist (self .titanic .X ),
507- np .array ([[0. , 0. , 0.5 , 0.5 ],
508- [0. , 0. , 0.5 , 0.5 ],
509- [0.5 , 0.5 , 0. , 0. ],
510- [0.5 , 0.5 , 0. , 0. ]]))
511- np .testing .assert_almost_equal (
512- self .dist (self .titanic [2 ].x , self .titanic [:3 ].X ),
513- np .array ([[0.5 , 0.5 , 0. ]]))
514- np .testing .assert_almost_equal (
515- self .dist (self .titanic [:2 ].X , self .titanic [3 ].x ),
516- np .array ([[0.5 ],
517- [0.5 ]]))
518- np .testing .assert_almost_equal (
519- self .dist (self .titanic [:2 ].X , self .titanic [:3 ].X ),
520- np .array ([[0. , 0. , 0.5 ],
521- [0. , 0. , 0.5 ]]))
503+ with self .assertWarns (DataConversionWarning ):
504+ np .testing .assert_almost_equal (
505+ self .dist (self .titanic [0 ].x , self .titanic [2 ].x , axis = 1 ),
506+ np .array ([[0.5 ]]))
507+ np .testing .assert_almost_equal (
508+ self .dist (self .titanic .X ),
509+ np .array ([[0. , 0. , 0.5 , 0.5 ],
510+ [0. , 0. , 0.5 , 0.5 ],
511+ [0.5 , 0.5 , 0. , 0. ],
512+ [0.5 , 0.5 , 0. , 0. ]]))
513+ np .testing .assert_almost_equal (
514+ self .dist (self .titanic [2 ].x , self .titanic [:3 ].X ),
515+ np .array ([[0.5 , 0.5 , 0. ]]))
516+ np .testing .assert_almost_equal (
517+ self .dist (self .titanic [:2 ].X , self .titanic [3 ].x ),
518+ np .array ([[0.5 ],
519+ [0.5 ]]))
520+ np .testing .assert_almost_equal (
521+ self .dist (self .titanic [:2 ].X , self .titanic [:3 ].X ),
522+ np .array ([[0. , 0. , 0.5 ],
523+ [0. , 0. , 0.5 ]]))
522524
523525
524526# noinspection PyTypeChecker
0 commit comments