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的案例应用


更新……


 


相关文章
|
8月前
|
人工智能 自然语言处理 数据挖掘
云上玩转Qwen3系列之三:PAI-LangStudio x Hologres构建ChatBI数据分析Agent应用
PAI-LangStudio 和 Qwen3 构建基于 MCP 协议的 Hologres ChatBI 智能 Agent 应用,通过将 Agent、MCP Server 等技术和阿里最新的推理模型 Qwen3 编排在一个应用流中,为大模型提供了 MCP+OLAP 的智能数据分析能力,使用自然语言即可实现 OLAP 数据分析的查询效果,减少了幻觉。开发者可以基于该模板进行灵活扩展和二次开发,以满足特定场景的需求。
|
4月前
|
机器学习/深度学习 数据采集 算法
量子机器学习入门:三种数据编码方法对比与应用
在量子机器学习中,数据编码方式决定了量子模型如何理解和处理信息。本文详解角度编码、振幅编码与基础编码三种方法,分析其原理、实现及适用场景,帮助读者选择最适合的编码策略,提升量子模型性能。
361 8
|
5月前
|
机器学习/深度学习 人工智能 自然语言处理
Java 大视界 -- Java 大数据机器学习模型在自然语言生成中的可控性研究与应用(229)
本文深入探讨Java大数据与机器学习在自然语言生成(NLG)中的可控性研究,分析当前生成模型面临的“失控”挑战,如数据噪声、标注偏差及黑盒模型信任问题,提出Java技术在数据清洗、异构框架融合与生态工具链中的关键作用。通过条件注入、强化学习与模型融合等策略,实现文本生成的精准控制,并结合网易新闻与蚂蚁集团的实战案例,展示Java在提升生成效率与合规性方面的卓越能力,为金融、法律等强监管领域提供技术参考。
|
5月前
|
机器学习/深度学习 算法 Java
Java 大视界 -- Java 大数据机器学习模型在生物信息学基因功能预测中的优化与应用(223)
本文探讨了Java大数据与机器学习模型在生物信息学中基因功能预测的优化与应用。通过高效的数据处理能力和智能算法,提升基因功能预测的准确性与效率,助力医学与农业发展。
|
5月前
|
机器学习/深度学习 搜索推荐 数据可视化
Java 大视界 -- Java 大数据机器学习模型在电商用户流失预测与留存策略制定中的应用(217)
本文探讨 Java 大数据与机器学习在电商用户流失预测与留存策略中的应用。通过构建高精度预测模型与动态分层策略,助力企业提前识别流失用户、精准触达,实现用户留存率与商业价值双提升,为电商应对用户流失提供技术新思路。
|
5月前
|
机器学习/深度学习 存储 分布式计算
Java 大视界 --Java 大数据机器学习模型在金融风险压力测试中的应用与验证(211)
本文探讨了Java大数据与机器学习模型在金融风险压力测试中的创新应用。通过多源数据采集、模型构建与优化,结合随机森林、LSTM等算法,实现信用风险动态评估、市场极端场景模拟与操作风险预警。案例分析展示了花旗银行与蚂蚁集团的智能风控实践,验证了技术在提升风险识别效率与降低金融风险损失方面的显著成效。
|
6月前
|
机器学习/深度学习 分布式计算 Java
Java 大视界 -- Java 大数据机器学习模型在遥感图像土地利用分类中的优化与应用(199)
本文探讨了Java大数据与机器学习模型在遥感图像土地利用分类中的优化与应用。面对传统方法效率低、精度差的问题,结合Hadoop、Spark与深度学习框架,实现了高效、精准的分类。通过实际案例展示了Java在数据处理、模型融合与参数调优中的强大能力,推动遥感图像分类迈向新高度。
|
6月前
|
机器学习/深度学习 存储 Java
Java 大视界 -- Java 大数据机器学习模型在游戏用户行为分析与游戏平衡优化中的应用(190)
本文探讨了Java大数据与机器学习模型在游戏用户行为分析及游戏平衡优化中的应用。通过数据采集、预处理与聚类分析,开发者可深入洞察玩家行为特征,构建个性化运营策略。同时,利用回归模型优化游戏数值与付费机制,提升游戏公平性与用户体验。
|
8月前
|
机器学习/深度学习 数据采集 人工智能
智能嗅探AJAX触发:机器学习在动态渲染中的创新应用
随着Web技术发展,动态加载数据的网站(如今日头条)对传统爬虫提出新挑战:初始HTML无完整数据、请求路径动态生成且易触发反爬策略。本文以爬取“AI”相关新闻为例,探讨了通过浏览器自动化、抓包分析和静态逆向接口等方法采集数据的局限性,并提出借助机器学习智能识别AJAX触发点的解决方案。通过特征提取与模型训练,爬虫可自动推测数据接口路径并高效采集。代码实现展示了如何模拟AJAX请求获取新闻标题、简介、作者和时间,并分类存储。未来,智能化将成为采集技术的发展趋势。
209 1
智能嗅探AJAX触发:机器学习在动态渲染中的创新应用
|
8月前
|
人工智能 自然语言处理 数据库
云上玩转Qwen3系列之二:PAI-LangStudio搭建联网搜索和RAG增强问答应用
本文详细介绍了如何使用 PAI-LangStudio 和 Qwen3 构建基于 RAG 和联网搜索 的 AI 智能问答应用。该应用通过将 RAG、web search 等技术和阿里最新的推理模型 Qwen3 编排在一个应用流中,为大模型提供了额外的联网搜索和特定领域知识库检索的能力,提升了智能回答的效果,减少了幻觉。开发者可以基于该模板进行灵活扩展和二次开发,以满足特定场景的需求。

热门文章

最新文章