当前位置: 首页 > wzjs >正文

网站备案怎么查好f123网站

网站备案怎么查,好f123网站,婚庆公司网站建设,前端什么证书含金量高这一节我们用TensorFlow定义简单的分类器。首先考虑分类器的方程式是什么是值得的。数学习的技巧是使用sigmoid函数。sigmoid函数绘制如图3-40, 通常标记为σ, 是实数域里的函数取值(0, 1)。这个特征很便利,因为我们可以将sigmoid的输出解释为事件发现的概率。 (转…

这一节我们用TensorFlow定义简单的分类器。首先考虑分类器的方程式是什么是值得的。数学习的技巧是使用sigmoid函数。sigmoid函数绘制如图3-40, 通常标记为σ, 是实数域里的函数取值(0, 1)。这个特征很便利,因为我们可以将sigmoid的输出解释为事件发现的概率。  (转换离散事件到连续值是机器学习里反复出现的主题)

图3-40. 绘制sigmoid 函数.

预测离散事件的概率的方程式如下。这些方程式定义了简单的逻辑回归模型:

y0 = σ( wx + b

y1 = 1 σ (wx + b

TensorFlow提供了工具函数来计算sigmoidal值的交叉熵损失。最简单的函数是tf.nn.sigmoid_cross_entropy_with_logits. ( logitsigmoid的逆。实际上,这意味着传递参数到 sigmoid, wx + b, 而不是sigmoidal value σ wx + b 本身)。我们推荐使用 TensorFlow的实现而不是手工定义交叉熵,因为计算交叉熵损失有许多复杂的数值问题。

#List3-44

import numpy as np

np.random.seed(456)

import tensorflow as tf

#tf.set_random_seed(456)

import matplotlib.pyplot as plt

from sklearn.metrics import accuracy_score

from scipy.special import logit

# Generate synthetic data

N = 100

# Zeros form a Gaussian centered at (-1, -1)

x_zeros = np.random.multivariate_normal(mean=np.array((-1, -1)), cov=.1*np.eye(2), size=(N//2,))

y_zeros = np.zeros((N//2,))

# Ones form a Gaussian centered at (1, 1)

x_ones = np.random.multivariate_normal(mean=np.array((1, 1)), cov=.1*np.eye(2), size=(N//2,))

y_ones = np.ones((N//2,))

x_np = np.vstack([x_zeros, x_ones])

y_np = np.concatenate([y_zeros, y_ones])

# Save image of the data distribution

plt.xlabel(r"$x_1$")

plt.ylabel(r"$x_2$")

plt.title("Toy Logistic Regression Data")

# Plot Zeros

plt.scatter(x_zeros[:, 0], x_zeros[:, 1], color="blue")

plt.scatter(x_ones[:, 0], x_ones[:, 1], color="red")

plt.savefig("logistic_data.png")

x_np,y_np

模型的训练代码见List3-45 ,与线性回归模型的代码相同。

#List3-45

W = tf.Variable(tf.random.normal((2, 1)))

b = tf.Variable(tf.random.normal((1,)))

W,b

x=tf.cast(x_np,tf.float32)

y=tf.cast(y_np,tf.float32)

learning_r=0.01

optimizer = tf.optimizers.SGD(learning_r)

n_steps = 100

# Train model

for i in range(n_steps):   

    with tf.GradientTape() as tape:

        #_, summary, loss = sess.run([train_op, merged, l], feed_dict=feed_dict)

        y_logit = tf.squeeze(tf.matmul(x, W) + b)

        # the sigmoid gives the class probability of 1

        y_one_prob = tf.sigmoid(y_logit)

        # Rounding P(y=1) will give the correct prediction.

        y_pred = tf.round(y_one_prob)

        entropy = tf.nn.sigmoid_cross_entropy_with_logits(logits=y_logit, labels=y)

        # Sum all contributions

        l = tf.reduce_sum(entropy)       

        gradients=tape.gradient(l,[W,b])

    optimizer.apply_gradients(zip(gradients, [W, b]))

    #W=W-tf.Variable(learning_r,tf.float32)*W

    #b=b-tf.Variable(learning_r,tf.float32)*b

    print("loss: %f" % l)

    #train_writer.add_summary(summary, i)

    # Get weights

    w_final=W

    b_final=b

# Make Predictions

    #y_pred_np = sess.run(y_pred, feed_dict={x: x_np})

#score = accuracy_score(y_np, y_pred_np)

#print("Classification Accuracy: %f" % score)

plt.clf()

# Save image of the data distribution

plt.xlabel(r"$x_1$")

plt.ylabel(r"$x_2$")

plt.title("Learned Model (Classification Accuracy: 1.00)")

plt.xlim(-2, 2)

plt.ylim(-2, 2)

# Plot Zeros

plt.scatter(x_zeros[:, 0], x_zeros[:, 1], color="blue")

plt.scatter(x_ones[:, 0], x_ones[:, 1], color="red")

x_left = -2

y_left = (1./w_final[1]) * (-b_final + logit(.5) - w_final[0]*x_left)

x_right = 2

y_right = (1./w_final[1]) * (-b_final + logit(.5) - w_final[0]*x_right)

plt.plot([x_left, x_right], [y_left, y_right], color='k')

plt.savefig("logistic_pred.png")

图3-41

http://www.dtcms.com/wzjs/112903.html

相关文章:

  • 有个网站经常换域名百度关键词检测工具
  • 广州响应网站建设站长平台网站
  • 百度做销售网站多少钱网推软件有哪些
  • 网站在线支付接口申请搜索引擎优化推广
  • 公司做网站的费用如何记账比较好的品牌策划公司有哪些
  • 什么系统做购物网站好友情链接平台站长资源
  • 263邮箱个人登录口seo排名首页
  • 知名的网站建设公司seo研究院
  • 网站菜单导航怎么做百度竞价排名服务
  • asp.ney旅游信息网站下载 简洁google官方下载app
  • 作图网站都有哪些怎么做电商生意
  • java开发面试题seo优化宣传
  • 广东做网站的公司资阳市网站seo
  • 网站推广系统合肥新闻 今天 最新消息
  • 做美食的网站网站推广常用方法
  • 电子商务类网站模板青岛网站建设公司哪家好
  • 电子商务网站开发技术支持电子商务网站建设规划方案
  • 怎样做阿里巴巴网站seo推广灰色词
  • 网站建设的流程该怎么确定站长友情链接平台
  • 怎么做网站app营销计划
  • 高端科技网站建设外链大全
  • 网站安全管理制度建设网盘资源大全
  • 中国建设银行网站用户名是什么意思免费网络推广公司
  • 升级网站网站推广四个阶段
  • 中国诚乡建设部网站怎么设计一个网页
  • 哪个网站做原创歌曲seo引流什么意思
  • 军人可以做网站吗seo推广方法
  • 做金融看哪些网站有哪些产品推广文案范文
  • 做网站最小的字体是多少钱淘宝运营培训班
  • 合肥建设银行招聘网站千锋教育靠谱吗