• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python _sklearn.mean_squared_error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.contrib.learn.python.learn.estimators._sklearn.mean_squared_error函数的典型用法代码示例。如果您正苦于以下问题:Python mean_squared_error函数的具体用法?Python mean_squared_error怎么用?Python mean_squared_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mean_squared_error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testContinueTraining

  def testContinueTraining(self):
    boston = base.load_boston()
    output_dir = tempfile.mkdtemp()
    est = estimator.SKCompat(
        estimator.Estimator(
            model_fn=linear_model_fn, model_dir=output_dir))
    float64_labels = boston.target.astype(np.float64)
    est.fit(x=boston.data, y=float64_labels, steps=50)
    scores = est.score(
        x=boston.data,
        y=float64_labels,
        metrics={'MSE': metric_ops.streaming_mean_squared_error})
    del est
    # Create another estimator object with the same output dir.
    est2 = estimator.SKCompat(
        estimator.Estimator(
            model_fn=linear_model_fn, model_dir=output_dir))

    # Check we can evaluate and predict.
    scores2 = est2.score(
        x=boston.data,
        y=float64_labels,
        metrics={'MSE': metric_ops.streaming_mean_squared_error})
    self.assertAllClose(scores['MSE'], scores2['MSE'])
    predictions = np.array(list(est2.predict(x=boston.data)))
    other_score = _sklearn.mean_squared_error(predictions, float64_labels)
    self.assertAllClose(scores['MSE'], other_score)

    # Check we can keep training.
    est2.fit(x=boston.data, y=float64_labels, steps=100)
    scores3 = est2.score(
        x=boston.data,
        y=float64_labels,
        metrics={'MSE': metric_ops.streaming_mean_squared_error})
    self.assertLess(scores3['MSE'], scores['MSE'])
开发者ID:Immexxx,项目名称:tensorflow,代码行数:35,代码来源:estimator_test.py


示例2: testContinueTrainingDictionaryInput

  def testContinueTrainingDictionaryInput(self):
    boston = tf.contrib.learn.datasets.load_boston()
    output_dir = tempfile.mkdtemp()
    est = tf.contrib.learn.Estimator(model_fn=linear_model_fn,
                                     model_dir=output_dir)
    boston_input = {'input': boston.data}
    float64_target = {'labels': boston.target.astype(np.float64)}
    est.fit(x=boston_input, y=float64_target, steps=50)
    scores = est.evaluate(
      x=boston_input,
      y=float64_target,
      metrics={'MSE': tf.contrib.metrics.streaming_mean_squared_error})
    del est
    # Create another estimator object with the same output dir.
    est2 = tf.contrib.learn.Estimator(model_fn=linear_model_fn,
                                      model_dir=output_dir)

    # Check we can evaluate and predict.
    scores2 = est2.evaluate(
      x=boston_input,
      y=float64_target,
      metrics={'MSE': tf.contrib.metrics.streaming_mean_squared_error})
    self.assertAllClose(scores2['MSE'],
                        scores['MSE'])
    predictions = np.array(list(est2.predict(x=boston_input)))
    other_score = _sklearn.mean_squared_error(predictions, float64_target['labels'])
    self.assertAllClose(other_score, scores['MSE'])
开发者ID:tensorflow,项目名称:tensorflow,代码行数:27,代码来源:estimator_test.py


示例3: testContinueTraining

  def testContinueTraining(self):
    boston = tf.contrib.learn.datasets.load_boston()
    output_dir = tempfile.mkdtemp()
    est = tf.contrib.learn.Estimator(model_fn=linear_model_fn,
                                     model_dir=output_dir)
    float64_target = boston.target.astype(np.float64)
    est.fit(x=boston.data, y=float64_target, steps=50)
    scores = est.evaluate(
        x=boston.data,
        y=float64_target,
        metrics={'MSE': tf.contrib.metrics.streaming_mean_squared_error})
    del est
    # Create another estimator object with the same output dir.
    est2 = tf.contrib.learn.Estimator(model_fn=linear_model_fn,
                                      model_dir=output_dir)

    # Check we can evaluate and predict.
    scores2 = est2.evaluate(
        x=boston.data,
        y=float64_target,
        metrics={'MSE': tf.contrib.metrics.streaming_mean_squared_error})
    self.assertAllClose(scores2['MSE'],
                        scores['MSE'])
    predictions = est2.predict(x=boston.data)
    other_score = _sklearn.mean_squared_error(predictions, float64_target)
    self.assertAllClose(other_score, scores['MSE'])

    # Check we can keep training.
    est2.fit(x=boston.data, y=float64_target, steps=100)
    scores3 = est2.evaluate(
        x=boston.data,
        y=float64_target,
        metrics={'MSE': tf.contrib.metrics.streaming_mean_squared_error})
    self.assertLess(scores3['MSE'], scores['MSE'])
