Python sklearn.ensemble.AdaBoostClassifier() Examples
The following are 30
code examples of sklearn.ensemble.AdaBoostClassifier().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sklearn.ensemble
, or try the search function
.
Example #1
Source File: test_sklearn_adaboost_converter.py From sklearn-onnx with MIT License | 6 votes |
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')", )
Example #2
Source File: test_weight_boosting.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #3
Source File: classifier.py From stock-price-prediction with MIT License | 6 votes |
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'])
Example #4
Source File: test_weight_boosting.py From twitter-stock-recommendation with MIT License | 6 votes |
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)
Example #5
Source File: AdaBoost_Classify.py From Machine-Learning-for-Beginner-by-Python3 with MIT License | 6 votes |
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 # 最终确定组合的函数
Example #6
Source File: AdaBoost_Classify.py From Machine-Learning-for-Beginner-by-Python3 with MIT License | 6 votes |
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) # 主函数
Example #7
Source File: test_weight_boosting.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #8
Source File: test_weight_boosting.py From twitter-stock-recommendation with MIT License | 6 votes |
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)
Example #9
Source File: test_static_selection.py From DESlib with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_different_scorer(): X, y = make_classification(n_samples=100, random_state=42) X_val, y_val = make_classification(n_samples=25, random_state=123) pool = AdaBoostClassifier(n_estimators=10).fit(X, y) performances = [] for clf in pool: preds = clf.predict_proba(X_val) performances.append(log_loss(y_val.ravel(), preds[:, -1])) id_best = np.argsort(performances) ss = StaticSelection(pool_classifiers=pool, scoring='neg_log_loss') ss.fit(X_val, y_val) assert (id_best[:ss.n_classifiers_ensemble_] == ss.clf_indices_).all() # Test if static_selection can select the best classifier according to a # metric that needs to be minimized.
Example #10
Source File: test_weight_boosting.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #11
Source File: classifier.py From libfaceid with MIT License | 6 votes |
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)))
Example #12
Source File: models_classification.py From easyML with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__( self,data_block, predictors=[],cv_folds=10, scoring_metric='accuracy',additional_display_metrics=[]): base_classification.__init__( self, alg=AdaBoostClassifier(), data_block=data_block, predictors=predictors,cv_folds=cv_folds, scoring_metric=scoring_metric, additional_display_metrics=additional_display_metrics ) self.model_output = pd.Series(self.default_parameters) self.model_output['Feature_Importance'] = "-" #Set parameters to default values: self.set_parameters(set_default=True)
Example #13
Source File: AdaBoost.py From Awesome-Scripts with MIT License | 6 votes |
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)
Example #14
Source File: ada_boosting.py From DataMiningCompetitionFirstPrize with MIT License | 6 votes |
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
Example #15
Source File: ABuMLCreater.py From abu with GNU General Public License v3.0 | 6 votes |
def adaboost_classifier(self, assign=True, base_estimator=DecisionTreeClassifier(), **kwargs): """ 有监督学习分类器,实例化AdaBoostClassifier,默认使用: AdaBoostClassifier(base_estimator=base_estimator, n_estimators=100, random_state=1) 通过**kwargs即关键字参数透传AdaBoostClassifier,即: AdaBoostClassifier(**kwargs) :param base_estimator: 默认使用DecisionTreeClassifier() :param assign: 是否保存实例后的AdaBoostClassifier对象,默认True,self.clf = clf :param kwargs: 有参数情况下初始化: AdaBoostClassifier(**kwargs) 无参数情况下初始化: AdaBoostClassifier(n_estimators=100, random_state=1) :return: 实例化的AdaBoostClassifier对象 """ if kwargs is not None and len(kwargs) > 0: if 'base_estimator' not in kwargs: kwargs['base_estimator'] = base_estimator clf = AdaBoostClassifier(**kwargs) else: clf = AdaBoostClassifier(base_estimator=base_estimator, n_estimators=100, random_state=1) if assign: self.clf = clf return clf
Example #16
Source File: test_sklearn_adaboost_converter.py From sklearn-onnx with MIT License | 6 votes |
def test_ada_boost_classifier_bool(self): model, X_test = fit_classification_model( AdaBoostClassifier(random_state=42), 3, is_bool=True) model_onnx = convert_sklearn( model, "AdaBoost classification", [("input", BooleanTensorType((None, X_test.shape[1])))], target_opset=10, ) self.assertIsNotNone(model_onnx) dump_data_and_model( X_test, model, model_onnx, basename="SklearnAdaBoostClassifierBool", allow_failure="StrictVersion(" "onnxruntime.__version__)" "<= StrictVersion('0.2.1')", )
Example #17
Source File: test_sklearn_adaboost_converter.py From sklearn-onnx with MIT License | 6 votes |
def test_ada_boost_classifier_samme_decision_function(self): model, X_test = fit_classification_model(AdaBoostClassifier( n_estimators=5, algorithm="SAMME", random_state=42, base_estimator=DecisionTreeClassifier( max_depth=6, random_state=42)), 2) options = {id(model): {'raw_scores': True}} model_onnx = convert_sklearn( model, "AdaBoostClSamme", [("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="SklearnAdaBoostClassifierSAMMEDTDecisionFunction", allow_failure="StrictVersion(" "onnxruntime.__version__)" "< StrictVersion('0.5.0')", methods=['predict', 'decision_function_binary'], )
Example #18
Source File: test_sklearn_adaboost_converter.py From sklearn-onnx with MIT License | 6 votes |
def test_ada_boost_classifier_samme(self): model, X_test = fit_classification_model(AdaBoostClassifier( n_estimators=5, algorithm="SAMME", random_state=42, base_estimator=DecisionTreeClassifier( max_depth=6, random_state=42)), 2) model_onnx = convert_sklearn( model, "AdaBoostClSamme", [("input", FloatTensorType((None, X_test.shape[1])))], target_opset=10, ) self.assertIsNotNone(model_onnx) dump_data_and_model( X_test, model, model_onnx, basename="SklearnAdaBoostClassifierSAMMEDT", allow_failure="StrictVersion(" "onnxruntime.__version__)" "< StrictVersion('0.5.0')", )
Example #19
Source File: test_sklearn_adaboost_converter.py From sklearn-onnx with MIT License | 6 votes |
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')", )
Example #20
Source File: test_sklearn_adaboost_converter.py From sklearn-onnx with MIT License | 6 votes |
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'], )
Example #21
Source File: scikitlearn.py From sia-cog with MIT License | 6 votes |
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
Example #22
Source File: SupervisedClassifier.py From CDSS with GNU General Public License v3.0 | 6 votes |
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)
Example #23
Source File: ClassificationAdaBoost.py From AirTicketPredicting with MIT License | 6 votes |
def __init__(self, isTrain, isOutlierRemoval): super(ClassificationAdaBoost, self).__init__(isTrain, isOutlierRemoval) # data preprocessing self.dataPreprocessing() self.dt_stump = DecisionTreeClassifier(max_depth=10) self.ada = AdaBoostClassifier( base_estimator=self.dt_stump, learning_rate=1, n_estimators=7, algorithm="SAMME.R") # self.dt_stump = DecisionTreeClassifier(max_depth=14) # self.ada = AdaBoostClassifier( # base_estimator=self.dt_stump, # learning_rate=1, # n_estimators=50, # algorithm="SAMME")
Example #24
Source File: ml_gaussiannb.py From resilient-community-apps with MIT License | 5 votes |
def __init__(self, imbalance_upsampling=None, class_weight=None, method=None, random_state=1, log=None): """ Construtor :param imbalance_upsampling: Use upsampling to compensate imbalanced dataset :param class_weight: Use class_weight to compensate imbalanced dataset :param method: [Optional] Ensemble method :param random_state: Random state :param log: Log """ MlModelCommon.__init__(self, imbalance_upsampling=imbalance_upsampling, class_weight=class_weight, method=method, log=log) # # GaussianNB does not support class_weight # if method == "Bagging": model = GaussianNB() self.ensemble_method = BaggingClassifier(base_estimator=model, n_estimators=100, random_state=random_state) elif method == "Adaptive Boosting": model = GaussianNB() self.ensemble_method = AdaBoostClassifier(base_estimator=model, n_estimators=100, random_state=random_state) else: self.ensemble_method = None GaussianNB.__init__(self)
Example #25
Source File: test_ensemble.py From pandas-ml with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_objectmapper(self): df = pdml.ModelFrame([]) self.assertIs(df.ensemble.AdaBoostClassifier, ensemble.AdaBoostClassifier) self.assertIs(df.ensemble.AdaBoostRegressor, ensemble.AdaBoostRegressor) self.assertIs(df.ensemble.BaggingClassifier, ensemble.BaggingClassifier) self.assertIs(df.ensemble.BaggingRegressor, ensemble.BaggingRegressor) self.assertIs(df.ensemble.ExtraTreesClassifier, ensemble.ExtraTreesClassifier) self.assertIs(df.ensemble.ExtraTreesRegressor, ensemble.ExtraTreesRegressor) self.assertIs(df.ensemble.GradientBoostingClassifier, ensemble.GradientBoostingClassifier) self.assertIs(df.ensemble.GradientBoostingRegressor, ensemble.GradientBoostingRegressor) self.assertIs(df.ensemble.IsolationForest, ensemble.IsolationForest) self.assertIs(df.ensemble.RandomForestClassifier, ensemble.RandomForestClassifier) self.assertIs(df.ensemble.RandomTreesEmbedding, ensemble.RandomTreesEmbedding) self.assertIs(df.ensemble.RandomForestRegressor, ensemble.RandomForestRegressor) self.assertIs(df.ensemble.VotingClassifier, ensemble.VotingClassifier)
Example #26
Source File: test_weight_boosting.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_base_estimator(): # Test different base estimators. from sklearn.ensemble import RandomForestClassifier from sklearn.svm import SVC # XXX doesn't work with y_class because RF doesn't support classes_ # Shouldn't AdaBoost run a LabelBinarizer? clf = AdaBoostClassifier(RandomForestClassifier()) clf.fit(X, y_regr) clf = AdaBoostClassifier(SVC(), algorithm="SAMME") clf.fit(X, y_class) from sklearn.ensemble import RandomForestRegressor from sklearn.svm import SVR clf = AdaBoostRegressor(RandomForestRegressor(), random_state=0) clf.fit(X, y_regr) clf = AdaBoostRegressor(SVR(), random_state=0) clf.fit(X, y_regr) # Check that an empty discrete ensemble fails in fit, not predict. X_fail = [[1, 1], [1, 1], [1, 1], [1, 1]] y_fail = ["foo", "bar", 1, 2] clf = AdaBoostClassifier(SVC(), algorithm="SAMME") assert_raises_regexp(ValueError, "worse than random", clf.fit, X_fail, y_fail)
Example #27
Source File: ABuMLCreater.py From abu with GNU General Public License v3.0 | 5 votes |
def adaboost_classifier_best(self, x, y, param_grid=None, assign=True, n_jobs=-1, show=True): """ 寻找AdaBoostClassifier构造器的最优参数 上层AbuML中adaboost_classifier_best函数,直接使用AbuML中的x,y数据调用 eg: adaboost_classifier_best无param_grid参数调用: from abupy import AbuML, ml ttn_abu = AbuML.create_test_more_fiter() ttn_abu.adaboost_classifier_best() adaboost_classifier_best有param_grid参数调用: param_grid = {'learning_rate': np.arange(0.2, 1.2, 0.2), 'n_estimators': np.arange(10, 100, 10)} ttn_abu.adaboost_classifier_best(param_grid=param_grid, n_jobs=-1) out: AdaBoostClassifier(learning_rate=0.6, n_estimators=70) :param x: 训练集x矩阵,numpy矩阵 :param y: 训练集y序列,numpy序列 :param param_grid: 最优字典关键字参数, eg:param_grid = {'learning_rate': np.arange(0.2, 1.2, 0.2), 'n_estimators': np.arange(10, 100, 10)} :param assign: 是否保存实例化后最优参数的学习器对象,默认True :param n_jobs: 并行执行的进程任务数量,默认-1, 开启与cpu相同数量的进程数 :param show: 是否可视化最优参数搜索结果 :return: 通过最优参数构造的AdaBoostClassifier对象 """ return self._estimators_prarms_best(self.adaboost_classifier, x, y, param_grid, assign, n_jobs, show)
Example #28
Source File: ml_knn.py From resilient-community-apps with MIT License | 5 votes |
def __init__(self, imbalance_upsampling=None, class_weight=None, random_state=1, n_neighbors=5, method=None, log=None): """ :param imbalance_upsampling: Use upsampling to compensate imbalance :param class_weight: Use class_weight to compensate imbalance :param random_state: Random state :param n_neighbors: Number of neighbor samples to use :param method: Ensemble method :param log: Log """ MlModelCommon.__init__(self, imbalance_upsampling=imbalance_upsampling, class_weight=class_weight, method=method, log=log) # # class_weight is not supported for KNN. # if method == "Bagging": model = KNeighborsClassifier(n_neighbors=n_neighbors, metric="minkowski") self.ensemble_method = BaggingClassifier(base_estimator=model, n_estimators=10, random_state=random_state) elif method == "Adaptive Boosting": model = KNeighborsClassifier(n_neighbors=n_neighbors, metric="minkowski") self.ensemble_method = AdaBoostClassifier(base_estimator=model, n_estimators=10, random_state=random_state) else: self.ensemble_method = None KNeighborsClassifier.__init__(self, n_neighbors=n_neighbors, metric="minkowski")
Example #29
Source File: test_weight_boosting.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_error(): # Test that it gives proper exception on deficient input. assert_raises(ValueError, AdaBoostClassifier(learning_rate=-1).fit, X, y_class) assert_raises(ValueError, AdaBoostClassifier(algorithm="foo").fit, X, y_class) assert_raises(ValueError, AdaBoostClassifier().fit, X, y_class, sample_weight=np.asarray([-1]))
Example #30
Source File: test_weight_boosting.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_sample_weight_missing(): from sklearn.cluster import KMeans clf = AdaBoostClassifier(KMeans(), algorithm="SAMME") assert_raises(ValueError, clf.fit, X, y_regr) clf = AdaBoostRegressor(KMeans()) assert_raises(ValueError, clf.fit, X, y_regr)