TF学习——TF之API:TensorFlow的高级机器学习API—tf.contrib.learn的简介、使用方法、案例应用之详细攻略

简介: TF学习——TF之API:TensorFlow的高级机器学习API—tf.contrib.learn的简介、使用方法、案例应用之详细攻略

tf.contrib.learn的简介




tf.contrib.learn 是 TensorFlow 提供的一个机器学习高级 API 模块,让用户可以更方便的配置、训练和评估各种各样的机器学习模型,里面内置了很多模型可以直接调用,其实,就是类似最经典的机器学习库 scikit-learn 的 API 。很多调用方法都很相同。


1、常用的模型


线性分类 tf.contrib.learn.LinearClassifier

线性回归 tf.contrib.learn.LinearRegressor

逻辑斯谛回归 tf.contrib.learn.LogisticRegressor

K-means 聚类 tf.contrib.learn.KMeansClustering

神经网络分类器 tf.contrib.learn.DNNClassifier

神经网络回归器 tf.contrib.learn.DNNRegressor

广度深度回归 tf.contrib.learn.DNNLinearCombinedRegressor

广度深度分类 tf.contrib.learn.DNNLinearCombinedClassifier

注意:该模块已被弃用,请仔细查看API说明,https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/contrib/learn/README.md

Many canned estimators (subclasses of Estimator) have equivalents in core exposed under tf.estimator: DNNClassifier, DNNRegressor, DNNEstimator, LinearClassifier, LinearRegressor, LinearEstimator, DNNLinearCombinedClassifier,DNNLinearCombinedRegressor and DNNLinearCombinedEstimator.


To migrate to the new api, users need to take the following steps:

Replace tf.contrib.learn with tf.estimator.



tf.contrib.learn的使用方法


Modules


datasets module: Dataset utilities and synthetic/reference datasets (deprecated).

graph_actions module: High level operations on graphs (deprecated).

head module: Abstractions for the head(s) of a model (deprecated).

io module: Tools to allow different io formats (deprecated).

learn_runner module: Utilities to run and tune an Experiment (deprecated).

models module: Various high level TF models (deprecated).

monitors module: Monitors instrument the training process (deprecated).

ops module: Various TensorFlow Ops (deprecated).

preprocessing module: Preprocessing tools useful for building models (deprecated).

utils module: TensorFlow Learn Utils (deprecated).


Classes


class BaseEstimator: Abstract BaseEstimator class to train and evaluate TensorFlow models.

class DNNClassifier: A classifier for TensorFlow DNN models.

class DNNEstimator: A Estimator for TensorFlow DNN models with user specified _Head.

class DNNLinearCombinedClassifier: A classifier for TensorFlow Linear and DNN joined training models.

class DNNLinearCombinedEstimator: An estimator for TensorFlow Linear and DNN joined training models.

class DNNLinearCombinedRegressor: A regressor for TensorFlow Linear and DNN joined training models.

class DNNRegressor: A regressor for TensorFlow DNN models.

class DynamicRnnEstimator: Dynamically unrolled RNN (deprecated).

class Estimator: Estimator class is the basic TensorFlow model trainer/evaluator.

class Evaluable: Interface for objects that are evaluatable by, e.g., Experiment.

class Experiment: Experiment is a class containing all information needed to train a model.

class ExportStrategy: A class representing a type of model export.

class Head: Interface for the head/top of a model.

class InputFnOps: A return type for an input_fn (deprecated).

class KMeansClustering: An Estimator for K-Means clustering.

class LinearClassifier: Linear classifier model.

class LinearEstimator: Linear model with user specified head.

class LinearRegressor: Linear regressor model.

class MetricSpec: MetricSpec connects a model to metric functions.

class ModeKeys: Standard names for model modes (deprecated).

class ModelFnOps: Ops returned from a model_fn.

class NanLossDuringTrainingError: Unspecified run-time error.

class NotFittedError: Exception class to raise if estimator is used before fitting.

class PredictionKey: THIS CLASS IS DEPRECATED.

class ProblemType: Enum-like values for the type of problem that the model solves.

class RunConfig: This class specifies the configurations for an Estimator run.

class SKCompat: Scikit learn wrapper for TensorFlow Learn Estimator.

class SVM: Support Vector Machine (SVM) model for binary classification.

class TaskType: DEPRECATED CLASS.

class Trainable: Interface for objects that are trainable by, e.g., Experiment.


Functions


LogisticRegressor(...): Builds a logistic regression Estimator for binary classification.

binary_svm_head(...): Creates a Head for binary classification with SVMs. (deprecated)

build_parsing_serving_input_fn(...): Build an input_fn appropriate for serving, expecting fed tf.Examples. (deprecated)

evaluate(...): Evaluate a model loaded from a checkpoint. (deprecated)

extract_dask_data(...): Extract data from dask.Series or dask.DataFrame for predictors. (deprecated)

extract_dask_labels(...): Extract data from dask.Series or dask.DataFrame for labels. (deprecated)

extract_pandas_data(...): Extract data from pandas.DataFrame for predictors. (deprecated)

extract_pandas_labels(...): Extract data from pandas.DataFrame for labels. (deprecated)

extract_pandas_matrix(...): Extracts numpy matrix from pandas DataFrame. (deprecated)

infer(...): Restore graph from restore_checkpoint_path and run output_dict tensors. (deprecated)

infer_real_valued_columns_from_input(...): Creates FeatureColumn objects for inputs defined by input x. (deprecated)

infer_real_valued_columns_from_input_fn(...): Creates FeatureColumn objects for inputs defined by input_fn. (deprecated)