开发者ID:imzhenyu,项目名称:tensorflow,代码行数:34,代码来源:estimator_test.py


示例4: testCustomMetrics

  def testCustomMetrics(self):
    """Tests custom evaluation metrics."""

    def _input_fn(num_epochs=None):
      # Create 4 rows, one of them (y = x), three of them (y=Not(x))
      labels = constant_op.constant([[1.], [0.], [0.], [0.]])
      features = {
          'x':
              input_lib.limit_epochs(
                  array_ops.ones(
                      shape=[4, 1], dtype=dtypes.float32),
                  num_epochs=num_epochs),
      }
      return features, labels

    def _my_metric_op(predictions, labels):
      return math_ops.reduce_sum(math_ops.multiply(predictions, labels))

    regressor = dnn.DNNRegressor(
        feature_columns=[feature_column.real_valued_column('x')],
        hidden_units=[3, 3],
        config=run_config.RunConfig(tf_random_seed=1))

    regressor.fit(input_fn=_input_fn, steps=5)
    scores = regressor.evaluate(
        input_fn=_input_fn,
        steps=1,
        metrics={
            'my_error': metric_ops.streaming_mean_squared_error,
            ('my_metric', 'scores'): _my_metric_op
        })
    self.assertIn('loss', set(scores.keys()))
    self.assertIn('my_error', set(scores.keys()))
    self.assertIn('my_metric', set(scores.keys()))
    predict_input_fn = functools.partial(_input_fn, num_epochs=1)
    predictions = np.array(list(regressor.predict(input_fn=predict_input_fn)))
    self.assertAlmostEqual(
        _sklearn.mean_squared_error(np.array([1, 0, 0, 0]), predictions),
        scores['my_error'])

    # Tests the case that the 2nd element of the key is not "scores".
    with self.assertRaises(KeyError):
      regressor.evaluate(
          input_fn=_input_fn,
          steps=1,
          metrics={
              ('my_error', 'predictions'):
                  metric_ops.streaming_mean_squared_error
          })

    # Tests the case where the tuple of the key doesn't have 2 elements.
    with self.assertRaises(ValueError):
      regressor.evaluate(
          input_fn=_input_fn,
          steps=1,
          metrics={
              ('bad_length_name', 'scores', 'bad_length'):
                  metric_ops.streaming_mean_squared_error
          })
开发者ID:willdzeng,项目名称:tensorflow,代码行数:59,代码来源:dnn_test.py


示例5: testOneDim

 def testOneDim(self):
   random.seed(42)
   x = np.random.rand(1000)
   y = 2 * x + 3
   regressor = learn.TensorFlowLinearRegressor()
   regressor.fit(x, y)
   score = mean_squared_error(y, regressor.predict(x))
   self.assertLess(score, 1.0, "Failed with score = {0}".format(score))
开发者ID:0ruben,项目名称:tensorflow,代码行数:8,代码来源:base_test.py


示例6: testBoston

 def testBoston(self):
   random.seed(42)
   boston = datasets.load_boston()
   regressor = learn.LinearRegressor(
       feature_columns=learn.infer_real_valued_columns_from_input(boston.data))
   regressor.fit(boston.data, boston.target, max_steps=500)
   score = mean_squared_error(boston.target, regressor.predict(boston.data))
   self.assertLess(score, 150, "Failed with score = {0}".format(score))
开发者ID:MostafaGazar,项目名称:tensorflow,代码行数:8,代码来源:base_test.py


示例7: testBoston

 def testBoston(self):
   random.seed(42)
   boston = datasets.load_boston()
   regressor = learn.TensorFlowLinearRegressor(batch_size=boston.data.shape[0],
                                               steps=500,
                                               learning_rate=0.001)
   regressor.fit(boston.data, boston.target)
   score = mean_squared_error(boston.target, regressor.predict(boston.data))
   self.assertLess(score, 150, "Failed with score = {0}".format(score))
开发者ID:0ruben,项目名称:tensorflow,代码行数:9,代码来源:base_test.py


