Skip to content

Commit

Permalink
Merge pull request #6805 from VesnaT/pls_names
Browse files Browse the repository at this point in the history
PLS: Rename loadings, change U/T order
  • Loading branch information
lanzagar committed May 17, 2024
2 parents ccc6cc3 + b798933 commit 38c7b96
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion Orange/regression/pls.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def trvar(i, name):
domain = Domain(
[trvar(i, var_names_X[i]) for i in range(n_components)],
data.domain.class_vars,
list(data.domain.metas) +
[trvar(n_components + i, var_names_Y[i]) for i in
range(n_components)]
)
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/model/owpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _create_output_coeffs_loadings(self) -> Table:
n_components = x_rotations.shape[1]

names = [f"coef ({v.name})" for v in self.model.domain.class_vars]
names += [f"Loading {i + 1}" for i in range(n_components)]
names += [f"w*c {i + 1}" for i in range(n_components)]
domain = Domain(
[ContinuousVariable(n) for n in names],
metas=[StringVariable("Variable name"),
Expand All @@ -98,7 +98,7 @@ def _create_output_data(self) -> Table:
proj_domain = projection.domain
nprobs_domain = normal_probs.domain
dmodx_domain = dmodx.domain
metas = proj_domain.metas + proj_domain.attributes + \
metas = data_domain.metas + proj_domain.attributes + proj_domain.metas + \
nprobs_domain.attributes + dmodx_domain.attributes
domain = Domain(data_domain.attributes, data_domain.class_vars, metas)
data: Table = self.data.transform(domain)
Expand Down
16 changes: 8 additions & 8 deletions Orange/widgets/model/tests/test_owpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_output_coefsdata(self):
self.assertEqual(coefsdata.Y.shape, (14, 0))
self.assertEqual(coefsdata.metas.shape, (14, 2))

self.assertEqual(["coef (MEDV)", "Loading 1", "Loading 2"],
self.assertEqual(["coef (MEDV)", "w*c 1", "w*c 2"],
[v.name for v in coefsdata.domain.attributes])
self.assertEqual(["Variable name", "Variable role"],
[v.name for v in coefsdata.domain.metas])
Expand All @@ -57,7 +57,7 @@ def test_output_coefsdata_multi_target(self):
self.assertEqual(coefsdata.Y.shape, (14, 0))
self.assertEqual(coefsdata.metas.shape, (14, 2))

attr_names = ["coef (MEDV)", "coef (CRIM)", "Loading 1", "Loading 2"]
attr_names = ["coef (MEDV)", "coef (CRIM)", "w*c 1", "w*c 2"]
self.assertEqual(attr_names,
[v.name for v in coefsdata.domain.attributes])
self.assertEqual(["Variable name", "Variable role"],
Expand All @@ -78,7 +78,7 @@ def test_output_data(self):
self.assertEqual(output.metas.shape, (506, 8))
self.assertEqual([v.name for v in self._data.domain.variables],
[v.name for v in output.domain.variables])
metas = ["PLS U1", "PLS U2", "PLS T1", "PLS T2",
metas = ["PLS T1", "PLS T2", "PLS U1", "PLS U2",
"Sample Quantiles (MEDV)", "Theoretical Quantiles (MEDV)",
"DModX"]
self.assertEqual([v.name for v in self._data.domain.metas] + metas,
Expand All @@ -93,7 +93,7 @@ def test_output_data_multi_target(self):
orig_domain = self._data_multi_target.domain
self.assertEqual([v.name for v in orig_domain.variables],
[v.name for v in output.domain.variables])
metas = ["PLS U1", "PLS U2", "PLS T1", "PLS T2",
metas = ["PLS T1", "PLS T2", "PLS U1", "PLS U2",
"Sample Quantiles (MEDV)", "Theoretical Quantiles (MEDV)",
"Sample Quantiles (CRIM)", "Theoretical Quantiles (CRIM)",
"DModX"]
Expand All @@ -119,10 +119,10 @@ def test_missing_target(self):
data.Y[[0, 4]] = np.nan
self.send_signal(self.widget.Inputs.data, data)
output = self.get_output(self.widget.Outputs.data)
self.assertFalse(np.isnan(output.metas[:, 3:].astype(float)).any())
self.assertTrue(np.isnan(output.metas[0, 1:3].astype(float)).all())
self.assertTrue(np.isnan(output.metas[4, 1:3].astype(float)).all())
self.assertFalse(np.isnan(output.metas[1:4, 1:3].astype(float)).any())
self.assertFalse(np.isnan(output.metas[:, 1:3].astype(float)).any())
self.assertTrue(np.isnan(output.metas[0, 3:4].astype(float)).all())
self.assertTrue(np.isnan(output.metas[4, 3:5].astype(float)).all())
self.assertFalse(np.isnan(output.metas[1:4, 3:5].astype(float)).any())

with data.unlocked(data.Y):
data.Y[:] = np.nan
Expand Down

0 comments on commit 38c7b96

Please sign in to comment.