Esempio n. 1
0
 def test_invalid_sample_weights(self):
     """Checks that weights must be 1D array with the same length as the number of samples"""
     X = self.random_state.uniform(0, 100, size=(3, 3))
     wts_len = np.ones(len(X) + 1)
     wts_dim = np.ones((len(X), 2))
     model = StandardFlexibleScaler()
     with self.assertRaises(ValueError):
         model.fit_transform(X, sample_weight=wts_len)
     with self.assertRaises(ValueError):
         model.fit_transform(X, sample_weight=wts_dim)
Esempio n. 2
0
 def test_sample_weights(self):
     """Checks that sample weights of one are equal to the unweighted case and that the nonuniform weights are different from the unweighted case"""
     X = self.random_state.uniform(0, 100, size=(3, 3))
     equal_wts = np.ones(len(X))
     nonequal_wts = self.random_state.uniform(0, 100, size=(len(X),))
     model = StandardFlexibleScaler()
     weighted_model = StandardFlexibleScaler()
     X_unweighted = model.fit_transform(X)
     X_equal_weighted = weighted_model.fit_transform(X, sample_weight=equal_wts)
     self.assertTrue((np.isclose(X_unweighted, X_equal_weighted, atol=1e-12)).all())
     X_nonequal_weighted = weighted_model.fit_transform(
         X, sample_weight=nonequal_wts
     )
     self.assertFalse(
         (np.isclose(X_unweighted, X_nonequal_weighted, atol=1e-12)).all()
     )
Esempio n. 3
0
 def test_fit_transform_pf(self):
     """Checks that in the case of normalization by columns,
     the result is the same as in the case of using the package from sklearn
     """
     X = self.random_state.uniform(0, 100, size=(3, 3))
     model = StandardFlexibleScaler(column_wise=True)
     transformed_skcosmo = model.fit_transform(X)
     transformed_sklearn = StandardScaler().fit_transform(X)
     self.assertTrue(
         (np.isclose(transformed_sklearn, transformed_skcosmo, atol=1e-12)).all()
     )
Esempio n. 4
0
 def test_fit_transform_npf(self):
     """Checks that the entire matrix is correctly normalized
     (not column-wise). Compare with the value calculated
     directly from the equation.
     """
     X = self.random_state.uniform(0, 100, size=(3, 3))
     model = StandardFlexibleScaler(column_wise=False)
     X_tr = model.fit_transform(X)
     mean = X.mean(axis=0)
     var = ((X - mean) ** 2).mean(axis=0)
     scale = np.sqrt(var.sum())
     X_ex = (X - mean) / scale
     self.assertTrue((np.isclose(X_ex, X_tr, atol=1e-12)).all())