当前位置: 首页>>代码示例>>Python>>正文


Python ensemble.AdaBoostClassifier方法代码示例

本文整理汇总了Python中sklearn.ensemble.AdaBoostClassifier方法的典型用法代码示例。如果您正苦于以下问题:Python ensemble.AdaBoostClassifier方法的具体用法?Python ensemble.AdaBoostClassifier怎么用?Python ensemble.AdaBoostClassifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.ensemble的用法示例。


在下文中一共展示了ensemble.AdaBoostClassifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: buildModel

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def buildModel(dataset, method, parameters):
    """
    Build final model for predicting real testing data
    """
    features = dataset.columns[0:-1]

    if method == 'RNN':
        clf = performRNNlass(dataset[features], dataset['UpDown'])
        return clf

    elif method == 'RF':
        clf = RandomForestClassifier(n_estimators=1000, n_jobs=-1)

    elif method == 'KNN':
        clf = neighbors.KNeighborsClassifier()

    elif method == 'SVM':
        c = parameters[0]
        g =  parameters[1]
        clf = SVC(C=c, gamma=g)

    elif method == 'ADA':
        clf = AdaBoostClassifier()

    return clf.fit(dataset[features], dataset['UpDown']) 
开发者ID:chinuy,项目名称:stock-price-prediction,代码行数:27,代码来源:classifier.py

示例2: Train

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def Train(data, modelcount, censhu, yanzhgdata):
    model = AdaBoostClassifier(DecisionTreeClassifier(max_depth=censhu),
                               algorithm="SAMME",
                               n_estimators=modelcount, learning_rate=0.8)

    model.fit(data[:, :-1], data[:, -1])
    # 给出训练数据的预测值
    train_out = model.predict(data[:, :-1])
    # 计算MSE
    train_mse = fmse(data[:, -1], train_out)[0]

    # 给出验证数据的预测值
    add_yan = model.predict(yanzhgdata[:, :-1])
    # 计算f1度量
    add_mse = fmse(yanzhgdata[:, -1], add_yan)[0]
    print(train_mse, add_mse)
    return train_mse, add_mse

# 最终确定组合的函数 
开发者ID:Anfany,项目名称:Machine-Learning-for-Beginner-by-Python3,代码行数:21,代码来源:AdaBoost_Classify.py

示例3: recspre

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def recspre(estrs, predata, datadict, zhe):

    mo, ze = estrs.split('-')
    model = AdaBoostClassifier(DecisionTreeClassifier(max_depth=int(ze)),
                               algorithm="SAMME",
                               n_estimators=int(mo), learning_rate=0.8)

    model.fit(datadict[zhe]['train'][:, :-1], datadict[zhe]['train'][:, -1])

    # 预测
    yucede = model.predict(predata[:, :-1])
    # 计算混淆矩阵

    print(ConfuseMatrix(predata[:, -1], yucede))

    return fmse(predata[:, -1], yucede)

# 主函数 
开发者ID:Anfany,项目名称:Machine-Learning-for-Beginner-by-Python3,代码行数:20,代码来源:AdaBoost_Classify.py

示例4: test_gridsearch

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def test_gridsearch():
    # Check that base trees can be grid-searched.
    # AdaBoost classification
    boost = AdaBoostClassifier(base_estimator=DecisionTreeClassifier())
    parameters = {'n_estimators': (1, 2),
                  'base_estimator__max_depth': (1, 2),
                  'algorithm': ('SAMME', 'SAMME.R')}
    clf = GridSearchCV(boost, parameters)
    clf.fit(iris.data, iris.target)

    # AdaBoost regression
    boost = AdaBoostRegressor(base_estimator=DecisionTreeRegressor(),
                              random_state=0)
    parameters = {'n_estimators': (1, 2),
                  'base_estimator__max_depth': (1, 2)}
    clf = GridSearchCV(boost, parameters)
    clf.fit(boston.data, boston.target) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:19,代码来源:test_weight_boosting.py

示例5: test_importances

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def test_importances():
    # Check variable importances.
    X, y = datasets.make_classification(n_samples=2000,
                                        n_features=10,
                                        n_informative=3,
                                        n_redundant=0,
                                        n_repeated=0,
                                        shuffle=False,
                                        random_state=1)

    for alg in ['SAMME', 'SAMME.R']:
        clf = AdaBoostClassifier(algorithm=alg)

        clf.fit(X, y)
        importances = clf.feature_importances_

        assert_equal(importances.shape[0], 10)
        assert_equal((importances[:3, np.newaxis] >= importances[3:]).all(),
                     True) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:21,代码来源:test_weight_boosting.py

