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


Python scikit_learn.KerasClassifier方法代码示例

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


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

示例1: load_pipeline_keras

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def load_pipeline_keras() -> Pipeline:
    """Load a Keras Pipeline from disk."""

    dataset = joblib.load(config.PIPELINE_PATH)

    build_model = lambda: load_model(config.MODEL_PATH)

    classifier = KerasClassifier(build_fn=build_model,
                                 batch_size=config.BATCH_SIZE,
                                 validation_split=10,
                                 epochs=config.EPOCHS,
                                 verbose=2,
                                 callbacks=m.callbacks_list,
                                 # image_size = config.IMAGE_SIZE
                                 )

    classifier.classes_ = joblib.load(config.CLASSES_PATH)
    classifier.model = build_model()

    return Pipeline([
        ('dataset', dataset),
        ('cnn_model', classifier)
    ]) 
开发者ID:trainindata,项目名称:deploying-machine-learning-models,代码行数:25,代码来源:data_management.py

示例2: create_keras_model

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def create_keras_model():
    """
    This function compiles and returns a Keras model.
    Should be passed to KerasClassifier in the Keras scikit-learn API.
    """

    model = Sequential()
    model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 1)))
    model.add(Conv2D(64, (3, 3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(10, activation='softmax'))

    model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])

    return model


# create the classifier 
开发者ID:modAL-python,项目名称:modAL,代码行数:24,代码来源:keras_integration.py

示例3: execute

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def execute():
    train_df, holdout_df = prep_data()

    env = Environment(
        train_dataset=train_df,
        results_path="HyperparameterHunterAssets",
        metrics=["roc_auc_score"],
        target_column=[f"target_{_}" for _ in range(10)],  # 10 classes (one-hot-encoded output)
        holdout_dataset=holdout_df,
        cv_type="StratifiedKFold",
        cv_params=dict(n_splits=3, shuffle=True, random_state=True),
    )

    exp = CVExperiment(KerasClassifier, build_fn_exp, dict(batch_size=64, epochs=10, verbose=1))

    opt = BayesianOptPro(iterations=10, random_state=32)
    opt.forge_experiment(KerasClassifier, build_fn_opt, dict(batch_size=64, epochs=10, verbose=0))
    opt.go() 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:20,代码来源:mnist_example.py

