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

Python datasets.load_iris函数代码示例

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

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



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

示例1: testIrisES

  def testIrisES(self):
    random.seed(42)

    iris = datasets.load_iris()
    x_train, x_test, y_train, y_test = train_test_split(iris.data,
                                                        iris.target,
                                                        test_size=0.2,
                                                        random_state=42)

    x_train, x_val, y_train, y_val = train_test_split(
        x_train, y_train, test_size=0.2)
    val_monitor = learn.monitors.ValidationMonitor(x_val, y_val,
                                                   early_stopping_rounds=100)

    # classifier without early stopping - overfitting
    classifier1 = learn.TensorFlowDNNClassifier(hidden_units=[10, 20, 10],
                                                n_classes=3,
                                                steps=1000)
    classifier1.fit(x_train, y_train)
    accuracy_score(y_test, classifier1.predict(x_test))

    # classifier with early stopping - improved accuracy on testing set
    classifier2 = learn.TensorFlowDNNClassifier(hidden_units=[10, 20, 10],
                                                n_classes=3,
                                                steps=1000)

    classifier2.fit(x_train, y_train, monitors=[val_monitor])
    accuracy_score(y_test, classifier2.predict(x_test))
开发者ID:Baaaaam,项目名称:tensorflow,代码行数:28,代码来源:test_early_stopping.py


示例2: testIrisMomentum

  def testIrisMomentum(self):
    random.seed(42)

    iris = datasets.load_iris()
    x_train, x_test, y_train, y_test = train_test_split(iris.data,
                                                        iris.target,
                                                        test_size=0.2,
                                                        random_state=42)

    def custom_optimizer(learning_rate):
      return tf.train.MomentumOptimizer(learning_rate, 0.9)

    cont_features = [
        tf.contrib.layers.real_valued_column("", dimension=4)]
    classifier = learn.TensorFlowDNNClassifier(
        feature_columns=cont_features,
        hidden_units=[10, 20, 10],
        n_classes=3,
        steps=400,
        learning_rate=0.01,
        optimizer=custom_optimizer)
    classifier.fit(x_train, y_train)
    score = accuracy_score(y_test, classifier.predict(x_test))

    self.assertGreater(score, 0.65, "Failed with score = {0}".format(score))
开发者ID:JamesFysh,项目名称:tensorflow,代码行数:25,代码来源:estimators_test.py


示例3: testIris

 def testIris(self):
   path = tf.test.get_temp_dir() + '/tmp.saver'
   random.seed(42)
   iris = datasets.load_iris()
   classifier = learn.TensorFlowLinearClassifier(n_classes=3)
   classifier.fit(iris.data, iris.target)
   classifier.save(path)
开发者ID:AngleFork,项目名称:tensorflow,代码行数:7,代码来源:saver_test.py


示例4: testIrisStreaming

  def testIrisStreaming(self):
    iris = datasets.load_iris()

    def iris_data():
      while True:
        for x in iris.data:
          yield x

    def iris_predict_data():
      for x in iris.data:
        yield x

    def iris_target():
      while True:
        for y in iris.target:
          yield y

    classifier = learn.LinearClassifier(
        feature_columns=learn.infer_real_valued_columns_from_input(iris.data),
        n_classes=3)
    classifier.fit(iris_data(), iris_target(), max_steps=500)
    score1 = accuracy_score(iris.target, classifier.predict(iris.data))
    score2 = accuracy_score(iris.target,
                            classifier.predict(iris_predict_data()))
    self.assertGreater(score1, 0.5, "Failed with score = {0}".format(score1))
    self.assertEqual(score2, score1, "Scores from {0} iterator doesn't "
                     "match score {1} from full "
                     "data.".format(score2, score1))
开发者ID:MostafaGazar,项目名称:tensorflow,代码行数:28,代码来源:base_test.py


示例5: testIrisClassWeight

 def testIrisClassWeight(self):
     iris = datasets.load_iris()
     classifier = learn.TensorFlowLinearClassifier(
         n_classes=3, class_weight=[0.1, 0.8, 0.1])
     classifier.fit(iris.data, iris.target)
     score = accuracy_score(iris.target, classifier.predict(iris.data))
     self.assertLess(score, 0.7, "Failed with score = {0}".format(score))
开发者ID:2er0,项目名称:tensorflow,代码行数:7,代码来源:test_base.py