示例6: test_multidimensional_X

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def test_multidimensional_X():
    """
    Check that the AdaBoost estimators can work with n-dimensional
    data matrix
    """

    from sklearn.dummy import DummyClassifier, DummyRegressor

    rng = np.random.RandomState(0)

    X = rng.randn(50, 3, 3)
    yc = rng.choice([0, 1], 50)
    yr = rng.randn(50)

    boost = AdaBoostClassifier(DummyClassifier(strategy='most_frequent'))
    boost.fit(X, yc)
    boost.predict(X)
    boost.predict_proba(X)

    boost = AdaBoostRegressor(DummyRegressor())
    boost.fit(X, yr)
    boost.predict(X) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:24,代码来源:test_weight_boosting.py

示例7: __init__

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def __init__(self, classifier=FaceClassifierModels.DEFAULT):
        self._clf = None
        if classifier == FaceClassifierModels.LINEAR_SVM:
            self._clf = SVC(C=1.0, kernel="linear", probability=True)
        elif classifier == FaceClassifierModels.NAIVE_BAYES:
            self._clf = GaussianNB()
        elif classifier == FaceClassifierModels.RBF_SVM:
            self._clf = SVC(C=1, kernel='rbf', probability=True, gamma=2)
        elif classifier == FaceClassifierModels.NEAREST_NEIGHBORS:
            self._clf = KNeighborsClassifier(1)
        elif classifier == FaceClassifierModels.DECISION_TREE:
            self._clf = DecisionTreeClassifier(max_depth=5)
        elif classifier == FaceClassifierModels.RANDOM_FOREST:
            self._clf = RandomForestClassifier(max_depth=5, n_estimators=10, max_features=1)
        elif classifier == FaceClassifierModels.NEURAL_NET:
            self._clf = MLPClassifier(alpha=1)
        elif classifier == FaceClassifierModels.ADABOOST:
            self._clf = AdaBoostClassifier()
        elif classifier == FaceClassifierModels.QDA:
            self._clf = QuadraticDiscriminantAnalysis()
        print("classifier={}".format(FaceClassifierModels(classifier))) 
开发者ID:richmondu,项目名称:libfaceid,代码行数:23,代码来源:classifier.py

示例8: getModels

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def getModels():
    result = []
    result.append("LinearRegression")
    result.append("BayesianRidge")
    result.append("ARDRegression")
    result.append("ElasticNet")
    result.append("HuberRegressor")
    result.append("Lasso")
    result.append("LassoLars")
    result.append("Rigid")
    result.append("SGDRegressor")
    result.append("SVR")
    result.append("MLPClassifier")
    result.append("KNeighborsClassifier")
    result.append("SVC")
    result.append("GaussianProcessClassifier")
    result.append("DecisionTreeClassifier")
    result.append("RandomForestClassifier")
    result.append("AdaBoostClassifier")
    result.append("GaussianNB")
    result.append("LogisticRegression")
    result.append("QuadraticDiscriminantAnalysis")
    return result 
开发者ID:tech-quantum,项目名称:sia-cog,代码行数:25,代码来源:scikitlearn.py

示例9: main

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def main():
	# prepare data
	trainingSet=[]
	testSet=[]
	accuracy = 0.0
	split = 0.20
	loadDataset('../Dataset/med.data', split, trainingSet, testSet)
	print('Train set: ' + repr(len(trainingSet)))
	print('Test set: ' + repr(len(testSet)))
	trainData = np.array(trainingSet)[:,0:np.array(trainingSet).shape[1] - 1]
	columns = trainData.shape[1] 
	X = np.array(trainData)
	y = np.array(trainingSet)[:,columns]
	clf = AdaBoostClassifier()
	clf.fit(X, y)
	testData = np.array(testSet)[:,0:np.array(trainingSet).shape[1] - 1]
	X_test = np.array(testData)
	y_test = np.array(testSet)[:,columns]
	accuracy = clf.score(X_test,y_test)
	accuracy *= 100
	print("Accuracy %:",accuracy) 
开发者ID:DedSecInside,项目名称:Awesome-Scripts,代码行数:23,代码来源:AdaBoost.py

示例10: learn

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def learn(x, y, test_x):
    # set sample weight
    weight_list = []
    for j in range(len(y)):
        if y[j] == "0":
            weight_list.append(variables.weight_0_ada)
        if y[j] == "1000":
            weight_list.append(variables.weight_1000_ada)
        if y[j] == "1500":
            weight_list.append(variables.weight_1500_ada)
        if y[j] == "2000":
            weight_list.append(variables.weight_2000_ada)

    clf = AdaBoostClassifier(n_estimators=variables.n_estimators_ada, learning_rate=variables.learning_rate_ada).fit(x,
                                                                                                                     y,
                                                                                                                     np.asarray(
                                                                                                                         weight_list))
    prediction_list = clf.predict(test_x)
    prediction_list_prob = clf.predict_proba(test_x)

    return prediction_list, prediction_list_prob 
开发者ID:lzddzh,项目名称:DataMiningCompetitionFirstPrize,代码行数:23,代码来源:ada_boosting.py

