[英]How to plot a scatter plot with its linear regression?
我如何使用matplotlib進行估算的行。
我有幾點,我使用以下代碼使用matplotlib進行了繪制:
import matplotlib.pyplot as plt
for smp, lbl in zip(samples, labels):
plt.scatter(smp[0], smp[1], marker='*', cl = 'b', s=100, label=lbl)
# set limit, xlabel, ylabel, legend ...
# ...
plt.show()
謝謝,
使用polyfit
進行線性回歸:
import matplotlib.pyplot as plt
from pylab import polyfit, poly1d
x, y = zip(*samples)
fit = polyfit(x, y, 1)
fit_fn = poly1d(fit)
plt.plot(x,y, '*', x, fit_fn(x), 'k')
plt.show()
結果示例:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.