示例8: testOneDim

 def testOneDim(self):
   random.seed(42)
   x = np.random.rand(1000)
   y = 2 * x + 3
   feature_columns = learn.infer_real_valued_columns_from_input(x)
   regressor = learn.TensorFlowLinearRegressor(feature_columns=feature_columns)
   regressor.fit(x, y)
   score = mean_squared_error(y, regressor.predict(x))
   self.assertLess(score, 1.0, "Failed with score = {0}".format(score))
开发者ID:AntHar,项目名称:tensorflow,代码行数:9,代码来源:base_test.py


示例9: testMultiRegression

 def testMultiRegression(self):
   random.seed(42)
   rng = np.random.RandomState(1)
   x = np.sort(200 * rng.rand(100, 1) - 100, axis=0)
   y = np.array([np.pi * np.sin(x).ravel(), np.pi * np.cos(x).ravel()]).T
   regressor = learn.TensorFlowLinearRegressor(learning_rate=0.01)
   regressor.fit(x, y)
   score = mean_squared_error(regressor.predict(x), y)
   self.assertLess(score, 10, "Failed with score = {0}".format(score))
开发者ID:0ruben,项目名称:tensorflow,代码行数:9,代码来源:multioutput_test.py


示例10: testBostonAll

 def testBostonAll(self):
   boston = tf.contrib.learn.datasets.load_boston()
   est = tf.contrib.learn.Estimator(model_fn=linear_model_fn,
                                    classification=False)
   est.fit(x=boston.data, y=boston.target.astype(np.float32), steps=100)
   scores = est.evaluate(
       x=boston.data,
       y=boston.target.astype(np.float32))
   predictions = est.predict(x=boston.data)
   other_score = mean_squared_error(predictions, boston.target)
   self.assertAllClose(other_score, scores['mean_squared_error'])
开发者ID:3kwa,项目名称:tensorflow,代码行数:11,代码来源:estimator_test.py


示例11: testBostonAll

 def testBostonAll(self):
   boston = tf.contrib.learn.datasets.load_boston()
   est = tf.contrib.learn.Estimator(model_fn=linear_model_fn)
   est.fit(x=boston.data, y=boston.target.astype(np.float32), steps=100)
   scores = est.evaluate(
       x=boston.data,
       y=boston.target.astype(np.float32),
       metrics={'MSE': tf.contrib.metrics.streaming_mean_squared_error})
   predictions = est.predict(x=boston.data)
   other_score = _sklearn.mean_squared_error(predictions, boston.target)
   self.assertAllClose(other_score, scores['MSE'])
开发者ID:EvenStrangest,项目名称:tensorflow,代码行数:11,代码来源:estimator_test.py


示例12: testMultiRegression

 def testMultiRegression(self):
   random.seed(42)
   rng = np.random.RandomState(1)
   x = np.sort(200 * rng.rand(100, 1) - 100, axis=0)
   y = np.array([np.pi * np.sin(x).ravel(), np.pi * np.cos(x).ravel()]).T
   regressor = learn.LinearRegressor(
       feature_columns=learn.infer_real_valued_columns_from_input(x),
       target_dimension=2)
   regressor.fit(x, y, steps=100)
   score = mean_squared_error(regressor.predict(x), y)
   self.assertLess(score, 10, "Failed with score = {0}".format(score))
开发者ID:JamesFysh,项目名称:tensorflow,代码行数:11,代码来源:multioutput_test.py


示例13: testCustomMetrics

  def testCustomMetrics(self):
    """Tests custom evaluation metrics."""

    def _input_fn(num_epochs=None):
      # Create 4 rows, one of them (y = x), three of them (y=Not(x))
      labels = constant_op.constant([[1.], [0.], [0.], [0.]])
      features = {
          'x':
              input_lib.limit_epochs(
                  array_ops.ones(shape=[4, 1], dtype=dtypes.float32),
                  num_epochs=num_epochs),
      }
      return features, labels

    def _my_metric_op(predictions, labels):
      return math_ops.reduce_sum(math_ops.multiply(predictions, labels))

    regressor = debug.DebugRegressor(
        config=run_config.RunConfig(tf_random_seed=1))

    regressor.fit(input_fn=_input_fn, steps=5)
    scores = regressor.evaluate(
        input_fn=_input_fn,
        steps=1,
        metrics={
            'my_error':
                MetricSpec(
                    metric_fn=metric_ops.streaming_mean_squared_error,
                    prediction_key='scores'),
            'my_metric':
                MetricSpec(metric_fn=_my_metric_op, prediction_key='scores')
        })
    self.assertIn('loss', set(scores.keys()))
    self.assertIn('my_error', set(scores.keys()))
    self.assertIn('my_metric', set(scores.keys()))
    predict_input_fn = functools.partial(_input_fn, num_epochs=1)
    predictions = np.array(
        list(regressor.predict_scores(input_fn=predict_input_fn)))
    self.assertAlmostEqual(
        _sklearn.mean_squared_error(np.array([1, 0, 0, 0]), predictions),
        scores['my_error'])

    # Tests the case where the prediction_key is not "scores".
    with self.assertRaisesRegexp(KeyError, 'bad_type'):
      regressor.evaluate(
          input_fn=_input_fn,
          steps=1,
          metrics={
              'bad_name':
                  MetricSpec(
                      metric_fn=metric_ops.streaming_auc,
                      prediction_key='bad_type')
          })
