Exemplo n.º 1
0
def test_isotonic_dtype():
    y = [2, 1, 4, 3, 5]
    weights = np.array([.9, .9, .9, .9, .9], dtype=np.float64)
    reg = IsotonicRegression()

    for dtype in (np.int32, np.int64, np.float32, np.float64):
        for sample_weight in (None, weights.astype(np.float32), weights):
            y_np = np.array(y, dtype=dtype)
            expected_dtype = \
                check_array(y_np, dtype=[np.float64, np.float32],
                            ensure_2d=False).dtype

            res = isotonic_regression(y_np, sample_weight=sample_weight)
            assert res.dtype == expected_dtype

            X = np.arange(len(y)).astype(dtype)
            reg.fit(X, y_np, sample_weight=sample_weight)
            res = reg.predict(X)
            assert res.dtype == expected_dtype
Exemplo n.º 2
0
 def predict(self, X):
     X = check_array(X)
     self.key = 1000
     return np.ones(X.shape[0])
Exemplo n.º 3
0
 def transform(self, X):
     X = check_array(X)
     if X.shape[1] != self.X_shape_[1]:
         raise ValueError('Bad number of features')
     return sp.csr_matrix(X)
Exemplo n.º 4
0
 def fit(self, X, y=None):
     self.X_shape_ = check_array(X).shape
     return self
Exemplo n.º 5
0
 def predict(self, X):
     # return 1 if X has more than one element else return 0
     X = check_array(X)
     if X.shape[0] > 1:
         return np.ones(X.shape[0])
     return np.zeros(X.shape[0])
Exemplo n.º 6
0
 def transform(self, X):
     X = check_array(X)
     return X
Exemplo n.º 7
0
 def fit(self, X, y=None):
     X = check_array(X)
     return self
Exemplo n.º 8
0
 def predict(self, X):
     X = check_array(X)
     return np.ones(X.shape[0])
Exemplo n.º 9
0
 def predict(self, X):
     check_is_fitted(self)
     X = check_array(X)
     return np.ones(X.shape[0])