rbbt-dm 1.1.45 → 1.1.46

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
- SHA1:
3
- metadata.gz: 3d0fe8cd4d9acfbef39eab9bb2cc6537dc4846b8
4
- data.tar.gz: 0f373711bbd5c67c072012570b67301336082df3
2
+ SHA256:
3
+ metadata.gz: 5f70d6a55c5852ffdafd59a3199b41031ee5a5aaa4becc56ee2f7f49be3b5d43
4
+ data.tar.gz: f5d53ca95b6af4d6c2b63f00bbbfd398e3fa5a6feea15885b00ccd946f3aa765
5
5
  SHA512:
6
- metadata.gz: 03f79f5464f66d147ca1e86fa30a86d911dc84e6a2766e13c7a04be1141405e9f46e545e76f04283a765b168c79b37ecde140bee096c9ce85604ada8cd5176db
7
- data.tar.gz: 5e3aea0ec0e1c5683ac177e830883c4987dedd524353e14124148edc3c87181374a20a09c7b41c37c1bdb68e89efe0708fb532d3bc90f1403b4eb61bec8c87f4
6
+ metadata.gz: 7cd9928cd7a3e7558e27796f0e8f4c7635caa2331dc3f2d2d904434d9feedf6e3d2085ba301b55c61b87bdee83fbc588c666a99c0d0cc0d5414d1614a964a0a5
7
+ data.tar.gz: f559bff1acc000be594ad8e91534a4af24acad3ebf80c276b8055af582a91e5137c748acf55267c8001b0c667cc1c6a167ca86a11b34da52ebb796ba8fdd01fe
@@ -0,0 +1,7 @@
1
+ class MLTask
2
+ def initialize
3
+ end
4
+
5
+ def pre_process
6
+ end
7
+ end
@@ -9,7 +9,7 @@ class SVMModel < VectorModel
9
9
 
10
10
  @train_model =<<-EOF
11
11
  library(e1071);
12
- model = svm(class ~ ., data = features);
12
+ model = svm(class ~ ., data = features, scale=c(0));
13
13
  EOF
14
14
 
15
15
  @eval_model =<<-EOF
@@ -57,6 +57,11 @@ cat(paste(label, sep="\\n"));
57
57
  @labels = []
58
58
  end
59
59
 
60
+ def clear
61
+ @features = []
62
+ @labels = []
63
+ end
64
+
60
65
  def add(element, label = nil)
61
66
  @features << extract_features.call(element)
62
67
  @labels << label unless label.nil?
@@ -119,4 +124,53 @@ cat(paste(label, sep="\\n"));
119
124
 
120
125
  acc
121
126
  end
127
+
128
+ def cross_validation(folds = 10)
129
+
130
+ res = TSV.setup({}, "Fold~TP,TN,FP,FN,P,R,F1#:type=:list")
131
+
132
+ feature_folds = Misc.divide(@features, folds)
133
+ labels_folds = Misc.divide(@labels, folds)
134
+
135
+ folds.times do |fix|
136
+
137
+ test_set = feature_folds[fix]
138
+ train_set = feature_folds.values_at(*((0..9).to_a - [fix])).inject([]){|acc,e| acc += e; acc}
139
+
140
+ test_labels = labels_folds[fix]
141
+ train_labels = labels_folds.values_at(*((0..9).to_a - [fix])).flatten
142
+
143
+ tp, fp, tn, fn, pr, re, f1 = [0, 0, 0, 0, nil, nil, nil]
144
+
145
+ @features = train_set
146
+ @labels = train_labels
147
+ self.train
148
+ predictions = self.eval_list test_set, false
149
+
150
+ test_labels.zip(predictions).each do |gs,pred|
151
+ gs = gs.to_i
152
+ pred = pred > 0.5 ? 1 : 0
153
+ tp += 1 if gs == pred && gs == 1
154
+ tn += 1 if gs == pred && gs == 0
155
+ fp += 1 if gs == 0 && pred == 1
156
+ fn += 1 if gs == 1 && pred == 0
157
+ end
158
+
159
+ p = tp + fn
160
+ pp = tp + fp
161
+
162
+ pr = tp.to_f / pp
163
+ re = tp.to_f / p
164
+
165
+ f1 = (2.0 * tp) / (2.0 * tp + fp + fn)
166
+
167
+ Misc.fingerprint([tp,tn,fp,fn,pr,re,f1])
168
+
169
+ Log.debug "CV Fold #{fix} P:#{"%.3f" % pr} R:#{"%.3f" % re} F1:#{"%.3f" % f1}"
170
+
171
+ res[fix] = [tp,tn,fp,fn,pr,re,f1]
172
+ end
173
+
174
+ res
175
+ end
122
176
  end
@@ -0,0 +1,12 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'test_helper.rb')
2
+ require 'rbbt/ml_task'
3
+
4
+ class TestMLTask < Test::Unit::TestCase
5
+ def test_MLTask
6
+
7
+ triage = MLTask.new
8
+ ml_task.pre_process do
9
+ end
10
+ end
11
+ end
12
+
@@ -34,7 +34,7 @@ class TestVectorModel < Test::Unit::TestCase
34
34
  features = read.table("#{ feature_file }", sep ="\\t", stringsAsFactors=FALSE);
35
35
  labels = scan("#{ feature_file }.class", what=numeric());
36
36
  features = cbind(features, class = labels);
37
- library(e1071)
37
+ rbbt.require('e1071')
38
38
  model = svm(class ~ ., data = features)
39
39
  save(model, file="#{ model_file }");
40
40
  EOF
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-dm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.45
4
+ version: 1.1.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-24 00:00:00.000000000 Z
11
+ date: 2020-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbbt-util
@@ -95,6 +95,7 @@ files:
95
95
  - lib/rbbt/matrix/barcode.rb
96
96
  - lib/rbbt/matrix/differential.rb
97
97
  - lib/rbbt/matrix/knowledge_base.rb
98
+ - lib/rbbt/ml_task.rb
98
99
  - lib/rbbt/network/paths.rb
99
100
  - lib/rbbt/plots/bar.rb
100
101
  - lib/rbbt/plots/heatmap.rb
@@ -115,6 +116,7 @@ files:
115
116
  - test/rbbt/statistics/test_fisher.rb
116
117
  - test/rbbt/statistics/test_hypergeometric.rb
117
118
  - test/rbbt/statistics/test_random_walk.rb
119
+ - test/rbbt/test_ml_task.rb
118
120
  - test/rbbt/test_stan.rb
119
121
  - test/rbbt/vector/model/test_svm.rb
120
122
  - test/rbbt/vector/test_model.rb
@@ -137,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
139
  - !ruby/object:Gem::Version
138
140
  version: '0'
139
141
  requirements: []
140
- rubyforge_project:
141
- rubygems_version: 2.6.13
142
+ rubygems_version: 3.0.6
142
143
  signing_key:
143
144
  specification_version: 4
144
145
  summary: Data-mining and statistics
@@ -149,6 +150,7 @@ test_files:
149
150
  - test/rbbt/statistics/test_fisher.rb
150
151
  - test/rbbt/statistics/test_fdr.rb
151
152
  - test/rbbt/statistics/test_hypergeometric.rb
153
+ - test/rbbt/test_ml_task.rb
152
154
  - test/rbbt/vector/test_model.rb
153
155
  - test/rbbt/vector/model/test_svm.rb
154
156
  - test/rbbt/test_stan.rb