def test_symbol_labels():
    # Test with non-integer class labels.
    clf = GradientBoostingClassifier(n_estimators=100, random_state=1)

    symbol_y = tosequence(map(str, y))

    clf.fit(X, symbol_y)
    assert_array_equal(clf.predict(T), tosequence(map(str, true_result)))
    assert_equal(100, len(clf.estimators_))
示例#2
0
def test_symbol_labels():
    # Test with non-integer class labels.
    clf = GradientBoostingClassifier(n_estimators=100, random_state=1)

    symbol_y = tosequence(map(str, y))

    clf.fit(X, symbol_y)
    assert_array_equal(clf.predict(T), tosequence(map(str, true_result)))
    assert_equal(100, len(clf.estimators_))
示例#3
0
    def __init__(self, meta_estimator, base_estimators, probabilities=True):
        self.meta_estimator = meta_estimator
        self.probabilities = probabilities

        self.named_estimators = dict(base_estimators)
        names, estimators = zip(*base_estimators)
        if len(self.named_estimators) != len(base_estimators):
            raise ValueError("Names provided are not unique: %s" % (names, ))

        # shallow copy of steps
        self.base_estimators = tosequence(zip(names, estimators))

        self._extra_params = ["meta_estimator", "probabilities"]

        for t in estimators:
            if not hasattr(t, "fit") or not (hasattr(t, "predict")
                                             or hasattr(t, "predict_proba")):
                raise TypeError("All base estimators should implement "
                                "fit and predict/predict_proba"
                                " '%s' (type %s) doesn't)" % (t, type(t)))

        if not hasattr(meta_estimator, "fit"):
            raise TypeError("meta estimator should implement fit "
                            "'%s' (type %s) doesn't)" %
                            (meta_estimator, type(meta_estimator)))
示例#4
0
    def __init__(self, steps):
        # Default values
        super().__init__()
        self.steps = tosequence(steps)
        self.active = False

        self.__configure()
示例#5
0
    def __init__(self, steps, feature_names=None, target_feature=None,
                 exclude_from_ppc=None, exclude_from_fit=None):
        super(H2OPipeline, self).__init__(target_feature=target_feature,
                                          min_version=self._min_version,
                                          max_version=self._max_version)

        # assign to attribute
        self.feature_names = feature_names

        # if we have any to exclude...
        self.exclude_from_ppc = validate_x(exclude_from_ppc)
        self.exclude_from_fit = validate_x(exclude_from_fit)

        names, estimators = zip(*steps)
        if len(dict(steps)) != len(steps):
            raise ValueError("Provided step names are not unique: %s"
                             % (names,))

        # shallow copy of steps
        self.steps = tosequence(steps)
        transforms = estimators[:-1]
        estimator = estimators[-1]

        for t in transforms:
            if not isinstance(t, BaseH2OTransformer):
                raise TypeError("All intermediate steps of the chain should "
                                "be instances of BaseH2OTransformer"
                                " '%s' (type %s) isn't)" % (t, type(t)))

        if not isinstance(estimator, (H2OEstimator, BaseH2OTransformer)):
            raise TypeError("Last step of chain should be an H2OEstimator or BaseH2OTransformer, "
                            "not of type %s" % type(estimator))
示例#6
0
 def __init__(self,
              estimator_list,
              cv=3,
              n_jobs=1,
              pre_dispatch='2*n_jobs',
              verbose=0):
     self.estimator_list = tosequence(estimator_list)
     self.cv = cv
     self.n_jobs = n_jobs
     self.pre_dispatch = pre_dispatch
     self.verbose = verbose
示例#7
0
    def _check_steps(self, steps):
        names, transforms = zip(*steps)
        if len(dict(steps)) != len(steps):
            raise ValueError("Provided step names are not unique: {}"
                             "".format(names))

        # shallow copy of steps
        self.steps = tosequence(steps)

        for t in transforms:
            if (not (hasattr(t, "fit") or hasattr(t, "fit_transform")) or not
                    hasattr(t, "transform")):
                raise TypeError("All steps of the chain should "
                                "be transforms and implement fit and transform"
                                " '%s' (type %s) doesn't)" % (t, type(t)))
