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 File: tenant_pays_landlord.py    From JusticeAI with 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 #2
Source File: hous_price.py    From deep_learning with 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 #3
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #4
Source File: test_keras.py    From hyperparameter_hunter with 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() 
Example #5
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #6
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #8
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #9
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #10
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #11
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #13
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #15
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #16
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #18
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #19
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #20
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #21
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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 #23
Source File: scikit_learn_test.py    From DeepLearning_Wavelet-LSTM with 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)