Rpyを使ってRに線形回帰(単なる直線回帰ですが)を
させる方法を説明しているページ


のplot部分をGnuplot.pyを使ってGnuplotで書いてみる。

from rpy import r

import Gnuplot

my_x = [5.05, 6.75, 3.21, 2.66]
my_y = [1.65, 26.5, -5.93, 7.96]
ls_fit = r.lsfit(my_x,my_y)
gradient = ls_fit['coefficients']['X']
yintercept= ls_fit['coefficients']['Intercept']

#ここから

g1 = Gnuplot.Gnuplot()
g1.plot(zip(mx_x,my_y))

# sに直線の式のTemplateを作成
s = Template('$grad * x + ($itspt)')
form1 = s.substitute(grad=gradiant,itspt=yintercept)
'5.3935773612 * x + (-16.2811279931)'

g1.plot(form1)

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2007年05月21日 22:26