国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

【PyTorch基礎(chǔ)教程1】線性模型(學(xué)不會來打我啊)

djfml / 3728人閱讀

摘要:文章目錄一線性模型二繪圖工具三作業(yè)一線性模型不要小看簡單線性模型哈哈,雖然這講我們還沒正式用到,但是用到的前向傳播損失函數(shù)兩種繪圖等方法在后面是很常用的。

一、線性模型

不要小看簡單線性模型哈哈,雖然這講我們還沒正式用到pytorch,但是用到的前向傳播、損失函數(shù)、兩種繪loss圖等方法在后面是很常用的。
對下面的代碼說明:

  • zip函數(shù)可以將x_datay_data組合元組列表,在for循環(huán)中每次遍歷就是對于列表中的每個元組。
  • 函數(shù)forward()中,有一個變量w。這個變量最終的值是從for循環(huán)中傳入的。
# -*- coding: utf-8 -*-"""Created on Tue Oct 12 14:30:13 2021@author: 86493"""import numpy as npimport matplotlib.pyplot as pltx_data = [1.0, 2.0, 3.0]y_data = [2.0, 4.0, 6.0]def forward(x):    return x * wdef loss(x, y):    y_pred = forward(x)    return (y_pred - y) * (y_pred - y)# 保存權(quán)重w_list = []# 保存權(quán)重的損失函數(shù)值mse_list = []# 窮舉w值對應(yīng)的損失函數(shù)MSEfor w in np.arange(0.0, 4.1, 0.1):    print("w = ", w)    loss_sum = 0    for x_val, y_val in zip(x_data, y_data):        # 為了打印y預(yù)測值,其實loss里也計算了        y_pred_val = forward(x_val)        loss_val = loss(x_val, y_val)        loss_sum += loss_val        print("/t", x_val, y_val,              y_pred_val, loss_val)    print("MSE = ", loss_sum / 3)    print("="*60)    w_list.append(w)    mse_list.append(loss_sum / 3)     # 繪loss變化圖,橫坐標(biāo)是w,縱坐標(biāo)是lossplt.plot(w_list, mse_list)plt.ylabel("Loss")plt.xlabel("w")plt.show()

剛才對應(yīng)的打印結(jié)果為:

w =  0.0	 1.0 2.0 0.0 4.0	 2.0 4.0 0.0 16.0	 3.0 6.0 0.0 36.0MSE =  18.666666666666668============================================================w =  0.1	 1.0 2.0 0.1 3.61	 2.0 4.0 0.2 14.44	 3.0 6.0 0.30000000000000004 32.49MSE =  16.846666666666668============================================================w =  0.2	 1.0 2.0 0.2 3.24	 2.0 4.0 0.4 12.96	 3.0 6.0 0.6000000000000001 29.160000000000004MSE =  15.120000000000003============================================================w =  0.30000000000000004	 1.0 2.0 0.30000000000000004 2.8899999999999997	 2.0 4.0 0.6000000000000001 11.559999999999999	 3.0 6.0 0.9000000000000001 26.009999999999998MSE =  13.486666666666665============================================================w =  0.4	 1.0 2.0 0.4 2.5600000000000005	 2.0 4.0 0.8 10.240000000000002	 3.0 6.0 1.2000000000000002 23.04MSE =  11.946666666666667============================================================w =  0.5	 1.0 2.0 0.5 2.25	 2.0 4.0 1.0 9.0	 3.0 6.0 1.5 20.25MSE =  10.5============================================================w =  0.6000000000000001	 1.0 2.0 0.6000000000000001 1.9599999999999997	 2.0 4.0 1.2000000000000002 7.839999999999999	 3.0 6.0 1.8000000000000003 17.639999999999993MSE =  9.146666666666663============================================================w =  0.7000000000000001	 1.0 2.0 0.7000000000000001 1.6899999999999995	 2.0 4.0 1.4000000000000001 6.759999999999998	 3.0 6.0 2.1 15.209999999999999MSE =  7.886666666666666============================================================w =  0.8	 1.0 2.0 0.8 1.44	 2.0 4.0 1.6 5.76	 3.0 6.0 2.4000000000000004 12.959999999999997MSE =  6.719999999999999============================================================w =  0.9	 1.0 2.0 0.9 1.2100000000000002	 2.0 4.0 1.8 4.840000000000001	 3.0 6.0 2.7 10.889999999999999MSE =  5.646666666666666============================================================w =  1.0	 1.0 2.0 1.0 1.0	 2.0 4.0 2.0 4.0	 3.0 6.0 3.0 9.0MSE =  4.666666666666667============================================================w =  1.1	 1.0 2.0 1.1 0.8099999999999998	 2.0 4.0 2.2 3.2399999999999993	 3.0 6.0 3.3000000000000003 7.289999999999998MSE =  3.779999999999999============================================================w =  1.2000000000000002	 1.0 2.0 1.2000000000000002 0.6399999999999997	 2.0 4.0 2.4000000000000004 2.5599999999999987	 3.0 6.0 3.6000000000000005 5.759999999999997MSE =  2.986666666666665============================================================w =  1.3	 1.0 2.0 1.3 0.48999999999999994	 2.0 4.0 2.6 1.9599999999999997	 3.0 6.0 3.9000000000000004 4.409999999999998MSE =  2.2866666666666657============================================================w =  1.4000000000000001	 1.0 2.0 1.4000000000000001 0.3599999999999998	 2.0 4.0 2.8000000000000003 1.4399999999999993	 3.0 6.0 4.2 3.2399999999999993MSE =  1.6799999999999995============================================================w =  1.5	 1.0 2.0 1.5 0.25	 2.0 4.0 3.0 1.0	 3.0 6.0 4.5 2.25MSE =  1.1666666666666667============================================================w =  1.6	 1.0 2.0 1.6 0.15999999999999992	 2.0 4.0 3.2 0.6399999999999997	 3.0 6.0 4.800000000000001 1.4399999999999984MSE =  0.746666666666666============================================================w =  1.7000000000000002	 1.0 2.0 1.7000000000000002 0.0899999999999999	 2.0 4.0 3.4000000000000004 0.3599999999999996	 3.0 6.0 5.1000000000000005 0.809999999999999MSE =  0.4199999999999995============================================================w =  1.8	 1.0 2.0 1.8 0.03999999999999998	 2.0 4.0 3.6 0.15999999999999992	 3.0 6.0 5.4 0.3599999999999996MSE =  0.1866666666666665============================================================w =  1.9000000000000001	 1.0 2.0 1.9000000000000001 0.009999999999999974	 2.0 4.0 3.8000000000000003 0.0399999999999999	 3.0 6.0 5.7 0.0899999999999999MSE =  0.046666666666666586============================================================w =  2.0	 1.0 2.0 2.0 0.0	 2.0 4.0 4.0 0.0	 3.0 6.0 6.0 0.0MSE =  0.0============================================================w =  2.1	 1.0 2.0 2.1 0.010000000000000018	 2.0 4.0 4.2 0.04000000000000007	 3.0 6.0 6.300000000000001 0.09000000000000043MSE =  0.046666666666666835============================================================w =  2.2	 1.0 2.0 2.2 0.04000000000000007	 2.0 4.0 4.4 0.16000000000000028	 3.0 6.0 6.6000000000000005 0.36000000000000065MSE =  0.18666666666666698============================================================w =  2.3000000000000003	 1.0 2.0 2.3000000000000003 0.09000000000000016	 2.0 4.0 4.6000000000000005 0.36000000000000065	 3.0 6.0 6.9 0.8100000000000006MSE =  0.42000000000000054============================================================w =  2.4000000000000004	 1.0 2.0 2.4000000000000004 0.16000000000000028	 2.0 4.0 4.800000000000001 0.6400000000000011	 3.0 6.0 7.200000000000001 1.4400000000000026MSE =  0.7466666666666679============================================================w =  2.5	 1.0 2.0 2.5 0.25	 2.0 4.0 5.0 1.0	 3.0 6.0 7.5 2.25MSE =  1.1666666666666667============================================================w =  2.6	 1.0 2.0 2.6 0.3600000000000001	 2.0 4.0 5.2 1.4400000000000004	 3.0 6.0 7.800000000000001 3.2400000000000024MSE =  1.6800000000000008============================================================w =  2.7	 1.0 2.0 2.7 0.49000000000000027	 2.0 4.0 5.4 1.960000000000001	 3.0 6.0 8.100000000000001 4.410000000000006MSE =  2.2866666666666693==========================================           
               
                                           
                       
                 

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/122570.html

相關(guān)文章

  • 轉(zhuǎn)行測試的看過來!0基礎(chǔ)~自動化測試,我整理的超全學(xué)習(xí)指南...

    摘要:在這個階段,學(xué)習(xí)工具什么的,重點在于接口測試的學(xué)習(xí),所有的工具的學(xué)習(xí),都是在為了接口測試的學(xué)習(xí)做鋪墊。接口測試工具的使用。 很多朋友想要入行軟件測試,但是都不知道該怎么學(xué)。 抽個時間簡單的給大家說下,對于0基礎(chǔ)的朋友,應(yīng)該怎么去學(xué)習(xí)軟件測試。 學(xué)習(xí)軟件測試有2條路可以選。 最省事的當(dāng)然是找個...

    Hanks10100 評論0 收藏0
  • 第7期 Datawhale 組隊學(xué)習(xí)計劃

    馬上就要開始啦這次共組織15個組隊學(xué)習(xí) 涵蓋了AI領(lǐng)域從理論知識到動手實踐的內(nèi)容 按照下面給出的最完備學(xué)習(xí)路線分類 難度系數(shù)分為低、中、高三檔 可以按照需要參加 - 學(xué)習(xí)路線 - showImg(https://segmentfault.com/img/remote/1460000019082128); showImg(https://segmentfault.com/img/remote/...

    dinfer 評論0 收藏0
  • ApacheCN 編程/大數(shù)據(jù)/數(shù)據(jù)科學(xué)/人工智能學(xué)習(xí)資源 2019.6

    摘要:請回復(fù)這個帖子并注明組織個人信息來申請加入。權(quán)限分配靈活,能者居之。數(shù)量超過個,在所有組織中排名前。網(wǎng)站日超過,排名的峰值為。導(dǎo)航歸檔社區(qū)自媒體平臺微博知乎專欄公眾號博客園簡書合作侵權(quán),請聯(lián)系請抄送一份到贊助我們 Special Sponsors showImg(https://segmentfault.com/img/remote/1460000018907426?w=1760&h=...

    Bmob 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<