Skip to content

Instantly share code, notes, and snippets.

View lokeshh's full-sized avatar
🌴
On vacation

Lokesh Sharma lokeshh

🌴
On vacation
View GitHub Profile
[1] pry(main)> dv = Daru::Vector.new ['third', 'third', 'first', 'second'], type: :category
=> #<Daru::Vector(4)>
0 third
1 third
2 first
3 second
[2] pry(main)> dv.order
=> ["third", "first", "second"]
[3] pry(main)> dv.order = ['first', 'second', 'thrd']
ArgumentError: The contents of new and old order must be the same.
lokeshh:~/workspace/daru_rails (master) $ rails console
Running via Spring preloader in process 3882
Loading development environment (Rails 4.2.6)
2.3.0 :001 > Nyaplot::Plot.new
NameError: uninitialized constant Layers
from /usr/local/rvm/gems/ruby-2.3.0/bundler/gems/nyaplot-06083fa83b2d/lib/nyaplot/plot.rb:50:in `initialize'
from (irb):1:in `new'
from (irb):1
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
require 'daru'
require 'memory_profiler'
report = MemoryProfiler.report do
@a = ['a'*1000]*1000
end
report.pretty_print
# Total allocated: 9161 bytes (4 objects)
# Total retained: 9081 bytes (2 objects)
y a b c d e
0 6 62.1 no male A
1 18 74.7 yes female B
1 16 69.7 no female A
0 14 71 no male C
1 5 56.9 no male B
0 11 58.7 no female B
0 8 63.3 no male B
1 11 70.4 no male A
1 15 70.5 no male C
> model = glm(y ~ a + e + c:d + e:d, data=data, family='binomial')
> summary(model)
Call:
glm(formula = y ~ a + e + c:d + e:d, family = "binomial", data = data)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.4049 -0.7803 -0.1191 0.9512 1.6154
[16] pry(main)> k
=> #<Daru::DataFrame(14x4)>
b c_no c_yes y
0 62.1 1 0 0
1 74.7 0 1 1
2 69.7 1 0 1
3 71 1 0 0
4 56.9 1 0 1
5 58.7 1 0 0
6 63.3 1 0 0
> try = Daru::DataFrame.from_csv 'try.csv'
> Statsample::GLM.compute try, 'y', :logistic
ExceptionForMatrix::ErrNotRegular: Not Regular Matrix
from /home/ubuntu/.rvm/gems/ruby-2.2.3/gems/backports-3.6.8/lib/backports/1.9.2/stdlib/matrix.rb:933:in `block in inverse_from'
[1] pry(main)> ds = Daru::DataFrame.new({
[1] pry(main)* a: [1.2, 2.3, 3.1],
[1] pry(main)* b: [4.20, 5.6, 1.1],
[1] pry(main)* c: [1.1, 2.2, 6.6]})
=> #<Daru::DataFrame(3x3)>
a b c
0 1.2 4.2 1.1
1 2.3 5.6 2.2
2 3.1 1.1 6.6
[2] pry(main)> x = Statsample::Regression.multiple ds, :c
Failures:
1) Daru::DataFrame#summary produces a summary of data frame
Failure/Error:
tuple.flatten.each_with_index
.all? { |tup, i| @levels[i][tup] }
NoMethodError:
undefined method `flatten' for :report_building_text:Symbol
# ./lib/daru/index.rb:501:in `include?'
require 'statsample'
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),
})