python中tensorflow实现二分类_TensorFlow实现创建分类器

本文演示如何使用TensorFlow创建一个二分类器,以预测鸢尾花是否为山鸢尾。通过导入iris数据集,选取花瓣长度和宽度作为特征,利用sigmoid交叉熵损失函数和梯度下降优化器进行训练,最终得到分类器的模型参数并绘制分类边界。
摘要由CSDN通过智能技术生成

本文实例为大家分享了TensorFlow实现创建分类器的具体代码,供大家参考,具体内容如下

创建一个iris数据集的分类器。

加载样本数据集,实现一个简单的二值分类器来预测一朵花是否为山鸢尾。iris数据集有三类花,但这里仅预测是否是山鸢尾。导入iris数据集和工具库,相应地对原数据集进行转换。

# Combining Everything Together

#----------------------------------

# This file will perform binary classification on the

# iris dataset. We will only predict if a flower is

# I.setosa or not.

#

# We will create a simple binary classifier by creating a line

# and running everything through a sigmoid to get a binary predictor.

# The two features we will use are pedal length and pedal width.

#

# We will use batch training, but this can be easily

# adapted to stochastic training.

import matplotlib.pyplot as plt

import numpy as np

from sklearn import datasets

import tensorflow as tf

from tensorflow.python.f

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值