make_export_strategy(...): Create an ExportStrategy for use with Experiment. (deprecated)

multi_class_head(...): Creates a Head for multi class single label classification. (deprecated)

multi_head(...): Creates a MultiHead stemming from same logits/hidden layer. (deprecated)

multi_label_head(...): Creates a Head for multi label classification. (deprecated)

no_op_train_fn(...): DEPRECATED FUNCTION

poisson_regression_head(...): Creates a Head for poisson regression. (deprecated)

read_batch_examples(...): Adds operations to read, queue, batch Example protos. (deprecated)

read_batch_features(...): Adds operations to read, queue, batch and parse Example protos. (deprecated)

read_batch_record_features(...): Reads TFRecord, queues, batches and parses Example proto. (deprecated)

read_keyed_batch_examples(...): Adds operations to read, queue, batch Example protos. (deprecated)

read_keyed_batch_examples_shared_queue(...): Adds operations to read, queue, batch Example protos. (deprecated)

read_keyed_batch_features(...): Adds operations to read, queue, batch and parse Example protos. (deprecated)

read_keyed_batch_features_shared_queue(...): Adds operations to read, queue, batch and parse Exampleprotos.(deprecated)

regression_head(...): Creates a Head for linear regression. (deprecated)

run_feeds(...): See run_feeds_iter(). Returns a list instead of an iterator. (deprecated)

run_n(...): Run output_dict tensors n times, with the same feed_dict each run. (deprecated)

train(...): Train a model. (deprecated)



tf.contrib.learn的案例应用


更新……


 


相关文章
|
3天前
|
机器学习/深度学习 人工智能 物联网
通义灵码在人工智能与机器学习领域的应用
通义灵码不仅在物联网领域表现出色,还在人工智能、机器学习、金融、医疗和教育等领域展现出广泛应用前景。本文探讨了其在这些领域的具体应用,如模型训练、风险评估、医疗影像诊断等,并总结了其提高开发效率、降低门槛、促进合作和推动创新的优势。
通义灵码在人工智能与机器学习领域的应用
|
3天前
|
机器学习/深度学习 传感器 自动驾驶
探索机器学习在图像识别中的创新应用
本文深入分析了机器学习技术在图像识别领域的最新进展,探讨了深度学习算法如何推动图像处理技术的突破。通过具体案例分析,揭示了机器学习模型在提高图像识别准确率、效率及应用场景拓展方面的潜力。文章旨在为读者提供一个全面的视角,了解当前机器学习在图像识别领域的创新应用和未来发展趋势。
|
4天前
|
机器学习/深度学习 人工智能 算法
【手写数字识别】Python+深度学习+机器学习+人工智能+TensorFlow+算法模型
手写数字识别系统,使用Python作为主要开发语言,基于深度学习TensorFlow框架,搭建卷积神经网络算法。并通过对数据集进行训练,最后得到一个识别精度较高的模型。并基于Flask框架,开发网页端操作平台,实现用户上传一张图片识别其名称。
18 0
【手写数字识别】Python+深度学习+机器学习+人工智能+TensorFlow+算法模型
|
13天前
|
机器学习/深度学习 人工智能 自然语言处理
思通数科AI平台在尽职调查中的技术解析与应用
思通数科AI多模态能力平台结合OCR、NLP和深度学习技术,为IPO尽职调查、融资等重要交易环节提供智能化解决方案。平台自动识别、提取并分类海量文档,实现高效数据核验与合规性检查,显著提升审查速度和精准度,同时保障敏感信息管理和数据安全。
62 11
|
13天前
|
机器学习/深度学习 数据采集 运维
智能化运维:机器学习在故障预测和自动化响应中的应用
智能化运维:机器学习在故障预测和自动化响应中的应用
38 4
|
14天前
|
机器学习/深度学习 TensorFlow API
机器学习实战:TensorFlow在图像识别中的应用探索
【10月更文挑战第28天】随着深度学习技术的发展,图像识别取得了显著进步。TensorFlow作为Google开源的机器学习框架,凭借其强大的功能和灵活的API,在图像识别任务中广泛应用。本文通过实战案例,探讨TensorFlow在图像识别中的优势与挑战,展示如何使用TensorFlow构建和训练卷积神经网络(CNN),并评估模型的性能。尽管面临学习曲线和资源消耗等挑战,TensorFlow仍展现出广阔的应用前景。
40 5
|
21天前
|
机器学习/深度学习 并行计算 数据挖掘
R语言是一种强大的统计分析工具,广泛应用于数据分析和机器学习领域
【10月更文挑战第21天】R语言是一种强大的统计分析工具,广泛应用于数据分析和机器学习领域。本文将介绍R语言中的一些高级编程技巧,包括函数式编程、向量化运算、字符串处理、循环和条件语句、异常处理和性能优化等方面,以帮助读者更好地掌握R语言的编程技巧,提高数据分析的效率。
38 2
|
8天前
|
机器学习/深度学习 人工智能 安全
人工智能与机器学习在网络安全中的应用
人工智能与机器学习在网络安全中的应用
25 0
|
4天前
|
JSON API 数据格式
淘宝 / 天猫官方商品 / 订单订单 API 接口丨商品上传接口对接步骤
要对接淘宝/天猫官方商品或订单API,需先注册淘宝开放平台账号,创建应用获取App Key和App Secret。之后,详细阅读API文档,了解接口功能及权限要求,编写认证、构建请求、发送请求和处理响应的代码。最后,在沙箱环境中测试与调试,确保API调用的正确性和稳定性。