示例4: test_classify_build_fn

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def test_classify_build_fn():
    clf = KerasClassifier(
        build_fn=build_fn_clf, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_classification_works(clf)
    assert_string_classification_works(clf) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:9,代码来源:scikit_learn_test.py

示例5: test_classify_class_build_fn

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def test_classify_class_build_fn():
    class ClassBuildFnClf(object):

        def __call__(self, hidden_dims):
            return build_fn_clf(hidden_dims)

    clf = KerasClassifier(
        build_fn=ClassBuildFnClf(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_classification_works(clf)
    assert_string_classification_works(clf) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:14,代码来源:scikit_learn_test.py

示例6: test_classify_inherit_class_build_fn

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def test_classify_inherit_class_build_fn():
    class InheritClassBuildFnClf(KerasClassifier):

        def __call__(self, hidden_dims):
            return build_fn_clf(hidden_dims)

    clf = InheritClassBuildFnClf(
        build_fn=None, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_classification_works(clf)
    assert_string_classification_works(clf) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:14,代码来源:scikit_learn_test.py

示例7: make_pipeline

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def make_pipeline(**kw):
    # In the case of this Iris dataset, our targets are string labels,
    # and KerasClassifier doesn't like that.  So we transform the
    # targets into a one-hot encoding instead using PipeLineY.
    return PipelineY([
            ('clf', KerasClassifier(build_fn=keras_model, **kw)),
        ],
        y_transformer=LabelBinarizer(),
        predict_use_inverse=False,
        ) 
开发者ID:ottogroup,项目名称:palladium,代码行数:12,代码来源:model.py

示例8: _execute

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def _execute():
    env = Environment(
        train_dataset=prep_data(),
        results_path="HyperparameterHunterAssets",
        metrics=["roc_auc_score"],
        target_column=[f"target_{_}" for _ in range(10)],
        cv_type="StratifiedKFold",
        cv_params=dict(n_splits=10, shuffle=True, random_state=True),
    )

    experiment = CVExperiment(
        model_initializer=KerasClassifier,
        model_init_params=build_fn,
        model_extra_params=dict(batch_size=32, epochs=10, verbose=0, shuffle=True),
    ) 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:17,代码来源:multi_classification_example.py

示例9: execute

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def execute():
    env = Environment(
        train_dataset=get_breast_cancer_data(),
        results_path="HyperparameterHunterAssets",
        target_column="diagnosis",
        metrics=["roc_auc_score"],
        cv_type="StratifiedKFold",
        cv_params=dict(n_splits=5, shuffle=True, random_state=32),
    )

    experiment = CVExperiment(
        model_initializer=KerasClassifier,
        model_init_params=build_fn,
        model_extra_params=dict(
            callbacks=[
                ModelCheckpoint(
                    filepath=os.path.abspath("foo_checkpoint"), save_best_only=True, verbose=1
                ),
                ReduceLROnPlateau(patience=5),
            ],
            batch_size=32,
            epochs=10,
            verbose=0,
            shuffle=True,
        ),
    ) 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:28,代码来源:experiment_example.py

示例10: _execute

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def _execute():
    env = Environment(
        train_dataset=prep_data(),
        results_path="HyperparameterHunterAssets",
        metrics=["roc_auc_score"],
        cv_type="StratifiedKFold",
        cv_params=dict(n_splits=3, shuffle=True, random_state=True),
    )

    experiment = CVExperiment(
        model_initializer=KerasClassifier,
        model_init_params=build_fn,
        model_extra_params=dict(batch_size=32, epochs=3, verbose=0, shuffle=True),
    ) 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:16,代码来源:image_classification_example.py

示例11: _execute

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def _execute():
    #################### Environment ####################
    env = Environment(
        train_dataset=get_breast_cancer_data(target="target"),
        results_path="HyperparameterHunterAssets",
        metrics=["roc_auc_score"],
        cv_type="StratifiedKFold",
        cv_params=dict(n_splits=5, shuffle=True, random_state=32),
    )

    #################### Experimentation ####################
    experiment = CVExperiment(
        model_initializer=KerasClassifier,
        model_init_params=dict(build_fn=_build_fn_experiment),
        model_extra_params=dict(
            callbacks=[ReduceLROnPlateau(patience=5)], batch_size=32, epochs=10, verbose=0
        ),
    )

    #################### Optimization ####################
    optimizer = BayesianOptPro(iterations=10)
    optimizer.forge_experiment(
        model_initializer=KerasClassifier,
        model_init_params=dict(build_fn=_build_fn_optimization),
        model_extra_params=dict(
            callbacks=[ReduceLROnPlateau(patience=Integer(5, 10))],
            batch_size=Categorical([32, 64], transform="onehot"),
            epochs=10,
            verbose=0,
        ),
    )
    optimizer.go() 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:34,代码来源:optimization_example.py

示例12: run_initialization_matching_optimization_0

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def run_initialization_matching_optimization_0(build_fn):
    optimizer = DummyOptPro(iterations=1)
    optimizer.forge_experiment(
        model_initializer=KerasClassifier,
        model_init_params=dict(build_fn=build_fn),
        model_extra_params=dict(epochs=1, batch_size=128, verbose=0),
    )
    optimizer.go()
    return optimizer


#################### `glorot_normal` (`VarianceScaling`) #################### 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:14,代码来源:test_keras.py

示例13: fit

# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasClassifier [as 别名]
def fit(self, X, y):
        if self.multi_class:
            self.n_classes_ = len(set(y))
        else:
            self.n_classes_ = 1

        build_callable = lambda: self.build_function(X.shape[1], self.n_classes_)
        keras_params=copy(self.keras_params)
        keras_params['build_fn']=build_callable

        self.classifier_ = KerasClassifier(**keras_params)
        self.classifier_.fit(X, y) 
开发者ID:scikit-multilearn,项目名称:scikit-multilearn,代码行数:14,代码来源:keras.py


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