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

一个公司做100个网站快速建网站模板

一个公司做100个网站,快速建网站模板,网站设计流程及制作流程,漂亮网站设计目录 前言TensorFlow实现逻辑回归 前言 实现逻辑回归的套路和实现线性回归差不多, 只不过逻辑回归的目标函数和损失函数不一样而已. TensorFlow实现逻辑回归 import tensorflow as tf import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import mak…

目录

  • 前言
  • TensorFlow实现逻辑回归

前言

实现逻辑回归的套路和实现线性回归差不多, 只不过逻辑回归的目标函数和损失函数不一样而已.

TensorFlow实现逻辑回归

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs# 生成二分类数据集
data, target = make_blobs(centers=2)
plt.scatter(data[:, 0], data[:, 1], c=target)
plt.show()# 初始化参数 (修复维度)
w = tf.Variable(initial_value=np.random.randn(2, 1) * 0.01, dtype=tf.float32)  # 二分类只需 1 个输出单元
b = tf.Variable(initial_value=0.0, dtype=tf.float32)# 输入数据(无需对 target 做 one-hot 编码)
x = tf.constant(data, dtype=tf.float32)
y = tf.constant(target.reshape(-1, 1), dtype=tf.float32)  # 目标形状为 (100, 1)# 定义模型输出(logits)
def logits(x):return tf.matmul(x, w) + b  # 输出形状 (100, 1)# 定义损失函数(二元交叉熵)
def loss(y_true, y_pred):y_pred = tf.clip_by_value(y_pred, 1e-9, 1.0)return -tf.reduce_mean(y_true * tf.math.log(y_pred) + (1 - y_true) * tf.math.log(1 - y_pred))# 定义优化器
optimizer = tf.optimizers.SGD(0.001)# 定义训练步骤
def run_optimization():with tf.GradientTape() as g:pred = tf.sigmoid(logits(x))  # 使用 sigmoid 激活函数cost = loss(y, pred)gradients = g.gradient(cost, [w, b])optimizer.apply_gradients(zip(gradients, [w, b]))# 定义准确率计算
def accuracy(y_true, y_pred):y_pred_class = tf.cast(y_pred > 0.5, dtype=tf.float32)  # 概率转类别return tf.reduce_mean(tf.cast(tf.equal(y_true, y_pred_class), dtype=tf.float32))# 开始训练
for i in range(1, 10001):run_optimization()if i % 100 == 0:y_pred_prob = tf.sigmoid(logits(x))acc = accuracy(y, y_pred_prob)loss_ = loss(y, y_pred_prob)print(f'Step {i}, 准确率: {acc.numpy()}, 损失: {loss_.numpy()}')

结果如下:
在这里插入图片描述