示例11: run_sklearn

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def run_sklearn():
  n_trees = 100
  n_folds = 3

  # https://www.analyticsvidhya.com/blog/2015/06/tuning-random-forest-model/
  alg_list = [
      ['rforest',RandomForestClassifier(n_estimators=1000, n_jobs=-1, verbose=1, max_depth=3)],
      ['extree',ExtraTreesClassifier(n_estimators = 1000,max_depth=3,n_jobs=-1)],
      ['adaboost',AdaBoostClassifier(base_estimator=None, n_estimators=600, learning_rate=1.0)],
      ['knn', sklearn.neighbors.KNeighborsClassifier(n_neighbors=5,n_jobs=-1)]
  ]

  start_time = time.time()
  for name,alg in alg_list:
      train = jhkaggle.train_sklearn.TrainSKLearn("1",name,alg,False)
      train.run()
      train = None 
开发者ID:jeffheaton,项目名称:jh-kaggle-util,代码行数:19,代码来源:models.py

示例12: _train_adaboost

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def _train_adaboost(self, X, y):
        # Define hyperparams.
        # http://scikit-learn.org/stable/modules/ensemble.html#adaboost
        self._get_or_set_hyperparam('base_estimator')
        self._get_or_set_hyperparam('n_estimators')
        self._get_or_set_hyperparam('learning_rate')
        self._get_or_set_hyperparam('adaboost_algorithm')
        self._get_or_set_hyperparam('n_jobs')
        self._get_or_set_hyperparam('class_weight')
        self._get_or_set_hyperparam('scoring')

        # Build initial model.
        self._model = AdaBoostClassifier(\
            base_estimator=DecisionTreeClassifier(class_weight='balanced'),
            n_estimators=self._hyperparams['n_estimators'],
            learning_rate=self._hyperparams['learning_rate'],
            algorithm=self._hyperparams['adaboost_algorithm'],
            random_state=self._hyperparams['random_state']
        )

        # Tune hyperparams.
        self._tune_hyperparams(self._hyperparam_search_space, X, y) 
开发者ID:HealthRex,项目名称:CDSS,代码行数:24,代码来源:SupervisedClassifier.py

示例13: test_ada_boost_classifier_samme_r

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def test_ada_boost_classifier_samme_r(self):
        model, X_test = fit_classification_model(AdaBoostClassifier(
            n_estimators=10, algorithm="SAMME.R", random_state=42,
            base_estimator=DecisionTreeClassifier(
                max_depth=2, random_state=42)), 3)
        model_onnx = convert_sklearn(
            model,
            "AdaBoost classification",
            [("input", FloatTensorType((None, X_test.shape[1])))],
            target_opset=10
        )
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X_test,
            model,
            model_onnx,
            basename="SklearnAdaBoostClassifierSAMMER",
            allow_failure="StrictVersion("
            "onnxruntime.__version__)"
            "<= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:23,代码来源:test_sklearn_adaboost_converter.py

示例14: test_ada_boost_classifier_samme_r_decision_function

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def test_ada_boost_classifier_samme_r_decision_function(self):
        model, X_test = fit_classification_model(AdaBoostClassifier(
            n_estimators=10, algorithm="SAMME.R", random_state=42,
            base_estimator=DecisionTreeClassifier(
                max_depth=2, random_state=42)), 4)
        options = {id(model): {'raw_scores': True}}
        model_onnx = convert_sklearn(
            model,
            "AdaBoost classification",
            [("input", FloatTensorType((None, X_test.shape[1])))],
            target_opset=10,
            options=options,
        )
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X_test,
            model,
            model_onnx,
            basename="SklearnAdaBoostClassifierSAMMERDecisionFunction",
            allow_failure="StrictVersion("
            "onnxruntime.__version__)"
            "<= StrictVersion('0.2.1')",
            methods=['predict', 'decision_function'],
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:26,代码来源:test_sklearn_adaboost_converter.py

示例15: test_ada_boost_classifier_samme_r_logreg

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import AdaBoostClassifier [as 别名]
def test_ada_boost_classifier_samme_r_logreg(self):
        model, X_test = fit_classification_model(AdaBoostClassifier(
            n_estimators=5, algorithm="SAMME.R",
            base_estimator=LogisticRegression(
                solver='liblinear')), 4)
        model_onnx = convert_sklearn(
            model,
            "AdaBoost classification",
            [("input", FloatTensorType((None, X_test.shape[1])))],
            target_opset=10
        )
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X_test,
            model,
            model_onnx,
            basename="SklearnAdaBoostClassifierSAMMERLogReg",
            allow_failure="StrictVersion("
            "onnxruntime.__version__)"
            "<= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:23,代码来源:test_sklearn_adaboost_converter.py


注:本文中的sklearn.ensemble.AdaBoostClassifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。