當前位置: 首頁>>代碼示例>>Python>>正文


Python tensor_forest.RandomForestGraphs方法代碼示例

本文整理匯總了Python中tensorflow.contrib.tensor_forest.python.tensor_forest.RandomForestGraphs方法的典型用法代碼示例。如果您正苦於以下問題:Python tensor_forest.RandomForestGraphs方法的具體用法?Python tensor_forest.RandomForestGraphs怎麽用?Python tensor_forest.RandomForestGraphs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.contrib.tensor_forest.python.tensor_forest的用法示例。


在下文中一共展示了tensor_forest.RandomForestGraphs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testTrainingConstructionRegression

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testTrainingConstructionRegression(self):
    input_data = [[-1., 0.], [-1., 2.],  # node 1
                  [1., 0.], [1., -2.]]  # node 2
    input_labels = [0, 1, 2, 3]

    params = tensor_forest.ForestHParams(
        num_classes=4,
        num_features=2,
        num_trees=10,
        max_nodes=1000,
        split_after_samples=25,
        regression=True).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.training_graph(input_data, input_labels)
    self.assertTrue(isinstance(graph, ops.Operation)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:18,代碼來源:tensor_forest_test.py

示例2: testTrainingConstructionClassificationSparse

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testTrainingConstructionClassificationSparse(self):
    input_data = sparse_tensor.SparseTensor(
        indices=[[0, 0], [0, 3], [1, 0], [1, 7], [2, 1], [3, 9]],
        values=[-1.0, 0.0, -1., 2., 1., -2.0],
        dense_shape=[4, 10])
    input_labels = [0, 1, 2, 3]

    params = tensor_forest.ForestHParams(
        num_classes=4,
        num_features=10,
        num_trees=10,
        max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.training_graph(input_data, input_labels)
    self.assertTrue(isinstance(graph, ops.Operation)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:19,代碼來源:tensor_forest_test.py

示例3: testTrainingConstructionClassificationSparse

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testTrainingConstructionClassificationSparse(self):
    input_data = tf.SparseTensor(
        indices=[[0, 0], [0, 3],
                 [1, 0], [1, 7],
                 [2, 1],
                 [3, 9]],
        values=[-1.0, 0.0,
                -1., 2.,
                1.,
                -2.0],
        shape=[4, 10])
    input_labels = [0, 1, 2, 3]

    params = tensor_forest.ForestHParams(
        num_classes=4, num_features=10, num_trees=10, max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.training_graph(input_data, input_labels)
    self.assertTrue(isinstance(graph, tf.Operation)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:22,代碼來源:tensor_forest_test.py

示例4: __init__

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def __init__(self, params, device_assigner=None, model_dir=None,
               graph_builder_class=tensor_forest.RandomForestGraphs,
               master='', accuracy_metric=None,
               tf_random_seed=None, config=None):
    self.params = params.fill()
    self.accuracy_metric = (accuracy_metric or
                            ('r2' if self.params.regression else 'accuracy'))
    self.data_feeder = None
    self.device_assigner = (
        device_assigner or tensor_forest.RandomForestDeviceAssigner())
    self.graph_builder_class = graph_builder_class
    self.training_args = {}
    self.construction_args = {}

    super(TensorForestEstimator, self).__init__(model_dir=model_dir,
                                                config=config) 
開發者ID:lbkchen,項目名稱:deep-learning,代碼行數:18,代碼來源:rf3.py

示例5: testInferenceConstructionSparse

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testInferenceConstructionSparse(self):
    input_data = tf.SparseTensor(
        indices=[[0, 0], [0, 3],
                 [1, 0], [1, 7],
                 [2, 1],
                 [3, 9]],
        values=[-1.0, 0.0,
                -1., 2.,
                1.,
                -2.0],
        shape=[4, 10])

    params = tensor_forest.ForestHParams(
        num_classes=4, num_features=10, num_trees=10, max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.inference_graph(input_data)
    self.assertTrue(isinstance(graph, tf.Tensor)) 
開發者ID:lbkchen,項目名稱:deep-learning,代碼行數:21,代碼來源:tensor_forest_test.py

示例6: testTrainingConstructionClassification

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testTrainingConstructionClassification(self):
    input_data = [[-1., 0.], [-1., 2.],  # node 1
                  [1., 0.], [1., -2.]]  # node 2
    input_labels = [0, 1, 2, 3]

    params = tensor_forest.ForestHParams(
        num_classes=4,
        num_features=2,
        num_trees=10,
        max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.training_graph(input_data, input_labels)
    self.assertTrue(isinstance(graph, ops.Operation)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:17,代碼來源:tensor_forest_test.py

示例7: testInferenceConstruction

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testInferenceConstruction(self):
    input_data = [[-1., 0.], [-1., 2.],  # node 1
                  [1., 0.], [1., -2.]]  # node 2

    params = tensor_forest.ForestHParams(
        num_classes=4,
        num_features=2,
        num_trees=10,
        max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.inference_graph(input_data)
    self.assertTrue(isinstance(graph, ops.Tensor)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:16,代碼來源:tensor_forest_test.py

示例8: testImpurityConstruction

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testImpurityConstruction(self):
    params = tensor_forest.ForestHParams(
        num_classes=4,
        num_features=2,
        num_trees=10,
        max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.average_impurity()
    self.assertTrue(isinstance(graph, ops.Tensor)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:13,代碼來源:tensor_forest_test.py

示例9: testTrainingConstructionClassification

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testTrainingConstructionClassification(self):
    input_data = [[-1., 0.], [-1., 2.],  # node 1
                  [1., 0.], [1., -2.]]  # node 2
    input_labels = [0, 1, 2, 3]

    params = tensor_forest.ForestHParams(
        num_classes=4, num_features=2, num_trees=10, max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.training_graph(input_data, input_labels)
    self.assertTrue(isinstance(graph, tf.Operation)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:14,代碼來源:tensor_forest_test.py

示例10: testTrainingConstructionRegression

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testTrainingConstructionRegression(self):
    input_data = [[-1., 0.], [-1., 2.],  # node 1
                  [1., 0.], [1., -2.]]  # node 2
    input_labels = [0, 1, 2, 3]

    params = tensor_forest.ForestHParams(
        num_classes=4, num_features=2, num_trees=10, max_nodes=1000,
        split_after_samples=25, regression=True).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.training_graph(input_data, input_labels)
    self.assertTrue(isinstance(graph, tf.Operation)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:14,代碼來源:tensor_forest_test.py

示例11: testInferenceConstruction

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testInferenceConstruction(self):
    input_data = [[-1., 0.], [-1., 2.],  # node 1
                  [1., 0.], [1., -2.]]  # node 2

    params = tensor_forest.ForestHParams(
        num_classes=4, num_features=2, num_trees=10, max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.inference_graph(input_data)
    self.assertTrue(isinstance(graph, tf.Tensor)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:tensor_forest_test.py

示例12: testImpurityConstruction

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def testImpurityConstruction(self):
    params = tensor_forest.ForestHParams(
        num_classes=4, num_features=2, num_trees=10, max_nodes=1000,
        split_after_samples=25).fill()

    graph_builder = tensor_forest.RandomForestGraphs(params)
    graph = graph_builder.average_impurity()
    self.assertTrue(isinstance(graph, tf.Tensor)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:10,代碼來源:tensor_forest_test.py

示例13: __init__

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def __init__(self, params, device_assigner=None, model_dir=None,
               graph_builder_class=tensor_forest.RandomForestGraphs,
               config=None, weights_name=None, keys_name=None,
               feature_engineering_fn=None, early_stopping_rounds=100,
               num_trainers=1, trainer_id=0):

    """Initializes a TensorForestEstimator instance.

    Args:
      params: ForestHParams object that holds random forest hyperparameters.
        These parameters will be passed into `model_fn`.
      device_assigner: An `object` instance that controls how trees get
        assigned to devices. If `None`, will use
        `tensor_forest.RandomForestDeviceAssigner`.
      model_dir: Directory to save model parameters, graph, etc. To continue
        training a previously saved model, load checkpoints saved to this
        directory into an estimator.
      graph_builder_class: An `object` instance that defines how TF graphs for
        random forest training and inference are built. By default will use
        `tensor_forest.RandomForestGraphs`.
      config: `RunConfig` object to configure the runtime settings.
      weights_name: A string defining feature column name representing
        weights. Will be multiplied by the loss of the example. Used to
        downweight or boost examples during training.
      keys_name: A string defining feature column name representing example
        keys. Used by `predict_with_keys` method.
      feature_engineering_fn: Feature engineering function. Takes features and
        labels which are the output of `input_fn` and returns features and
        labels which will be fed into the model.
      early_stopping_rounds: Allows training to terminate early if the forest is
        no longer growing. 100 by default.
      num_trainers: Number of training jobs, which will partition trees
        among them.
      trainer_id: Which trainer this instance is.

    Returns:
      A `TensorForestEstimator` instance.
    """
    self.params = params.fill()
    self.graph_builder_class = graph_builder_class
    self.early_stopping_rounds = early_stopping_rounds
    self.weights_name = weights_name
    self._estimator = estimator.Estimator(
        model_fn=get_model_fn(params, graph_builder_class, device_assigner,
                              weights_name=weights_name, keys_name=keys_name,
                              num_trainers=num_trainers, trainer_id=trainer_id),
        model_dir=model_dir,
        config=config,
        feature_engineering_fn=feature_engineering_fn)
    self._skcompat = estimator.SKCompat(self._estimator) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:52,代碼來源:random_forest.py

示例14: __init__

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def __init__(self, params, device_assigner=None, model_dir=None,
               graph_builder_class=tensor_forest.RandomForestGraphs,
               config=None, weights_name=None, keys_name=None,
               feature_engineering_fn=None, early_stopping_rounds=100):

    """Initializes a TensorForestEstimator instance.

    Args:
      params: ForestHParams object that holds random forest hyperparameters.
        These parameters will be passed into `model_fn`.
      device_assigner: An `object` instance that controls how trees get
        assigned to devices. If `None`, will use
        `tensor_forest.RandomForestDeviceAssigner`.
      model_dir: Directory to save model parameters, graph, etc. To continue
        training a previously saved model, load checkpoints saved to this
        directory into an estimator.
      graph_builder_class: An `object` instance that defines how TF graphs for
        random forest training and inference are built. By default will use
        `tensor_forest.RandomForestGraphs`.
      config: `RunConfig` object to configure the runtime settings.
      weights_name: A string defining feature column name representing
        weights. Will be multiplied by the loss of the example. Used to
        downweight or boost examples during training.
      keys_name: A string defining feature column name representing example
        keys. Used by `predict_with_keys` method.
      feature_engineering_fn: Feature engineering function. Takes features and
        labels which are the output of `input_fn` and returns features and
        labels which will be fed into the model.
      early_stopping_rounds: Allows training to terminate early if the forest is
        no longer growing. 100 by default.

    Returns:
      A `TensorForestEstimator` instance.
    """
    self.params = params.fill()
    self.graph_builder_class = graph_builder_class
    self.early_stopping_rounds = early_stopping_rounds
    self.weights_name = weights_name
    self._estimator = estimator.Estimator(
        model_fn=get_model_fn(params, graph_builder_class, device_assigner,
                              weights_name=weights_name, keys_name=keys_name),
        model_dir=model_dir,
        config=config,
        feature_engineering_fn=feature_engineering_fn) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:46,代碼來源:random_forest.py

示例15: _build_estimator

# 需要導入模塊: from tensorflow.contrib.tensor_forest.python import tensor_forest [as 別名]
# 或者: from tensorflow.contrib.tensor_forest.python.tensor_forest import RandomForestGraphs [as 別名]
def _build_estimator(self, X=None, Y=None):

        if not self._estimator_built:
            if self.n_features is None:
                self.n_features = get_num_features(X)
            if self.n_classes is None:
                if not self.regression:
                    self.n_classes = get_num_classes(Y)
                else:
                    self.n_classes = get_num_features(Y)

            # Reload params from checkpoint if available
            if self._to_be_restored and self.n_features is None:
                self.n_features = read_tensor_in_checkpoint(
                    'n_features', self._to_be_restored)
            if self._to_be_restored and self.n_classes is None:
                self.n_classes = read_tensor_in_checkpoint(
                    'n_classes', self._to_be_restored)

            # Purity checks
            if self.n_classes is None:
                raise ValueError("'n_classes' cannot be None.")
            if self.n_features is None:
                raise ValueError("'n_features' cannot be None.")

            # Persistent Parameters
            tf.Variable(self.n_classes, dtype=tf.int32, name='n_classes')
            tf.Variable(self.n_features, dtype=tf.int32, name='n_features')

            # Random Forest Parameters
            self.params = tensor_forest.ForestHParams(
                num_classes=self.n_classes, num_features=self.n_features,
                num_trees=self.n_estimators, max_nodes=self.max_nodes,
                split_after_samples=self.split_after_samples,
                min_split_samples=self.min_samples_split,
                regression=self.regression,
                bagging_fraction=self.bagging_fraction,
                num_splits_to_consider=self.num_splits_to_consider,
                feature_bagging_fraction=self.feature_bagging_fraction,
                max_fertile_nodes=self.max_fertile_nodes,
                valid_leaf_threshold=self.valid_leaf_threshold,
                dominate_method=self.dominate_method,
                dominate_fraction=self.dominate_fraction).fill()
            self.forest_graph = tensor_forest.RandomForestGraphs(self.params)
            self._estimator_built = True 
開發者ID:limbo018,項目名稱:FRU,代碼行數:47,代碼來源:forest.py


注:本文中的tensorflow.contrib.tensor_forest.python.tensor_forest.RandomForestGraphs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。