开发者ID:eduardofv,项目名称:tensorflow,代码行数:53,代码来源:debug_test.py


示例14: testBostonAll

 def testBostonAll(self):
     boston = tf.contrib.learn.datasets.load_boston()
     est = tf.contrib.learn.Estimator(model_fn=linear_model_fn)
     float64_target = boston.target.astype(np.float64)
     est.fit(x=boston.data, y=float64_target, steps=100)
     scores = est.evaluate(
         x=boston.data, y=float64_target, metrics={"MSE": tf.contrib.metrics.streaming_mean_squared_error}
     )
     predictions = est.predict(x=boston.data)
     other_score = _sklearn.mean_squared_error(predictions, boston.target)
     self.assertAllClose(other_score, scores["MSE"])
     self.assertTrue("global_step" in scores)
     self.assertEqual(scores["global_step"], 100)
开发者ID:abhishekns,项目名称:tensorflow,代码行数:13,代码来源:estimator_test.py


示例15: testBostonAll

 def testBostonAll(self):
     boston = tf.contrib.learn.datasets.load_boston()
     est = tf.contrib.learn.SKCompat(tf.contrib.learn.Estimator(model_fn=linear_model_fn))
     float64_labels = boston.target.astype(np.float64)
     est.fit(x=boston.data, y=float64_labels, steps=100)
     scores = est.score(
         x=boston.data, y=float64_labels, metrics={"MSE": tf.contrib.metrics.streaming_mean_squared_error}
     )
     predictions = np.array(list(est.predict(x=boston.data)))
     other_score = _sklearn.mean_squared_error(predictions, boston.target)
     self.assertAllClose(scores["MSE"], other_score)
     self.assertTrue("global_step" in scores)
     self.assertEqual(100, scores["global_step"])
开发者ID:yuikns,项目名称:tensorflow,代码行数:13,代码来源:estimator_test.py


示例16: testBostonAll

 def testBostonAll(self):
   boston = base.load_boston()
   est = estimator.SKCompat(estimator.Estimator(model_fn=linear_model_fn))
   float64_labels = boston.target.astype(np.float64)
   est.fit(x=boston.data, y=float64_labels, steps=100)
   scores = est.score(
       x=boston.data,
       y=float64_labels,
       metrics={'MSE': metric_ops.streaming_mean_squared_error})
   predictions = np.array(list(est.predict(x=boston.data)))
   other_score = _sklearn.mean_squared_error(predictions, boston.target)
   self.assertAllClose(scores['MSE'], other_score)
   self.assertTrue('global_step' in scores)
   self.assertEqual(100, scores['global_step'])
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:14,代码来源:estimator_input_test.py


