Skip to content

Commit

Permalink
Merge pull request #818 from thocevar/tests
Browse files Browse the repository at this point in the history
Compatibility with newest Numpy and Scipy.
  • Loading branch information
marinkaz committed Dec 18, 2015
2 parents 6c1841e + 893b7c8 commit 12f3261
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Orange/classification/naive_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def fit_storage(self, table):
raise NotImplementedError("Only discrete variables are supported.")

cont = contingency.get_contingencies(table)
class_freq = np.diag(
contingency.get_contingency(table, table.domain.class_var))
class_freq = np.array(np.diag(
contingency.get_contingency(table, table.domain.class_var)))
return NaiveBayesModel(cont, class_freq, table.domain)


Expand Down
6 changes: 5 additions & 1 deletion Orange/preprocess/discretize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ def __init__(self, variable, points):
super().__init__(variable)
self.points = points

@staticmethod
def digitize(x, bins):
return np.digitize(x, bins) if bins else [0]*len(x)

def transform(self, c):
if c.size:
return np.where(np.isnan(c), np.NaN, np.digitize(c, self.points))
return np.where(np.isnan(c), np.NaN, self.digitize(c, self.points))
else:
return np.array([], dtype=int)

Expand Down
2 changes: 1 addition & 1 deletion Orange/tests/test_clustering_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_kmeans(self):

def test_kmeans_parameters(self):
table = Orange.data.Table('iris')
kmeans = KMeans(n_clusters=20,
kmeans = KMeans(n_clusters=10,
max_iter=10,
random_state=42,
tol=0.001,
Expand Down
2 changes: 1 addition & 1 deletion Orange/tests/test_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_spearmanr_distance_many_examples(self):
[ 0.25, 0. , 0.25, 0. , 0. , 0. , 0.25, 0. , 0.75],
[ 0.25, 0.75, 0.25, 0.75, 0.75, 0.75, 1. , 0.75, 0. ]]))

def test_spearmanr_distacne_numpy(self):
def test_spearmanr_distance_numpy(self):
np.testing.assert_almost_equal(self.dist(self.breast[0].x, self.breast[1].x, axis=0), np.array([[0.5083333333333333]]))
np.testing.assert_almost_equal(self.dist(self.breast[:2].X),
np.array([[ 0. , 0.5083333333333333],
Expand Down
2 changes: 1 addition & 1 deletion Orange/tests/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def test_conversion(self):
x, y, metas = domain.convert([42, 13, "White"])
assert_array_equal(x, np.array([42, 13]))
assert_array_equal(y, np.array([0]))
assert_array_equal(metas, np.array([Unknown, Unknown, Unknown], dtype=object))
self.assertTrue(all(np.isnan(np.array(metas, dtype=float))))

x, y, metas = domain.convert([42, 13, "White", "M", "HS", "1234567"])
assert_array_equal(x, np.array([42, 13]))
Expand Down
6 changes: 3 additions & 3 deletions Orange/tests/test_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def test_transformed_domain_does_not_pickle_data(self):
def test_chain(self):
zoo = Orange.data.Table('zoo')
zoo_c = Continuize(zoo)
pca = PCA()(zoo_c)(zoo)
pca2 = PCA()(zoo_c)(zoo_c)
pca3 = PCA(preprocessors=[Continuize()])(zoo)(zoo)
pca = PCA(n_components=3)(zoo_c)(zoo)
pca2 = PCA(n_components=3)(zoo_c)(zoo_c)
pca3 = PCA(n_components=3, preprocessors=[Continuize()])(zoo)(zoo)
np.testing.assert_almost_equal(pca.X, pca2.X)
np.testing.assert_almost_equal(pca.X, pca3.X)

13 changes: 3 additions & 10 deletions Orange/tests/test_softmax_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@ def test_SoftmaxRegression(self):
self.assertTrue(0.9 < ca < 1.0)

def test_SoftmaxRegressionPreprocessors(self):
np.random.seed(42)
table = Table('iris')
new_attrs = (ContinuousVariable('c0'),) + table.domain.attributes
new_domain = Domain(new_attrs,
table.domain.class_vars,
table.domain.metas)
new_table = np.hstack((
1000000 * np.random.random((table.X.shape[0], 1)),
table))
table = table.from_numpy(new_domain, new_table)
table.X[:,2] = table.X[:,2] * 0.001
table.X[:,3] = table.X[:,3] * 0.001
learners = [SoftmaxRegressionLearner(preprocessors=[]),
SoftmaxRegressionLearner()]
results = CrossValidation(table, learners, k=3)
results = CrossValidation(table, learners, k=10)
ca = CA(results)
self.assertTrue(ca[0] < ca[1])

Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/utils/colorpalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def getRGB(self, values):
values = np.clip(values, 0, 1 - EPS)
bin = np.digitize(values, self.bins)
nans = bin >= len(self.bins)
bin[nans] = 0 # just so that the next two lines pass
values[nans] = bin[nans] = 0 # just so that the next two lines pass
p = (values - self.bins[bin - 1]) / self.deriv
results = np.round((1 - p) * self.colors[bin - 1].T + p * self.colors[bin].T).T.astype(int)
results[nans] = NAN_GREY
Expand Down

0 comments on commit 12f3261

Please sign in to comment.