本文整理匯總了Python中sklearn.neural_network.MLPRegressor方法的典型用法代碼示例。如果您正苦於以下問題:Python neural_network.MLPRegressor方法的具體用法?Python neural_network.MLPRegressor怎麽用?Python neural_network.MLPRegressor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.neural_network
的用法示例。
在下文中一共展示了neural_network.MLPRegressor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ensure_many_models
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def ensure_many_models(self):
from sklearn.ensemble import GradientBoostingRegressor, RandomForestRegressor
from sklearn.neural_network import MLPRegressor
from sklearn.linear_model import ElasticNet, RANSACRegressor, HuberRegressor, PassiveAggressiveRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.svm import SVR, LinearSVR
import warnings
from sklearn.exceptions import ConvergenceWarning
warnings.filterwarnings('ignore', category=ConvergenceWarning)
for learner in [GradientBoostingRegressor, RandomForestRegressor, MLPRegressor,
ElasticNet, RANSACRegressor, HuberRegressor, PassiveAggressiveRegressor,
KNeighborsRegressor, SVR, LinearSVR]:
learner = learner()
learner_name = str(learner).split("(", maxsplit=1)[0]
with self.subTest("Test fit using {learner}".format(learner=learner_name)):
model = self.estimator.__class__(learner)
model.fit(self.data_lin["X"], self.data_lin["a"], self.data_lin["y"])
self.assertTrue(True) # Fit did not crash
示例2: test_model_mlp_regressor_identity
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_model_mlp_regressor_identity(self):
model, X_test = fit_regression_model(
MLPRegressor(random_state=42, activation="identity"), is_int=True)
model_onnx = convert_sklearn(
model,
"scikit-learn MLPRegressor",
[("input", Int64TensorType([None, X_test.shape[1]]))],
)
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X_test,
model,
model_onnx,
basename="SklearnMLPRegressorIdentityActivation-Dec4",
allow_failure="StrictVersion("
"onnxruntime.__version__)<= StrictVersion('0.2.1')",
)
示例3: test_partial_fit_regression
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_partial_fit_regression():
# Test partial_fit on regression.
# `partial_fit` should yield the same results as 'fit' for regression.
X = Xboston
y = yboston
for momentum in [0, .9]:
mlp = MLPRegressor(solver='sgd', max_iter=100, activation='relu',
random_state=1, learning_rate_init=0.01,
batch_size=X.shape[0], momentum=momentum)
with warnings.catch_warnings(record=True):
# catch convergence warning
mlp.fit(X, y)
pred1 = mlp.predict(X)
mlp = MLPRegressor(solver='sgd', activation='relu',
learning_rate_init=0.01, random_state=1,
batch_size=X.shape[0], momentum=momentum)
for i in range(100):
mlp.partial_fit(X, y)
pred2 = mlp.predict(X)
assert_almost_equal(pred1, pred2, decimal=2)
score = mlp.score(X, y)
assert_greater(score, 0.75)
示例4: test_shuffle
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_shuffle():
# Test that the shuffle parameter affects the training process (it should)
X, y = make_regression(n_samples=50, n_features=5, n_targets=1,
random_state=0)
# The coefficients will be identical if both do or do not shuffle
for shuffle in [True, False]:
mlp1 = MLPRegressor(hidden_layer_sizes=1, max_iter=1, batch_size=1,
random_state=0, shuffle=shuffle)
mlp2 = MLPRegressor(hidden_layer_sizes=1, max_iter=1, batch_size=1,
random_state=0, shuffle=shuffle)
mlp1.fit(X, y)
mlp2.fit(X, y)
assert np.array_equal(mlp1.coefs_[0], mlp2.coefs_[0])
# The coefficients will be slightly different if shuffle=True
mlp1 = MLPRegressor(hidden_layer_sizes=1, max_iter=1, batch_size=1,
random_state=0, shuffle=True)
mlp2 = MLPRegressor(hidden_layer_sizes=1, max_iter=1, batch_size=1,
random_state=0, shuffle=False)
mlp1.fit(X, y)
mlp2.fit(X, y)
assert not np.array_equal(mlp1.coefs_[0], mlp2.coefs_[0])
示例5: test_37_mlp_regressor
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_37_mlp_regressor(self):
print("\ntest 37 (mlp regressor without preprocessing)\n")
X, X_test, y, features, target, test_file = self.data_utility.get_data_for_regression()
model = MLPRegressor()
pipeline_obj = Pipeline([
("model", model)
])
pipeline_obj.fit(X,y)
file_name = 'test37sklearn.pmml'
skl_to_pmml(pipeline_obj, features, target, file_name)
model_name = self.adapa_utility.upload_to_zserver(file_name)
predictions, _ = self.adapa_utility.score_in_zserver(model_name, test_file)
model_pred = pipeline_obj.predict(X_test)
self.assertEqual(self.adapa_utility.compare_predictions(predictions, model_pred), True)
示例6: _setup_sklearn
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def _setup_sklearn(*args):
from delira.models import SklearnEstimator
from sklearn.neural_network import MLPRegressor
class Model(SklearnEstimator):
def __init__(self):
# prefit to enable prediction mode afterwards
module = MLPRegressor()
module.fit(*args)
super().__init__(module)
@staticmethod
def prepare_batch(batch: dict, input_device, output_device):
return batch
return Model()
示例7: test_ovr_regression_float_mlp
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_ovr_regression_float_mlp(self):
model, X = fit_classification_model(
OneVsRestClassifier(MLPRegressor()), 5)
model_onnx = convert_sklearn(
model,
"ovr regression",
[("input", FloatTensorType([None, X.shape[1]]))],
target_opset=TARGET_OPSET
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
basename="SklearnOVRRegressionFloatMLP-Out0",
allow_failure="StrictVersion(onnxruntime.__version__)"
"<= StrictVersion('0.2.1')",
)
示例8: test_model_mlp_regressor_default
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_model_mlp_regressor_default(self):
model, X_test = fit_regression_model(
MLPRegressor(random_state=42))
model_onnx = convert_sklearn(
model,
"scikit-learn MLPRegressor",
[("input", FloatTensorType([None, X_test.shape[1]]))],
)
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X_test,
model,
model_onnx,
basename="SklearnMLPRegressor-Dec4",
allow_failure="StrictVersion("
"onnxruntime.__version__)<= StrictVersion('0.2.1')",
)
示例9: test_model_mlp_regressor_logistic
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_model_mlp_regressor_logistic(self):
model, X_test = fit_regression_model(
MLPRegressor(random_state=42, activation="logistic"))
model_onnx = convert_sklearn(
model,
"scikit-learn MLPRegressor",
[("input", FloatTensorType([None, X_test.shape[1]]))],
)
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X_test,
model,
model_onnx,
basename="SklearnMLPRegressorLogisticActivation-Dec4",
allow_failure="StrictVersion("
"onnxruntime.__version__)<= StrictVersion('0.2.1')",
)
示例10: test_model_mlp_regressor_bool
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_model_mlp_regressor_bool(self):
model, X_test = fit_regression_model(
MLPRegressor(random_state=42), is_bool=True)
model_onnx = convert_sklearn(
model,
"scikit-learn MLPRegressor",
[("input", BooleanTensorType([None, X_test.shape[1]]))],
)
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X_test,
model,
model_onnx,
basename="SklearnMLPRegressorBool",
allow_failure="StrictVersion("
"onnxruntime.__version__)<= StrictVersion('0.2.1')",
)
示例11: test_model_ransac_regressor_mlp
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_model_ransac_regressor_mlp(self):
model, X = fit_regression_model(
linear_model.RANSACRegressor(
base_estimator=MLPRegressor(solver='lbfgs')))
model_onnx = convert_sklearn(
model, "ransac regressor",
[("input", FloatTensorType([None, X.shape[1]]))])
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
verbose=False,
basename="SklearnRANSACRegressorMLP-Dec3",
allow_failure="StrictVersion("
"onnxruntime.__version__)"
"<= StrictVersion('0.2.1')",
)
示例12: _get_regressor_object
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def _get_regressor_object(self, action, **func_args):
"""
Return a sklearn estimator object based on the estimator and corresponding parameters
- 'action': str
The sklearn estimator used.
- 'func_args': variable length keyworded argument
The parameters passed to the sklearn estimator.
"""
if action == "linear_regression":
return LinearRegression(**func_args)
elif action == "knn":
return KNeighborsRegressor(**func_args)
elif action == "svm":
return SVR(**func_args)
elif action == "random_forest":
return RandomForestRegressor(**func_args)
elif action == "neural_network":
return MLPRegressor(**func_args)
else:
raise ValueError("The function: {} is not supported by dowhy at the moment.".format(action))
示例13: _iwp_model
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def _iwp_model(self, processes, cv_folds):
"""Return the default model for the IWP regressor
"""
# Estimators are normally objects that have a fit and predict method
# (e.g. MLPRegressor from sklearn). To make their training easier we
# scale the input data in advance. With Pipeline objects from sklearn
# we can combine such steps easily since they behave like an
# estimator object as well.
estimator = Pipeline([
# SVM or NN work better if we have scaled the data in the first
# place. MinMaxScaler is the simplest one. RobustScaler or
# StandardScaler could be an alternative.
("scaler", RobustScaler(quantile_range=(15, 85))),
# The "real" estimator:
("estimator", MLPRegressor(max_iter=6000, early_stopping=True)),
])
# To optimize the results, we try different hyper parameters by
# using a grid search
hidden_layer_sizes = [
(15, 10, 3),
#(50, 20),
]
hyper_parameter = [
{ # Hyper parameter for lbfgs solver
'estimator__solver': ['lbfgs'],
'estimator__activation': ['tanh'],
'estimator__hidden_layer_sizes': hidden_layer_sizes,
'estimator__random_state': [0, 42, 100, 3452],
'estimator__alpha': [0.1, 0.001, 0.0001],
},
]
return GridSearchCV(
estimator, hyper_parameter, refit=True,
n_jobs=processes, cv=cv_folds, verbose=self.verbose,
)
示例14: test_lbfgs_regression
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_lbfgs_regression():
# Test lbfgs on the boston dataset, a regression problems.
X = Xboston
y = yboston
for activation in ACTIVATION_TYPES:
mlp = MLPRegressor(solver='lbfgs', hidden_layer_sizes=50,
max_iter=150, shuffle=True, random_state=1,
activation=activation)
mlp.fit(X, y)
if activation == 'identity':
assert_greater(mlp.score(X, y), 0.84)
else:
# Non linear models perform much better than linear bottleneck:
assert_greater(mlp.score(X, y), 0.95)
示例15: test_multioutput_regression
# 需要導入模塊: from sklearn import neural_network [as 別名]
# 或者: from sklearn.neural_network import MLPRegressor [as 別名]
def test_multioutput_regression():
# Test that multi-output regression works as expected
X, y = make_regression(n_samples=200, n_targets=5)
mlp = MLPRegressor(solver='lbfgs', hidden_layer_sizes=50, max_iter=200,
random_state=1)
mlp.fit(X, y)
assert_greater(mlp.score(X, y), 0.9)