當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。