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


Python _sklearn.mean_squared_error函数代码示例

本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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