示例6: testIrisStreaming

  def testIrisStreaming(self):
    iris = datasets.load_iris()

    def iris_data():
      while True:
        for x in iris.data:
          yield x

    def iris_predict_data():
      for x in iris.data:
        yield x

    def iris_target():
      while True:
        for y in iris.target:
          yield y

    classifier = learn.TensorFlowLinearClassifier(n_classes=3, steps=100)
    classifier.fit(iris_data(), iris_target())
    score1 = accuracy_score(iris.target, classifier.predict(iris.data))
    score2 = accuracy_score(iris.target,
                            classifier.predict(iris_predict_data()))
    self.assertGreater(score1, 0.5, "Failed with score = {0}".format(score1))
    self.assertEqual(score2, score1, "Scores from {0} iterator doesn't "
                     "match score {1} from full "
                     "data.".format(score2, score1))
开发者ID:0ruben,项目名称:tensorflow,代码行数:26,代码来源:base_test.py


示例7: testDNNDropout0_1

 def testDNNDropout0_1(self):
     # Dropping only a little.
     iris = datasets.load_iris()
     classifier = learn.TensorFlowDNNClassifier(hidden_units=[10, 20, 10], n_classes=3, dropout=0.1)
     classifier.fit(iris.data, iris.target)
     score = accuracy_score(iris.target, classifier.predict(iris.data))
     self.assertGreater(score, 0.9, "Failed with score = {0}".format(score))
开发者ID:kchodorow,项目名称:tensorflow,代码行数:7,代码来源:test_nonlinear.py


示例8: testIrisMomentum

  def testIrisMomentum(self):
    random.seed(42)

    iris = datasets.load_iris()
    x_train, x_test, y_train, y_test = train_test_split(iris.data,
                                                        iris.target,
                                                        test_size=0.2,
                                                        random_state=42)
    # setup exponential decay function
    def exp_decay(global_step):
      return tf.train.exponential_decay(learning_rate=0.1,
                                        global_step=global_step,
                                        decay_steps=100,
                                        decay_rate=0.001)

    def custom_optimizer(learning_rate):
      return tf.train.MomentumOptimizer(learning_rate, 0.9)

    classifier = learn.TensorFlowDNNClassifier(hidden_units=[10, 20, 10],
                                               n_classes=3,
                                               steps=400,
                                               learning_rate=exp_decay,
                                               optimizer=custom_optimizer)
    classifier.fit(x_train, y_train)
    score = accuracy_score(y_test, classifier.predict(x_test))

    self.assertGreater(score, 0.65, "Failed with score = {0}".format(score))
开发者ID:Baaaaam,项目名称:tensorflow,代码行数:27,代码来源:test_estimators.py


示例9: testNoCheckpoints

 def testNoCheckpoints(self):
   path = tf.test.get_temp_dir() + '/tmp/tmp.saver4'
   random.seed(42)
   iris = datasets.load_iris()
   classifier = learn.TensorFlowDNNClassifier(hidden_units=[10, 20, 10],
                                              n_classes=3)
   classifier.fit(iris.data, iris.target)
   classifier.save(path)
开发者ID:AngleFork,项目名称:tensorflow,代码行数:8,代码来源:saver_test.py


示例10: testIris

 def testIris(self):
   iris = datasets.load_iris()
   classifier = learn.TensorFlowLinearClassifier(
       feature_columns=learn.infer_real_valued_columns_from_input(iris.data),
       n_classes=3)
   classifier.fit(iris.data, [x for x in iris.target])
   score = accuracy_score(iris.target, classifier.predict(iris.data))
   self.assertGreater(score, 0.7, "Failed with score = {0}".format(score))
开发者ID:AntHar,项目名称:tensorflow,代码行数:8,代码来源:base_test.py


示例11: testIrisSummaries

 def testIrisSummaries(self):
   iris = datasets.load_iris()
   output_dir = tempfile.mkdtemp() + "learn_tests/"
   classifier = learn.TensorFlowLinearClassifier(n_classes=3,
                                                 model_dir=output_dir)
   classifier.fit(iris.data, iris.target)
   score = accuracy_score(iris.target, classifier.predict(iris.data))
   self.assertGreater(score, 0.5, "Failed with score = {0}".format(score))
开发者ID:0ruben,项目名称:tensorflow,代码行数:8,代码来源:base_test.py


示例12: testIris

 def testIris(self):
   path = tf.test.get_temp_dir() + '/tmp.saver'
   random.seed(42)
   iris = datasets.load_iris()
   cont_features = [
       tf.contrib.layers.real_valued_column('', dimension=4)]
   classifier = learn.LinearClassifier(
       feature_columns=cont_features, n_classes=3, model_dir=path)
   classifier.fit(iris.data, iris.target, steps=200)
开发者ID:apollos,项目名称:tensorflow,代码行数:9,代码来源:saver_test.py


示例13: testNoCheckpoints

 def testNoCheckpoints(self):
   random.seed(42)
   iris = datasets.load_iris()
   cont_features = [
       tf.contrib.layers.real_valued_column('', dimension=4)]
   classifier = learn.DNNClassifier(feature_columns=cont_features,
                                    hidden_units=[10, 20, 10],
                                    n_classes=3)
   classifier.fit(iris.data, iris.target, max_steps=100)
