Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// g100pon #50 回帰分析
// y = intercept + slope * x
// see: http://commons.apache.org/math/userguide/stat.html
@Grab(group='commons-math', module='commons-math', version='1.2')
import org.apache.commons.math.stat.regression.SimpleRegression
def reg = new SimpleRegression()
// データを1点づつ追加するパターン
reg.addData(1,2)
reg.addData(3,3)
reg.addData(3,3)
println "切片=${reg.intercept}"
println "傾き=${reg.slope}"
println "傾きの誤差=${reg.slopeStdErr}"
reg.clear()
// データをdouble[][]でまとめて追加するパターン
def data = [[ 1, 3], [2, 5], [3, 7], [4, 14], [5, 11]] as double[][]
reg.addData(data)
println "切片=${reg.intercept}"
println "傾き=${reg.slope}"
println "傾きの誤差=${reg.slopeStdErr}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment