Ejemplo n.º 1
0
    def test_otago_example(self):
        dataset = self.create_otago_dataset()
        transformed = self.get_transformed_otago_data()

        principal_components = pca.pca(dataset, 2)
        assert_that(principal_components, equals_dataset(transformed,
                                                         places=2))
Ejemplo n.º 2
0
    def test_get_weights(self):
        dataset = self.create_otago_dataset()
        reduced = pca.pca(dataset, 2)

        # Note: this is mostly a regression test, these expected values were
        # obtained by running the code.
        assert_that(
            pd.DataFrame(reduced.get_weights()),
            equals_dataframe(
                [[-0.6778734, -0.73517866], [-0.73517866, 0.6778734]],
                places=3))
Ejemplo n.º 3
0
    def test_get_first_component_feature_weights(self):
        dataset = self.create_otago_dataset()
        reduced = pca.pca(dataset, 2)

        # see note in test_get_weights
        impacts = reduced.get_first_component_impacts()
        assert_that(impacts,
                    equals_series({
                        "x": 0.6778734,
                        "y": 0.73517866
                    }, places=3))

        # verify order
        assert_that(impacts.index, contains("y", "x"))
Ejemplo n.º 4
0
 def test_reduced_dataset_has_row_indices(self):
     dataset = DataSet(
         pd.DataFrame([[1, 2], [3, 4], [5, 6]], index=["Cat", "Dog",
                                                       "Rat"]))
     reduced = pca.pca(dataset, 2)
     assert_that(reduced.get_sample_ids(), contains("Cat", "Dog", "Rat"))