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


Python SimpleClassificationPipeline.pre_transform方法代码示例

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


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

示例1: test_weighting_effect

# 需要导入模块: from autosklearn.pipeline.classification import SimpleClassificationPipeline [as 别名]
# 或者: from autosklearn.pipeline.classification.SimpleClassificationPipeline import pre_transform [as 别名]
    def test_weighting_effect(self):
        data = sklearn.datasets.make_classification(
            n_samples=1000, n_features=20, n_redundant=5, n_informative=5,
            n_repeated=2, n_clusters_per_class=2, weights=[0.8, 0.2],
            random_state=1)

        for name, clf, acc_no_weighting, acc_weighting in \
                [('adaboost', AdaboostClassifier, 0.709, 0.658),
                 ('decision_tree', DecisionTree, 0.683, 0.701),
                 ('extra_trees', ExtraTreesClassifier, 0.812, 0.8),
                 ('gradient_boosting', GradientBoostingClassifier,
                    0.800, 0.760),
                 ('random_forest', RandomForest, 0.846, 0.792),
                 ('libsvm_svc', LibSVM_SVC, 0.571, 0.658),
                 ('liblinear_svc', LibLinear_SVC, 0.685, 0.699),
                 ('sgd', SGD, 0.65384615384615385, 0.38795986622073581)]:
            for strategy, acc in [('none', acc_no_weighting),
                                  ('weighting', acc_weighting)]:
                # Fit
                data_ = copy.copy(data)
                X_train = data_[0][:700]
                Y_train = data_[1][:700]
                X_test = data_[0][700:]
                Y_test = data_[1][700:]

                cs = SimpleClassificationPipeline.\
                    get_hyperparameter_search_space(
                        include={'classifier': [name]})
                default = cs.get_default_configuration()
                default._values['balancing:strategy'] = strategy
                classifier = SimpleClassificationPipeline(default, random_state=1)
                predictor = classifier.fit(X_train, Y_train)
                predictions = predictor.predict(X_test)
                self.assertAlmostEqual(acc,
                    sklearn.metrics.f1_score(predictions, Y_test),
                    places=3)

                # pre_transform and fit_estimator
                data_ = copy.copy(data)
                X_train = data_[0][:700]
                Y_train = data_[1][:700]
                X_test = data_[0][700:]
                Y_test = data_[1][700:]

                cs = SimpleClassificationPipeline.get_hyperparameter_search_space(
                    include={'classifier': [name]})
                default = cs.get_default_configuration()
                default._values['balancing:strategy'] = strategy
                classifier = SimpleClassificationPipeline(default, random_state=1)
                Xt, fit_params = classifier.pre_transform(X_train, Y_train)
                classifier.fit_estimator(Xt, Y_train, **fit_params)
                predictions = classifier.predict(X_test)
                self.assertAlmostEqual(acc,
                                       sklearn.metrics.f1_score(
                                           predictions, Y_test),
                                       places=3)

        for name, pre, acc_no_weighting, acc_weighting in \
                [('extra_trees_preproc_for_classification',
                    ExtraTreesPreprocessorClassification, 0.7142857142857143,
                    0.72180451127819545),
                 ('liblinear_svc_preprocessor', LibLinear_Preprocessor,
                    0.5934065934065933, 0.71111111111111114)]:
            for strategy, acc in [('none', acc_no_weighting),
                                  ('weighting', acc_weighting)]:
                data_ = copy.copy(data)
                X_train = data_[0][:700]
                Y_train = data_[1][:700]
                X_test = data_[0][700:]
                Y_test = data_[1][700:]

                cs = SimpleClassificationPipeline.get_hyperparameter_search_space(
                    include={'classifier': ['sgd'], 'preprocessor': [name]})
                default = cs.get_default_configuration()
                default._values['balancing:strategy'] = strategy
                classifier = SimpleClassificationPipeline(default, random_state=1)
                predictor = classifier.fit(X_train, Y_train)
                predictions = predictor.predict(X_test)
                self.assertAlmostEqual(acc,
                                       sklearn.metrics.f1_score(
                                           predictions, Y_test),
                                       places=3)

                # pre_transform and fit_estimator
                data_ = copy.copy(data)
                X_train = data_[0][:700]
                Y_train = data_[1][:700]
                X_test = data_[0][700:]
                Y_test = data_[1][700:]

                cs = SimpleClassificationPipeline.get_hyperparameter_search_space(
                    include={'classifier': ['sgd'], 'preprocessor': [name]})
                default = cs.get_default_configuration()
                default._values['balancing:strategy'] = strategy
                classifier = SimpleClassificationPipeline(default, random_state=1)
                Xt, fit_params = classifier.pre_transform(X_train, Y_train)
                classifier.fit_estimator(Xt, Y_train, **fit_params)
                predictions = classifier.predict(X_test)
                self.assertAlmostEqual(acc,
                                       sklearn.metrics.f1_score(
#.........这里部分代码省略.........
开发者ID:Ayaro,项目名称:auto-sklearn,代码行数:103,代码来源:test_balancing.py


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