本文整理汇总了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))
示例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))
示例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))
示例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)
示例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))
示例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))
示例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))
示例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))
示例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))
示例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))
示例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))
示例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))
示例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)
示例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)
示例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