import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from sklearn import datasets
sess = tf.Session()
iris = datasets.load_iris()
binary_target = np.array([1.0 if x ==0 else 0. for x in iris.target])
iris_2d = np.array([[x[2], x[3]] for x in iris.data])
batch_size = 20
x1_data = tf.placeholder(shape=[None, 1], dtype=tf.float32)
x2_data = tf.placeholder(shape=[None, 1], dtype=tf.float32)
y_target = tf.placeholder(shape=[None, 1], dtype=tf.float32)
A = tf.Variable(tf.random_normal(shape=[1, 1]))
b = tf.Variable(tf.random_normal(shape=[1, 1]))
my_mult = tf.matmul(x2_data, A)
my_add = tf.add(my_mult, b)
my_output = tf.subtract(x1_data, my_add)
xentropy = tf.nn.sigmoid_cross_entropy_with_logits(logits=my_output, labels=y_target)
my_opt = tf.train.GradientDescentOptimizer(0.05)
train_step = my_opt.minimize(xentropy)
i
TensorFlow机器学习实战指南——山鸢尾花分类
最新推荐文章于 2024-09-30 18:26:55 发布
使用TensorFlow建立了一个二元分类模型,针对山鸢尾花数据集进行训练。通过梯度下降优化器训练了1000步,并展示了训练过程中权重参数的变化。最后,绘制了分类边界线与数据点分布图,有效地将鸢尾花中的山鸢尾花与其他类别分开。
摘要由CSDN通过智能技术生成