Skip to content

Instantly share code, notes, and snippets.

@lokeshh
Created August 14, 2016 21:37
Show Gist options
  • Select an option

  • Save lokeshh/5d42811b76b3dd506aa069614b30fb34 to your computer and use it in GitHub Desktop.

Select an option

Save lokeshh/5d42811b76b3dd506aa069614b30fb34 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 10000
df = Daru::DataFrame.new({
a: Statsample::Shorthand.rnorm(n),
b: Statsample::Shorthand.rnorm(n),
c: Statsample::Shorthand.rnorm(n),
d: Statsample::Shorthand.rnorm(n),
})
df[:y] = df.a * 3 + df.b * 5 + df.c * -2 + df.d * 2
df[:y].map! { |i| 1/(1+Math::exp(-i)) }
require 'nmatrix/lapacke'
Benchmark.bm do |x|
x.report do
Statsample::GLM.compute df, :y, :logistic, algorithm: :mle ;
end
end
# Result with NMatrix-lapacke
user system total real
2.810000 0.000000 2.810000 ( 2.810950)
# Result with Matrix
user system total real
1.180000 0.000000 1.180000 ( 1.186723)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment