示例#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
示例#2
0
 def predict(self, X):
     X = check_array(X)
     self.key = 1000
     return np.ones(X.shape[0])
示例#3
0
# Data

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument('-e',
                        '--estimators',
                        nargs="+",
                        required=True,
                        choices=ESTIMATORS)
    args = vars(parser.parse_args())

    data_train = fetch_20newsgroups_vectorized(subset="train")
    data_test = fetch_20newsgroups_vectorized(subset="test")
    X_train = check_array(data_train.data,
                          dtype=np.float32,
                          accept_sparse="csc")
    X_test = check_array(data_test.data, dtype=np.float32, accept_sparse="csr")
    y_train = data_train.target
    y_test = data_test.target

    print("20 newsgroups")
    print("=============")
    print("X_train.shape = {0}".format(X_train.shape))
    print("X_train.format = {0}".format(X_train.format))
    print("X_train.dtype = {0}".format(X_train.dtype))
    print("X_train density = {0}"
          "".format(X_train.nnz / np.product(X_train.shape)))
    print("y_train {0}".format(y_train.shape))
    print("X_test {0}".format(X_test.shape))
    print("X_test.format = {0}".format(X_test.format))
示例#4
0
 def fit(self, X, y=None):
     self.X_shape_ = check_array(X).shape
     return self
示例#5
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)
示例#6
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])
示例#7
0
 def transform(self, X):
     X = check_array(X)
     return X
示例#8
0
 def fit(self, X, y=None):
     X = check_array(X)
     return self
示例#9
0
 def predict(self, X):
     X = check_array(X)
     return np.ones(X.shape[0])
示例#10
0
 def predict(self, X):
     check_is_fitted(self)
     X = check_array(X)
     return np.ones(X.shape[0])