eps 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf9b15abb922ed62bace8127413e9353d37364f7fe63218088278420655a2561
4
- data.tar.gz: 9ae7077f18295a24daf682777106807eec96dfa75e6e4a9f6b595cb52981aec5
3
+ metadata.gz: ed82418a666490dc6683d0b1258c2dbc7451d86e9421bc5e1581a216e9b48a6f
4
+ data.tar.gz: d725f5e8f826f6e875aa06811a2d6cbf1fcbffd32073324eb43b32d6e99040eb
5
5
  SHA512:
6
- metadata.gz: d37cec29c949a729f9581532902b595f4fca1817054243e7e6261b5167917144ba988bbea5fe2a069ef4b988f91fa2b5fd0ea5628059c328b4575d374eb952d7
7
- data.tar.gz: 667afb1f383c0d2a8c45c281b7a2b88cc76c3b691704853feb03a8be5a95bfa3ba155ba3e82278c5993b638185c80a82fbbe852f5704ab6bed896af667dd3b76
6
+ metadata.gz: e3a8e472c998061e3a493ea2b2762a12747bac71d5544ca818bf69f50ac5e4c12cd7a2e0c5a8b767667c92238bbda54e7ef800f740210088fc982bfa84afa7a2
7
+ data.tar.gz: 2cdb0dda86b60c80a4a7fc4ad0fabafab71e57cfef8cdef349a190da4501e3105c1032b68f64c4196c99df1157da1a068d3bf6831b129b1544f925e371d924da
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.4.0 (2022-09-02)
2
+
3
+ - Fixed `stack level too deep` error with many rows
4
+ - Dropped support for `gsl` gem (use `gslr` instead)
5
+ - Dropped support for Ruby < 2.7
6
+
7
+ ## 0.3.9 (2021-10-14)
8
+
9
+ - Fixed error with `lessOrEqual` operator
10
+
11
+ ## 0.3.8 (2021-02-08)
12
+
13
+ - Fixed error with categorical and text features
14
+
1
15
  ## 0.3.7 (2020-11-23)
2
16
 
3
17
  - Fixed error with LightGBM summary
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-2019 Andrew Kane
3
+ Copyright (c) 2018-2021 Andrew Kane
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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 'eps'
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 'gslr', group: :development
391
+ gem "gslr", group: :development
392
392
  ```
393
393
 
394
394
  It only needs to be available in environments used to build the model.
@@ -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
- df.columns[c] = columns[c].values_at(*rows)
123
+ col = columns[c]
124
+ df.columns[c] = rows.map { |i| col[i] }
122
125
  end
123
- df.label = label.values_at(*rows) if label
124
- df.weight = weight.values_at(*rows) if 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
data/lib/eps/lightgbm.rb CHANGED
@@ -71,7 +71,7 @@ module Eps
71
71
  end
72
72
 
73
73
  # create datasets
74
- categorical_idx = @features.values.map.with_index.select { |type, _| type == "categorical" }.map(&:last)
74
+ categorical_idx = train_set.columns.keys.map.with_index.select { |k, _| @features[k] == "categorical" }.map(&:last)
75
75
  train_ds = ::LightGBM::Dataset.new(train_set.map_rows(&:to_a), label: train_set.label, weight: train_set.weight, categorical_feature: categorical_idx, params: params)
76
76
  validation_ds = ::LightGBM::Dataset.new(validation_set.map_rows(&:to_a), label: validation_set.label, weight: validation_set.weight, categorical_feature: categorical_idx, params: params, reference: train_ds) if validation_set
77
77
 
@@ -37,8 +37,7 @@ module Eps
37
37
  str
38
38
  end
39
39
 
40
- # TODO use keyword arguments for gsl and intercept in 0.4.0
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
- intercept = options.key?(:intercept) ? options[:intercept] : true
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 == :gslr
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
@@ -222,7 +222,7 @@ module Eps
222
222
  else
223
223
  operator = xml_predicate.attribute("operator").value
224
224
  value = xml_predicate.attribute("value").value
225
- value = value.to_f if operator == "greaterThan"
225
+ value = value.to_f if operator == "greaterThan" || operator == "lessOrEqual"
226
226
  field = xml_predicate.attribute("field").value
227
227
  field = derived_fields[field] if derived_fields[field]
228
228
  {
data/lib/eps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eps
2
- VERSION = "0.3.7"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.7
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: 2020-11-24 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lightgbm
@@ -38,92 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: daru
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: numo-narray
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rake
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rover-df
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
41
  description:
126
- email: andrew@chartkick.com
42
+ email: andrew@ankane.org
127
43
  executables: []
128
44
  extensions: []
129
45
  extra_rdoc_files: []
@@ -164,14 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
80
  requirements:
165
81
  - - ">="
166
82
  - !ruby/object:Gem::Version
167
- version: '2.4'
83
+ version: '2.7'
168
84
  required_rubygems_version: !ruby/object:Gem::Requirement
169
85
  requirements:
170
86
  - - ">="
171
87
  - !ruby/object:Gem::Version
172
88
  version: '0'
173
89
  requirements: []
174
- rubygems_version: 3.1.4
90
+ rubygems_version: 3.3.7
175
91
  signing_key:
176
92
  specification_version: 4
177
93
  summary: Machine learning for Ruby. Supports regression (linear regression) and classification