示例17: testCustomMetrics

    def testCustomMetrics(self):
        """Tests custom evaluation metrics."""

        def _input_fn(num_epochs=None):
            # Create 4 rows, one of them (y = x), three of them (y=Not(x))
            labels = tf.constant([[1.], [0.], [0.], [0.]])
            features = {
                'x':
                tf.train.limit_epochs(
                    tf.ones(shape=[4, 1], dtype=tf.float32),
                    num_epochs=num_epochs),
            }
            return features, labels

        def _my_metric_op(predictions, labels):
            return tf.reduce_sum(tf.mul(predictions, labels))

        regressor = tf.contrib.learn.DNNRegressor(
            feature_columns=[tf.contrib.layers.real_valued_column('x')],
            hidden_units=[3, 3],
            config=tf.contrib.learn.RunConfig(tf_random_seed=1))

        regressor.fit(input_fn=_input_fn, steps=5)
        scores = regressor.evaluate(
            input_fn=_input_fn,
            steps=1,
            metrics={
                'my_error': tf.contrib.metrics.streaming_mean_squared_error,
                'my_metric': _my_metric_op
            })
        self.assertIn('loss', set(scores.keys()))
        self.assertIn('my_error', set(scores.keys()))
        self.assertIn('my_metric', set(scores.keys()))
        predict_input_fn = functools.partial(_input_fn, num_epochs=1)
        predictions = np.array(
            list(regressor.predict(input_fn=predict_input_fn)))
        self.assertAlmostEqual(
            _sklearn.mean_squared_error(np.array([1, 0, 0, 0]), predictions),
            scores['my_error'])

        # Tests that when the key is a tuple, an error is raised.
        with self.assertRaises(KeyError):
            regressor.evaluate(
                input_fn=_input_fn,
                steps=1,
                metrics={
                    ('my_error', 'predictions'):
                    tf.contrib.metrics.streaming_mean_squared_error
                })
开发者ID:HKUST-SING,项目名称:tensorflow,代码行数:49,代码来源:dnn_test.py


示例18: testBostonAllDictionaryInput

 def testBostonAllDictionaryInput(self):
   boston = tf.contrib.learn.datasets.load_boston()
   est = tf.contrib.learn.Estimator(model_fn=linear_model_fn)
   boston_input = {'input': boston.data}
   float64_target = {'labels': boston.target.astype(np.float64)}
   est.fit(x=boston_input, y=float64_target, steps=100)
   scores = est.evaluate(
     x=boston_input,
     y=float64_target,
     metrics={'MSE': tf.contrib.metrics.streaming_mean_squared_error})
   predictions = np.array(list(est.predict(x=boston_input)))
   other_score = _sklearn.mean_squared_error(predictions, boston.target)
   self.assertAllClose(other_score, scores['MSE'])
   self.assertTrue('global_step' in scores)
   self.assertEqual(scores['global_step'], 100)
开发者ID:tensorflow,项目名称:tensorflow,代码行数:15,代码来源:estimator_test.py


示例19: testBostonDNN

 def testBostonDNN(self):
   boston = tf.contrib.learn.datasets.load_boston()
   regressor = tf.contrib.learn.TensorFlowDNNRegressor(
       hidden_units=[10, 20, 10], n_classes=0,
       batch_size=boston.data.shape[0], steps=300, learning_rate=0.01)
   regressor.fit(boston.data, boston.target)
   score = mean_squared_error(boston.target, regressor.predict(boston.data))
   self.assertLess(score, 110, "Failed with score = {0}".format(score))
   weights = regressor.weights_
   self.assertEqual(weights[0].shape, (13, 10))
   self.assertEqual(weights[1].shape, (10, 20))
   self.assertEqual(weights[2].shape, (20, 10))
   self.assertEqual(weights[3].shape, (10, 1))
   biases = regressor.bias_
   self.assertEqual(len(biases), 5)
开发者ID:2020zyc,项目名称:tensorflow,代码行数:15,代码来源:nonlinear_test.py


示例20: testBostonDNN

 def testBostonDNN(self):
   boston = tf.contrib.learn.datasets.load_boston()
   feature_columns = [tf.contrib.layers.real_valued_column("", dimension=13)]
   regressor = tf.contrib.learn.DNNRegressor(
       feature_columns=feature_columns, hidden_units=[10, 20, 10],
       config=tf.contrib.learn.RunConfig(tf_random_seed=1))
   regressor.fit(
       boston.data, boston.target, steps=300, batch_size=boston.data.shape[0])
   score = mean_squared_error(boston.target, regressor.predict(boston.data))
   self.assertLess(score, 110, "Failed with score = {0}".format(score))
   weights = regressor.weights_
   self.assertEqual(weights[0].shape, (13, 10))
   self.assertEqual(weights[1].shape, (10, 20))
   self.assertEqual(weights[2].shape, (20, 10))
   self.assertEqual(weights[3].shape, (10, 1))
   biases = regressor.bias_
   self.assertEqual(len(biases), 5)
开发者ID:apollos,项目名称:tensorflow,代码行数:17,代码来源:nonlinear_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dynamic_rnn_estimator._get_state_name函数代码示例发布时间:2022-05-27
下一篇:
Python _sklearn.accuracy_score函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap