Re: 請問如何計算回歸方程式

看板Python作者 (另類3k)時間5年前 (2020/06/26 01:05), 5年前編輯推噓2(201)
留言3則, 3人參與, 5年前最新討論串3/3 (看更多)
※ 引述《aredfish (一切都是假的)》之銘言: : 給定兩個相同長度的list,分別代表x與y的座標,請問我該怎麼用python去計算他的線性回歸方程式y=mx+b 呢? : ----- : Sent from JPTT on my Samsung SM-G930F. import numpy as np p1_n_order = 1 y = [3,5,7,9,11,13] x = [1,2,3,4,5,6] p1 = np.poly1d(np.polyfit(x,y,p1_n_order)) print(p1) 輸出結果為 2x+1 p2_n_order = 2 b = [5,15,29,47,69,95] a = [1,2,3,4,5,6] p2 = np.poly1d(np.polyfit(a,b,p2_n_order)) print(p2) 輸出結果為 2x^2+4x-1 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.192.83 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1593104759.A.7CE.html ※ 編輯: refusekkk (140.116.192.83 臺灣), 06/26/2020 01:08:51

06/26 17:12, 5年前 , 1F
原來np就可以直接計算了,感謝
06/26 17:12, 1F

06/27 12:13, 5年前 , 2F
06/27 12:13, 2F

07/01 08:17, 5年前 , 3F
推推
07/01 08:17, 3F
文章代碼(AID): #1UzDbtVE (Python)
討論串 (同標題文章)
文章代碼(AID): #1UzDbtVE (Python)