Python keras.wrappers.scikit_learn.KerasRegressor() Examples

The following are 23 code examples of keras.wrappers.scikit_learn.KerasRegressor(). 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 keras.wrappers.scikit_learn , or try the search function .
Example #1
Source Project: deep_learning   Author: jarvisqi   File: hous_price.py    License: MIT License 6 votes vote down vote up
def main():
    house_df = pd.read_csv('./data/housing.csv', sep='\s+', header=None)
    hose_set = house_df.values
    # print(hose_set)
    x = hose_set[:, 0:13]
    y = hose_set[:, 13]
    # print(y)

    # tbcallback=callbacks.TensorBoard(log_dir='./logs',histogram_freq=0, write_graph=True, write_images=True)
    estimators = []
    estimators.append(('mlp', KerasRegressor(build_fn=build_model, epochs=512, batch_size=32, verbose=1)))
    pipeline = Pipeline(estimators)
    kfold = KFold(n_splits=10, random_state=seed)

    # results = cross_val_score(estimator, x, y, cv=kfold)
    scores = cross_val_score(pipeline, x, y, cv=kfold)
    print('\n')
    print("Results: %.2f (%.2f) MSE" % (scores.mean(), scores.std())) 
Example #2
Source Project: JusticeAI   Author: Cyberjusticelab   File: tenant_pays_landlord.py    License: MIT License 6 votes vote down vote up
def train(self):
        """
            Trains the pipeline. After training the dataset is removed
            from the object to save space.
        """
        Log.write("Size of dataset: %d" % (len(self.dataset)))
        X = np.array([precedent['facts_vector'][self.important_facts_index] for precedent in self.dataset])
        Y = np.array([precedent['outcomes_vector'][self.outcome_index]
                      for precedent in self.dataset])
        self.input_dimensions = len(X[0])
        regressor = KerasRegressor(
            build_fn=self._nn_architecture, epochs=1000, batch_size=1024, verbose=0)
        scaler = StandardScaler()
        self.model = AbstractRegressor._create_pipeline(scaler, regressor)
        self.model.fit(X, Y)
        self.test() 
Example #3
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_build_fn():
    reg = KerasRegressor(
        build_fn=build_fn_reg, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #4
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_class_build_fn():
    class ClassBuildFnReg(object):

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

    reg = KerasRegressor(
        build_fn=ClassBuildFnReg(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #5
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_inherit_class_build_fn():
    class InheritClassBuildFnReg(KerasRegressor):

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

    reg = InheritClassBuildFnReg(
        build_fn=None, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #6
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_build_fn():
    reg = KerasRegressor(
        build_fn=build_fn_reg, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #7
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_class_build_fn():
    class ClassBuildFnReg(object):

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

    reg = KerasRegressor(
        build_fn=ClassBuildFnReg(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #8
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_build_fn():
    reg = KerasRegressor(
        build_fn=build_fn_reg, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #9
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_class_build_fn():
    class ClassBuildFnReg(object):

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

    reg = KerasRegressor(
        build_fn=ClassBuildFnReg(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #10
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_inherit_class_build_fn():
    class InheritClassBuildFnReg(KerasRegressor):

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

    reg = InheritClassBuildFnReg(
        build_fn=None, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #11
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_build_fn():
    reg = KerasRegressor(
        build_fn=build_fn_reg, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #12
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_class_build_fn():
    class ClassBuildFnReg(object):

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

    reg = KerasRegressor(
        build_fn=ClassBuildFnReg(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #13
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_build_fn():
    reg = KerasRegressor(
        build_fn=build_fn_reg, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #14
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_class_build_fn():
    class ClassBuildFnReg(object):

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

    reg = KerasRegressor(
        build_fn=ClassBuildFnReg(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #15
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_inherit_class_build_fn():
    class InheritClassBuildFnReg(KerasRegressor):

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

    reg = InheritClassBuildFnReg(
        build_fn=None, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #16
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_build_fn():
    reg = KerasRegressor(
        build_fn=build_fn_reg, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #17
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_class_build_fn():
    class ClassBuildFnReg(object):

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

    reg = KerasRegressor(
        build_fn=ClassBuildFnReg(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #18
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_build_fn():
    reg = KerasRegressor(
        build_fn=build_fn_reg, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #19
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_class_build_fn():
    class ClassBuildFnReg(object):

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

    reg = KerasRegressor(
        build_fn=ClassBuildFnReg(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #20
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_inherit_class_build_fn():
    class InheritClassBuildFnReg(KerasRegressor):

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

    reg = InheritClassBuildFnReg(
        build_fn=None, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #21
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_build_fn():
    reg = KerasRegressor(
        build_fn=build_fn_reg, hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #22
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: scikit_learn_test.py    License: MIT License 5 votes vote down vote up
def test_regression_class_build_fn():
    class ClassBuildFnReg(object):

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

    reg = KerasRegressor(
        build_fn=ClassBuildFnReg(), hidden_dims=hidden_dims,
        batch_size=batch_size, epochs=epochs)

    assert_regression_works(reg) 
Example #23
Source Project: hyperparameter_hunter   Author: HunterMcGushion   File: test_keras.py    License: MIT License 5 votes vote down vote up
def opt_regressor():
    optimizer = DummyOptPro(iterations=1)
    optimizer.forge_experiment(
        model_initializer=KerasRegressor,
        model_init_params=_build_fn_regressor,
        model_extra_params=dict(
            callbacks=[ReduceLROnPlateau(patience=Integer(5, 10))],
            batch_size=Categorical([32, 64], transform="onehot"),
            epochs=10,
            verbose=0,
        ),
    )
    optimizer.go()