Step 100, 准确率: 1.0, 损失: 0.4105553925037384
Step 200, 准确率: 1.0, 损失: 0.28594353795051575
Step 300, 准确率: 1.0, 损失: 0.21672113239765167
Step 400, 准确率: 1.0, 损失: 0.17359928786754608
Step 500, 准确率: 1.0, 损失: 0.1445026844739914
Step 600, 准确率: 1.0, 损失: 0.12367361038923264
Step 700, 准确率: 1.0, 损失: 0.10807851701974869
Step 800, 准确率: 1.0, 损失: 0.09598751366138458
Step 900, 准确率: 1.0, 损失: 0.08634963631629944
Step 1000, 准确率: 1.0, 损失: 0.07849213480949402
Step 1100, 准确率: 1.0, 损失: 0.07196593284606934
Step 1200, 准确率: 1.0, 损失: 0.06646033376455307
Step 1300, 准确率: 1.0, 损失: 0.061753835529088974
Step 1400, 准确率: 1.0, 损失: 0.05768435448408127
Step 1500, 准确率: 1.0, 损失: 0.054130859673023224
Step 1600, 准确率: 1.0, 损失: 0.0510009303689003
Step 1700, 准确率: 1.0, 损失: 0.048222970217466354
Step 1800, 准确率: 1.0, 损失: 0.04574064165353775
Step 1900, 准确率: 1.0, 损失: 0.04350901022553444
Step 2000, 准确率: 1.0, 损失: 0.04149177670478821
Step 2100, 准确率: 1.0, 损失: 0.039659276604652405
Step 2200, 准确率: 1.0, 损失: 0.03798716142773628
Step 2300, 准确率: 1.0, 损失: 0.03645514324307442
Step 2400, 准确率: 1.0, 损失: 0.035046208649873734
Step 2500, 准确率: 1.0, 损失: 0.03374601528048515
Step 2600, 准确率: 1.0, 损失: 0.03254235163331032
Step 2700, 准确率: 1.0, 损失: 0.031424783170223236
Step 2800, 准确率: 1.0, 损失: 0.030384326353669167
Step 2900, 准确率: 1.0, 损失: 0.02941320464015007
Step 3000, 准确率: 1.0, 损失: 0.02850465290248394
Step 3100, 准确率: 1.0, 损失: 0.027652768418192863
Step 3200, 准确率: 1.0, 损失: 0.026852363720536232
Step 3300, 准确率: 1.0, 损失: 0.026098856702446938
Step 3400, 准确率: 1.0, 损失: 0.025388216599822044
Step 3500, 准确率: 1.0, 损失: 0.024716870859265327
Step 3600, 准确率: 1.0, 损失: 0.02408158965408802
Step 3700, 准确率: 1.0, 损失: 0.0234795231372118
Step 3800, 准确率: 1.0, 损失: 0.022908106446266174
Step 3900, 准确率: 1.0, 损失: 0.0223650261759758
Step 4000, 准确率: 1.0, 损失: 0.021848207339644432
Step 4100, 准确率: 1.0, 损失: 0.02135578542947769
Step 4200, 准确率: 1.0, 损失: 0.020886056125164032
Step 4300, 准确率: 1.0, 损失: 0.02043745294213295
Step 4400, 准确率: 1.0, 损失: 0.020008569583296776
Step 4500, 准确率: 1.0, 损失: 0.019598128274083138
Step 4600, 准确率: 1.0, 损失: 0.01920494996011257
Step 4700, 准确率: 1.0, 损失: 0.01882794313132763
Step 4800, 准确率: 1.0, 损失: 0.018466131761670113
Step 4900, 准确率: 1.0, 损失: 0.01811859756708145
Step 5000, 准确率: 1.0, 损失: 0.01778450421988964
Step 5100, 准确率: 1.0, 损失: 0.0174630805850029
Step 5200, 准确率: 1.0, 损失: 0.01715361326932907
Step 5300, 准确率: 1.0, 损失: 0.016855429857969284
Step 5400, 准确率: 1.0, 损失: 0.016567926853895187
Step 5500, 准确率: 1.0, 损失: 0.016290517523884773
Step 5600, 准确率: 1.0, 损失: 0.0160226970911026
Step 5700, 准确率: 1.0, 损失: 0.015763945877552032
Step 5800, 准确率: 1.0, 损失: 0.015513807535171509
Step 5900, 准确率: 1.0, 损失: 0.015271877869963646
Step 6000, 准确率: 1.0, 损失: 0.015037745237350464
Step 6100, 准确率: 1.0, 损失: 0.014811034314334393
Step 6200, 准确率: 1.0, 损失: 0.014591369777917862
Step 6300, 准确率: 1.0, 损失: 0.014378437772393227
Step 6400, 准确率: 1.0, 损失: 0.014171929098665714
Step 6500, 准确率: 1.0, 损失: 0.013971567153930664
Step 6600, 准确率: 1.0, 损失: 0.013777065090835094
Step 6700, 准确率: 1.0, 损失: 0.013588163070380688
Step 6800, 准确率: 1.0, 损失: 0.01340463850647211
Step 6900, 准确率: 1.0, 损失: 0.013226241804659367
Step 7000, 准确率: 1.0, 损失: 0.013052761554718018
Step 7100, 准确率: 1.0, 损失: 0.012884002178907394
Step 7200, 准确率: 1.0, 损失: 0.01271976437419653
Step 7300, 准确率: 1.0, 损失: 0.012559876777231693
Step 7400, 准确率: 1.0, 损失: 0.012404152192175388
Step 7500, 准确率: 1.0, 损失: 0.012252428568899632
Step 7600, 准确率: 1.0, 损失: 0.012104558758437634
Step 7700, 准确率: 1.0, 损失: 0.01196039654314518
Step 7800, 准确率: 1.0, 损失: 0.011819805018603802
Step 7900, 准确率: 1.0, 损失: 0.01168263703584671
Step 8000, 准确率: 1.0, 损失: 0.011548792943358421
Step 8100, 准确率: 1.0, 损失: 0.011418122798204422
Step 8200, 准确率: 1.0, 损失: 0.011290528811514378
Step 8300, 准确率: 1.0, 损失: 0.011165900155901909
Step 8400, 准确率: 1.0, 损失: 0.01104412879794836
Step 8500, 准确率: 1.0, 损失: 0.010925106704235077
Step 8600, 准确率: 1.0, 损失: 0.010808765888214111
Step 8700, 准确率: 1.0, 损失: 0.010695010423660278
Step 8800, 准确率: 1.0, 损失: 0.010583736933767796
Step 8900, 准确率: 1.0, 损失: 0.010474861599504948
Step 9000, 准确率: 1.0, 损失: 0.010368350893259048
Step 9100, 准确率: 1.0, 损失: 0.01026405580341816
Step 9200, 准确率: 1.0, 损失: 0.01016198005527258
Step 9300, 准确率: 1.0, 损失: 0.010061997920274734
Step 9400, 准确率: 1.0, 损失: 0.009964067488908768
Step 9500, 准确率: 1.0, 损失: 0.009868137538433075
Step 9600, 准确率: 1.0, 损失: 0.009774118661880493
Step 9700, 准确率: 1.0, 损失: 0.00968195591121912
Step 9800, 准确率: 1.0, 损失: 0.009591614827513695
Step 9900, 准确率: 1.0, 损失: 0.009503037668764591
Step 10000, 准确率: 1.0, 损失: 0.009416175074875355