开发者ID:apollos,项目名称:tensorflow,代码行数:9,代码来源:saver_test.py


示例14: testIris_proba

 def testIris_proba(self):
   # If sklearn available.
   if log_loss:
     random.seed(42)
     iris = datasets.load_iris()
     classifier = learn.TensorFlowClassifier(n_classes=3, steps=250)
     classifier.fit(iris.data, iris.target)
     score = log_loss(iris.target, classifier.predict_proba(iris.data))
     self.assertLess(score, 0.8, "Failed with score = {0}".format(score))
开发者ID:0ruben,项目名称:tensorflow,代码行数:9,代码来源:base_test.py


示例15: testIrisSummaries

 def testIrisSummaries(self):
   iris = datasets.load_iris()
   output_dir = tempfile.mkdtemp() + "learn_tests/"
   classifier = learn.LinearClassifier(
       feature_columns=learn.infer_real_valued_columns_from_input(iris.data),
       n_classes=3, model_dir=output_dir)
   classifier.fit(iris.data, iris.target, max_steps=100)
   score = accuracy_score(iris.target, classifier.predict(iris.data))
   self.assertGreater(score, 0.5, "Failed with score = {0}".format(score))
开发者ID:MostafaGazar,项目名称:tensorflow,代码行数:9,代码来源:base_test.py


示例16: testIrisClassWeight

 def testIrisClassWeight(self):
   iris = datasets.load_iris()
   # Note, class_weight are not supported anymore :( Use weight_column.
   with self.assertRaises(ValueError):
     classifier = learn.TensorFlowLinearClassifier(
         n_classes=3, class_weight=[0.1, 0.8, 0.1])
     classifier.fit(iris.data, iris.target)
     score = accuracy_score(iris.target, classifier.predict(iris.data))
     self.assertLess(score, 0.7, "Failed with score = {0}".format(score))
开发者ID:0ruben,项目名称:tensorflow,代码行数:9,代码来源:base_test.py


示例17: testNoCheckpoints

 def testNoCheckpoints(self):
     path = tf.test.get_temp_dir() + '/tmp/tmp.saver4'
     random.seed(42)
     iris = datasets.load_iris()
     classifier = learn.TensorFlowDNNClassifier(hidden_units=[10, 20, 10], n_classes=3)
     classifier.fit(iris.data, iris.target)
     classifier.save(path)
     os.remove(os.path.join(path, 'checkpoint'))
     with self.assertRaises(ValueError):
         learn.TensorFlowEstimator.restore(path)
开发者ID:2er0,项目名称:tensorflow,代码行数:10,代码来源:test_saver.py


示例18: testIrisContinueTraining

 def testIrisContinueTraining(self):
     iris = datasets.load_iris()
     classifier = learn.TensorFlowLinearClassifier(n_classes=3,
         learning_rate=0.01, continue_training=True, steps=250)
     classifier.fit(iris.data, iris.target)
     score1 = accuracy_score(iris.target, classifier.predict(iris.data))
     classifier.fit(iris.data, iris.target)
     score2 = accuracy_score(iris.target, classifier.predict(iris.data))
     self.assertGreater(score2, score1,
                        "Failed with score = {0}".format(score2))
开发者ID:2er0,项目名称:tensorflow,代码行数:10,代码来源:test_base.py


示例19: test_pandas_series

 def test_pandas_series(self):
   if HAS_PANDAS:
     random.seed(42)
     iris = datasets.load_iris()
     data = pd.DataFrame(iris.data)
     labels = pd.Series(iris.target)
     classifier = learn.TensorFlowLinearClassifier(n_classes=3)
     classifier.fit(data, labels)
     score = accuracy_score(labels, classifier.predict(data))
     self.assertGreater(score, 0.5, "Failed with score = {0}".format(score))
开发者ID:0-T-0,项目名称:tensorflow,代码行数:10,代码来源:test_io.py


示例20: testNoCheckpoints

 def testNoCheckpoints(self):
   path = tf.test.get_temp_dir() + '/tmp/tmp.saver4'
   random.seed(42)
   iris = datasets.load_iris()
   cont_features = [
       tf.contrib.layers.real_valued_column('', dimension=4)]
   classifier = learn.TensorFlowDNNClassifier(feature_columns=cont_features,
                                              hidden_units=[10, 20, 10],
                                              n_classes=3)
   classifier.fit(iris.data, iris.target)
   classifier.save(path)
开发者ID:alephman,项目名称:Tensorflow,代码行数:11,代码来源:saver_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python base.load_boston函数代码示例发布时间:2022-05-27
下一篇:
Python learn.infer_real_valued_columns_from_input函数代码示例发布时间: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