def test_kendalltau_1D(self): """ Assert that a 2D matrix is required as input """ with pytest.raises(IndexError, match="tuple index out of range"): X = 0.1 * np.arange(10) kendalltau(X)
def test_kendalltau(self): """ Test results returned match expectations """ X, _ = load_energy(return_dataset=True).to_numpy() expected = np.array([ [1.0, -1.0, -0.2724275, -0.7361443, 0.7385489, 0.0, 0.0, 0.0], [-1.0, 1.0, 0.2724275, 0.7361443, -0.7385489, 0.0, 0.0, 0.0], [ -0.2724275, 0.2724275, 1.0, -0.15192004, 0.19528337, 0.0, 0.0, 0.0 ], [ -0.73614431, 0.73614431, -0.15192004, 1.0, -0.87518995, 0.0, 0.0, 0.0 ], [ 0.73854895, -0.73854895, 0.19528337, -0.87518995, 1.0, 0.0, 0.0, 0.0 ], [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.15430335], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.15430335, 1.0], ]) actual = kendalltau(X) npt.assert_almost_equal(expected, actual)
def test_kendalltau_shape(self): """ Assert that a square correlation matrix is returned """ corr = kendalltau(self.dataset) assert corr.shape[0] == corr.shape[1] for (i, j), val in np.ndenumerate(corr): assert corr[j][i] == pytest.approx(val)
def test_kendalltau_shape(self): """ Assert that a square correlation matrix is returned """ X, _ = load_energy(return_dataset=True).to_numpy() corr = kendalltau(X) assert corr.shape[0] == corr.shape[1] for (i, j), val in np.ndenumerate(corr): assert corr[j][i] == pytest.approx(val)
def test_kendalltau(self): """ Test results returned match expectations """ expected = np.array([ [ 1.0, -0.68, -0.57454545, 0.49858586, 0.07555556, -0.05858586, 0.02387848, 0.11357219, ], [ -0.68, 1.0, 0.58666667, -0.69090909, -0.22262626, -0.17171717, -0.05059964, -0.12397575, ], [ -0.57454545, 0.58666667, 1.0, -0.61050505, 0.18909091, 0.07515152, 0.00341121, -0.0638663, ], [ 0.49858586, -0.69090909, -0.61050505, 1.0, 0.11070707, 0.3030303, 0.03013237, 0.07542581, ], [ 0.07555556, -0.22262626, 0.18909091, 0.11070707, 1.0, 0.4610101, 0.01648752, 0.05982047, ], [ -0.05858586, -0.17171717, 0.07515152, 0.3030303, 0.4610101, 1.0, 0.03695479, -0.02398599, ], [ 0.02387848, -0.05059964, 0.00341121, 0.03013237, 0.01648752, 0.03695479, 1.0, 0.18298883, ], [ 0.11357219, -0.12397575, -0.0638663, 0.07542581, 0.05982047, -0.02398599, 0.18298883, 1.0, ], ]) npt.assert_almost_equal(expected, kendalltau(self.dataset))