文章转载自:

http://2vC0V3GJ.nmngg.cn
http://XzOQ2VAc.nmngg.cn
http://ziEWCBWS.nmngg.cn
http://FYIyPejh.nmngg.cn
http://YzMbqp8V.nmngg.cn
http://ixLR8mBU.nmngg.cn
http://f22k3Sha.nmngg.cn
http://hCeDnLlv.nmngg.cn
http://eWY91ccQ.nmngg.cn
http://2l5kyX3U.nmngg.cn
http://DNzOQoJE.nmngg.cn
http://IIQbkIUH.nmngg.cn
http://Y7IC3eCN.nmngg.cn
http://kr2qI5T4.nmngg.cn
http://y6dWQdMo.nmngg.cn
http://B1K8httc.nmngg.cn
http://c1vniplG.nmngg.cn
http://KWLENZlE.nmngg.cn
http://u5RQ841W.nmngg.cn
http://bABVnM1C.nmngg.cn
http://RTUAQgJP.nmngg.cn
http://emkU9lni.nmngg.cn
http://T9BySfy5.nmngg.cn
http://u0DV8aeq.nmngg.cn
http://aIz6PHR8.nmngg.cn
http://JAhnRDs2.nmngg.cn
http://9rYP3Itn.nmngg.cn
http://ml1gUI2W.nmngg.cn
http://QgOCa4bB.nmngg.cn
http://ZQ4762n1.nmngg.cn
http://www.dtcms.com/wzjs/636476.html

相关文章:

  • 佛山自助建站系统wordpress 如何删除所有评论
  • 网站建设与管理期末考试网站开发实践研究报告
  • 帮熟人做网站如何收费wordpress搭建表单
  • flash网站引导页面制作乐清手机网站
  • 网站备案审批号北京西站官网主页
  • 福州做彩票app网站网站建设类别
  • 网站备案查询验证码错误...东莞网站公司
  • wordpress视频插件w自己有网站怎么做优化
  • 北京建站公司兴田德润很赞无锡公司网站设计
  • 贸易公司网站模板做外贸需要做国外的网站吗
  • 盗版小说网站怎么做微信一键登录网站怎么做
  • 秦皇岛网站制作定制网络运营者应当制定网络安全事件
  • 网站内页做友链网站设计制作合同
  • 甘肃交通工程建设监理公司网站网页设计师考试报名
  • vs做网站mvc商业网站建设设计
  • 招标网官方网站网站播放图片多大合适
  • 网络营销网站建设ppt做外贸网站的好处
  • 学网站开发跟那个专业最相近知名的深圳小程序开发公司
  • 网站开发 软件垦利区建设局网站
  • 如何搭建网站服务器html5网站提示
  • 做网站得叫什么软件seo竞争对手分析
  • 山西网站设计门户网站功能模块
  • 优惠购网站怎么做的辽宁关键词优化排名外包
  • 健身网站开发可行性分析泉州网站关键词推广
  • 自己做h5制作开发搜索引擎关键词排名优化
  • 怎么在百度建立自己的网站yole市场调研公司
  • 做网站的软件电子360做网站和推广怎么样
  • 网站做下cdn8小8x人成免费观看网页
  • 统计 网站关键字 布局手机表格制作软件
  • 凯发网站兰州建网站