eps 0.3.9 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/lib/eps/data_frame.rb +6 -3
- data/lib/eps/linear_regression.rb +5 -28
- data/lib/eps/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed82418a666490dc6683d0b1258c2dbc7451d86e9421bc5e1581a216e9b48a6f
|
4
|
+
data.tar.gz: d725f5e8f826f6e875aa06811a2d6cbf1fcbffd32073324eb43b32d6e99040eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3a8e472c998061e3a493ea2b2762a12747bac71d5544ca818bf69f50ac5e4c12cd7a2e0c5a8b767667c92238bbda54e7ef800f740210088fc982bfa84afa7a2
|
7
|
+
data.tar.gz: 2cdb0dda86b60c80a4a7fc4ad0fabafab71e57cfef8cdef349a190da4501e3105c1032b68f64c4196c99df1157da1a068d3bf6831b129b1544f925e371d924da
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Check out [this post](https://ankane.org/rails-meet-data-science) for more info
|
|
14
14
|
Add this line to your application’s Gemfile:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem
|
17
|
+
gem "eps"
|
18
18
|
```
|
19
19
|
|
20
20
|
On Mac, also install OpenMP:
|
@@ -388,7 +388,7 @@ brew install gsl
|
|
388
388
|
Then, add this line to your application’s Gemfile:
|
389
389
|
|
390
390
|
```ruby
|
391
|
-
gem
|
391
|
+
gem "gslr", group: :development
|
392
392
|
```
|
393
393
|
|
394
394
|
It only needs to be available in environments used to build the model.
|
data/lib/eps/data_frame.rb
CHANGED
@@ -85,6 +85,8 @@ module Eps
|
|
85
85
|
finish -= 1 if rows.exclude_end?
|
86
86
|
rows = Range.new(rows.begin, size - 1) if finish >= size - 1
|
87
87
|
end
|
88
|
+
elsif rows.is_a?(Integer)
|
89
|
+
rows = [rows]
|
88
90
|
end
|
89
91
|
|
90
92
|
if cols
|
@@ -118,10 +120,11 @@ module Eps
|
|
118
120
|
cols.each do |c|
|
119
121
|
raise "Undefined column: #{c}" unless columns.include?(c)
|
120
122
|
|
121
|
-
|
123
|
+
col = columns[c]
|
124
|
+
df.columns[c] = rows.map { |i| col[i] }
|
122
125
|
end
|
123
|
-
df.label =
|
124
|
-
df.weight =
|
126
|
+
df.label = rows.map { |i| label[i] } if label
|
127
|
+
df.weight = rows.map { |i| weight[i] } if weight
|
125
128
|
|
126
129
|
singular ? df.columns[cols[0]] : df
|
127
130
|
end
|
@@ -37,8 +37,7 @@ module Eps
|
|
37
37
|
str
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
def _train(**options)
|
40
|
+
def _train(intercept: true, gsl: nil)
|
42
41
|
raise "Target must be numeric" if @target_type != "numeric"
|
43
42
|
check_missing_value(@train_set)
|
44
43
|
check_missing_value(@validation_set) if @validation_set
|
@@ -51,26 +50,16 @@ module Eps
|
|
51
50
|
|
52
51
|
x = data.map_rows(&:to_a)
|
53
52
|
|
54
|
-
gsl =
|
55
|
-
if options.key?(:gsl)
|
56
|
-
options[:gsl]
|
57
|
-
elsif defined?(GSL)
|
58
|
-
true
|
59
|
-
elsif defined?(GSLR)
|
60
|
-
:gslr
|
61
|
-
else
|
62
|
-
false
|
63
|
-
end
|
53
|
+
gsl = defined?(GSLR) if gsl.nil?
|
64
54
|
|
65
|
-
|
66
|
-
if intercept && gsl != :gslr
|
55
|
+
if intercept && !gsl
|
67
56
|
data.size.times do |i|
|
68
57
|
x[i].unshift(1)
|
69
58
|
end
|
70
59
|
end
|
71
60
|
|
72
61
|
v3 =
|
73
|
-
if gsl
|
62
|
+
if gsl
|
74
63
|
model = GSLR::OLS.new(intercept: intercept)
|
75
64
|
model.fit(x, data.label, weight: data.weight)
|
76
65
|
|
@@ -79,12 +68,6 @@ module Eps
|
|
79
68
|
coefficients = model.coefficients.dup
|
80
69
|
coefficients.unshift(model.intercept) if intercept
|
81
70
|
coefficients
|
82
|
-
elsif gsl
|
83
|
-
x = GSL::Matrix.alloc(*x)
|
84
|
-
y = GSL::Vector.alloc(data.label)
|
85
|
-
w = GSL::Vector.alloc(data.weight) if data.weight
|
86
|
-
c, @covariance, _, _ = w ? GSL::MultiFit.wlinear(x, w, y) : GSL::MultiFit.linear(x, y)
|
87
|
-
c.to_a
|
88
71
|
else
|
89
72
|
x = Matrix.rows(x)
|
90
73
|
y = Matrix.column_vector(data.label)
|
@@ -195,13 +178,7 @@ module Eps
|
|
195
178
|
def p_value
|
196
179
|
@p_value ||= begin
|
197
180
|
Hash[@coefficients.map do |k, _|
|
198
|
-
tp =
|
199
|
-
if @gsl
|
200
|
-
GSL::Cdf.tdist_P(t_value[k].abs, degrees_of_freedom)
|
201
|
-
else
|
202
|
-
Eps::Statistics.tdist_p(t_value[k].abs, degrees_of_freedom)
|
203
|
-
end
|
204
|
-
|
181
|
+
tp = Eps::Statistics.tdist_p(t_value[k].abs, degrees_of_freedom)
|
205
182
|
[k, 2 * (1 - tp)]
|
206
183
|
end]
|
207
184
|
end
|
data/lib/eps/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lightgbm
|
@@ -80,14 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
80
|
requirements:
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '2.
|
83
|
+
version: '2.7'
|
84
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
|
-
rubygems_version: 3.
|
90
|
+
rubygems_version: 3.3.7
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: Machine learning for Ruby. Supports regression (linear regression) and classification
|