示例#8
0
def _add_timed_sequence(steps, sink):
    """For each step in steps, decorate its relevant methods."""
    seq = tosequence(steps)
    method_names = ('fit', 'transform', 'fit_transform', 'predict',
                    'predict_proba')
    for name, step in seq:
        for method_name in method_names:
            old_func = getattr(step, method_name, None)
            # pylint: disable=protected-access
            if not old_func or hasattr(old_func, '_has_timing'):
                continue

            new_func = timing_decorator(step, name, method_name, sink)
            setattr(
                step,
                new_func.__name__,
                types.MethodType(new_func, step),
            )
    return seq
示例#9
0
    def __init__(self, steps):
        names, estimators = zip(*steps)
        if len(dict(steps)) != len(steps):
            raise ValueError("Provided step names are not unique: %s" %
                             (names, ))

        # shallow copy of steps
        self.steps = tosequence(steps)
        transforms = estimators[:-1]
        estimator = estimators[-1]

        for t in transforms:
            _validate_step_methods(t)
            _validate_step_behaviour(t)
            _validate_step_class(t)

        if not hasattr(estimator, "fit"):
            raise TypeError("Last step of chain should implement fit "
                            "'%s' (type %s) doesn't)" %
                            (estimator, type(estimator)))
示例#10
0
    def __init__(self, steps):
        names, estimators = zip(*steps)
        if len(dict(steps)) != len(steps):
            raise ValueError("Provided step names are not unique: %s" % (names,))

        # shallow copy of steps
        self.steps = tosequence(steps)
        estimator = estimators[-1]

        for e in estimators:
            if (not (hasattr(e, "fit") or hasattr(e, "fit_transform")) or not
                    hasattr(e, "transform")):
                raise TypeError("All steps of the chain should "
                                "be transforms and implement fit and transform"
                                " '%s' (type %s) doesn't)" % (e, type(e)))

        if not hasattr(estimator, "fit"):
            raise TypeError("Last step of chain should implement fit "
                            "'%s' (type %s) doesn't)"
                            % (estimator, type(estimator)))
示例#11
0
    def __init__(self, steps):
        names, estimators = zip(*steps)
        if len(dict(steps)) != len(steps):
            raise ValueError("Provided step names are not unique: %s" % (names,))

        # shallow copy of steps
        self.steps = tosequence(steps)
        estimator = estimators[-1]

        for e in estimators:
            if (not (hasattr(e, "fit") or hasattr(e, "fit_transform")) or not
                    hasattr(e, "transform")):
                raise TypeError("All steps of the chain should "
                                "be transforms and implement fit and transform"
                                " '%s' (type %s) doesn't)" % (e, type(e)))

        if not hasattr(estimator, "fit"):
            raise TypeError("Last step of chain should implement fit "
                            "'%s' (type %s) doesn't)"
                            % (estimator, type(estimator)))
示例#12
0
    def __init__(self, steps):
        names, estimators = zip(*steps)
        if len(dict(steps)) != len(steps):
            raise ValueError("Provided step names are not unique: %s" %
                             (names, ))

        # shallow copy of steps
        self.steps = tosequence(steps)
        transforms = estimators[:-1]
        estimator = estimators[-1]

        for t in transforms:
            _validate_step_methods(t)
            _validate_step_behaviour(t)
            _validate_step_class(t)

        if not hasattr(estimator, "fit"):
            raise TypeError("Last step of chain should implement fit "
                            "'%s' (type %s) doesn't)" %
                            (estimator, type(estimator)))
