Skip to content

Commit d47e6e1

Browse files
committed
Improved performance of tests
1 parent 363de62 commit d47e6e1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

test/classifier_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def test_early_stopping
5858
def test_missing_numeric
5959
x_train, y_train, x_test, _ = multiclass_data
6060

61+
x_train = x_train.map(&:dup)
62+
x_test = x_test.map(&:dup)
6163
[x_train, x_test].each do |xt|
6264
xt.each do |x|
6365
x.size.times do |i|
@@ -80,6 +82,8 @@ def test_missing_numeric
8082
def test_missing_categorical
8183
x_train, y_train, x_test, _ = multiclass_data
8284

85+
x_train = x_train.map(&:dup)
86+
x_test = x_test.map(&:dup)
8387
[x_train, x_test].each do |xt|
8488
xt.each do |x|
8589
x[3] = nil if x[3] > 7

test/test_helper.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def regression_test
2929

3030
def binary_data
3131
x, y = load_data
32-
y.map! { |v| v > 1 ? 1 : v }
32+
y = y.map { |v| v > 1 ? 1 : v }
3333
split_data(x, y)
3434
end
3535

@@ -62,12 +62,15 @@ def data_path
6262
end
6363

6464
def load_data
65-
x = []
66-
CSV.foreach(data_path, headers: true, converters: :numeric) do |row|
67-
x << row.to_h.values
65+
@@load_data ||= begin
66+
x = []
67+
y = []
68+
CSV.foreach(data_path, headers: true, converters: :numeric) do |row|
69+
x << row.values_at("x0", "x1", "x2", "x3").freeze
70+
y << row["y"]
71+
end
72+
[x.freeze, y.freeze]
6873
end
69-
y = x.map(&:pop)
70-
[x, y]
7174
end
7275

7376
def split_data(x, y)

0 commit comments

Comments
 (0)