本文整理汇总了Python中keras.wrappers.scikit_learn.KerasRegressor方法的典型用法代码示例。如果您正苦于以下问题:Python scikit_learn.KerasRegressor方法的具体用法?Python scikit_learn.KerasRegressor怎么用?Python scikit_learn.KerasRegressor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.wrappers.scikit_learn
的用法示例。
在下文中一共展示了scikit_learn.KerasRegressor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasRegressor [as 别名]
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()))
示例2: train
# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasRegressor [as 别名]
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()
示例3: test_regression_build_fn
# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasRegressor [as 别名]
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)
示例4: test_regression_class_build_fn
# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasRegressor [as 别名]
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)
示例5: test_regression_inherit_class_build_fn
# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasRegressor [as 别名]
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)
示例6: opt_regressor
# 需要导入模块: from keras.wrappers import scikit_learn [as 别名]
# 或者: from keras.wrappers.scikit_learn import KerasRegressor [as 别名]
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()