|
5 | 5 | import numpy as np |
6 | 6 |
|
7 | 7 | from Orange.data import Table |
| 8 | +from Orange.preprocess import Continuize |
8 | 9 | from Orange.projection import FreeViz |
9 | 10 |
|
10 | 11 |
|
@@ -72,3 +73,29 @@ def test_initial(self): |
72 | 73 | FreeViz.init_radial(2) |
73 | 74 | FreeViz.init_radial(3) |
74 | 75 | FreeViz.init_random(2, 4, 5) |
| 76 | + |
| 77 | + def test_transform_changed_domain(self): |
| 78 | + """ |
| 79 | + 1. Open data, apply some preprocessor, splits the data into two parts, |
| 80 | + use FreeViz on the first part, and then transform the second part. |
| 81 | +
|
| 82 | + 2. Open data, split into two parts, apply the same preprocessor and |
| 83 | + FreeViz only on the first part, and then transform the second part. |
| 84 | +
|
| 85 | + The transformed second part in (1) and (2) has to be the same. |
| 86 | + """ |
| 87 | + data = Table("titanic")[::10] |
| 88 | + normalize = Continuize() |
| 89 | + freeviz = FreeViz(maxiter=40) |
| 90 | + |
| 91 | + # normalize all |
| 92 | + ndata = normalize(data) |
| 93 | + model = freeviz(ndata[:100]) |
| 94 | + result_1 = model(ndata[100:]) |
| 95 | + |
| 96 | + # normalize only the "training" part |
| 97 | + ndata = normalize(data[:100]) |
| 98 | + model = freeviz(ndata) |
| 99 | + result_2 = model(data[100:]) |
| 100 | + |
| 101 | + np.testing.assert_almost_equal(result_1.X, result_2.X) |
0 commit comments