示例#13
0
文件: pipeline.py 项目: jcrudy/higgs
    def __init__(self, steps):
        self.named_steps = dict(steps)
        names, estimators = zip(*steps)
        if len(self.named_steps) != len(steps):
            raise ValueError("Names provided are not unique: %s" % names)
 
        # shallow copy of steps
        self.steps = tosequence(zip(names, estimators))
        transforms = estimators[:-1]
        estimator = estimators[-1]
 
        for t in transforms:
            if (not (hasattr(t, "fit") or hasattr(t, "fit_transform")) or not
                    hasattr(t, "transform")):
                raise TypeError("All intermediate steps a the chain should "
                                "be transforms and implement fit and transform"
                                "'%s' (type %s) doesn't)" % (t, type(t)))
 
        if not hasattr(estimator, "fit"):
            raise TypeError("Last step of chain should implement fit "
                            "'%s' (type %s) doesn't)"
                            % (estimator, type(estimator)))
示例#14
0
    def __init__(self,
                 steps,
                 feature_names=None,
                 target_feature=None,
                 exclude_from_ppc=None,
                 exclude_from_fit=None):
        super(H2OPipeline, self).__init__(target_feature=target_feature,
                                          min_version=self._min_version,
                                          max_version=self._max_version)

        # assign to attribute
        self.feature_names = feature_names

        # if we have any to exclude...
        self.exclude_from_ppc = validate_x(exclude_from_ppc)
        self.exclude_from_fit = validate_x(exclude_from_fit)

        names, estimators = zip(*steps)
        if len(dict(steps)) != len(steps):
            raise ValueError("Provided step names are not unique: %s" %
                             (names, ))

        # shallow copy of steps
        self.steps = tosequence(steps)
        transforms = estimators[:-1]
        estimator = estimators[-1]

        for t in transforms:
            if not isinstance(t, BaseH2OTransformer):
                raise TypeError("All intermediate steps of the chain should "
                                "be instances of BaseH2OTransformer"
                                " '%s' (type %s) isn't)" % (t, type(t)))

        if not isinstance(estimator, (H2OEstimator, BaseH2OTransformer)):
            raise TypeError(
                "Last step of chain should be an H2OEstimator or BaseH2OTransformer, "
                "not of type %s" % type(estimator))
示例#15
0
 def __init__(self, steps, memory=None):
     # shallow copy of steps
     self.steps = tosequence(steps)
     self._validate_steps()
     self.memory = memory
示例#16
0
 def __init__(self, steps, memory=None):
     # shallow copy of steps
     self.steps = tosequence(steps)
     self._validate_steps()
     self.memory = memory
示例#17
0
def _tosequence(X):
    """Turn X into a sequence or ndarray, avoiding a copy if possible."""
    if isinstance(X, Mapping):  # single sample
        return [X]
    else:
        return tosequence(X)
示例#18
0
def _tosequence(X):
    """Turn X into a sequence or ndarray, avoiding a copy if possible."""
    if isinstance(X, Mapping):  # single sample
        return [X]
    else:
        return tosequence(X)
示例#19
0
    if isinstance(X, type([])):
        if isinstance(X[0], type([])):
            r, c = len(X), len(X[0])
        else:
            c = len(X)
    elif isinstance(X, type(np.array([0]))):
        if X.ndim > 1:
            r, c = X.shape
        else:
            r, c = 1, X.size

    return r, c


if __name__ == '__main__':
    aux1 = {'key1': 1.0, 'key2': 2.3, 'key3': 3.5, 'key4': 4.8}
    aux = [('key1', 1.0), ('key2', 2.3), ('key3', 3.5), ('key4', 4.8)]
    #list1 = dict_to_list(aux1)
    #list = tuple_list_to_list(aux)
    #list_to_sequence = tosequence(aux)
    #print(list)
    #print(list1)

    #tuple_list = dict_to_tuple_list(aux1)

    test = tosequence(aux)
    print(test)
    print(test[-1][-1])
    time.sleep(20)

    #print(tuple_list)