当前位置: 首页>>代码示例>>Python>>正文


Python neural_network.MLPRegressor方法代码示例

本文整理汇总了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 
开发者ID:IBM,项目名称:causallib,代码行数:22,代码来源:test_standardization.py

示例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')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:19,代码来源:test_sklearn_mlp_converter.py

示例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) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:26,代码来源:test_mlp.py

示例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]) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:27,代码来源:test_mlp.py

示例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) 
开发者ID:nyoka-pmml,项目名称:nyoka,代码行数:18,代码来源:testScoreWithAdapaSklearn.py

示例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() 
开发者ID:delira-dev,项目名称:delira,代码行数:19,代码来源:test_abstract_models.py

示例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')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:20,代码来源:test_sklearn_one_vs_rest_classifier_converter.py

示例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')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:19,代码来源:test_sklearn_mlp_converter.py

示例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')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:19,代码来源:test_sklearn_mlp_converter.py

示例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')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:19,代码来源:test_sklearn_mlp_converter.py

示例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')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:20,代码来源:test_sklearn_glm_regressor_converter.py

示例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)) 
开发者ID:microsoft,项目名称:dowhy,代码行数:23,代码来源:dummy_outcome_refuter.py

示例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,
        ) 
开发者ID:atmtools,项目名称:typhon,代码行数:39,代码来源:common.py

示例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) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:16,代码来源:test_mlp.py

示例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) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:9,代码来源:test_mlp.py


注:本文中的sklearn.neural_network.MLPRegressor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。