1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
module OpenTox
module Validation
class TrainTest < Validation
field :training_dataset_id, type: BSON::ObjectId
field :test_dataset_id, type: BSON::ObjectId
def self.create model, training_set, test_set
atts = model.attributes.dup # do not modify attributes of the original model
atts["_id"] = BSON::ObjectId.new
atts[:training_dataset_id] = training_set.id
validation_model = model.class.create model.prediction_feature, training_set, atts
validation_model.save
predictions = validation_model.predict test_set.substances
nr_unpredicted = 0
predictions.each do |cid,prediction|
if prediction[:value]
prediction[:measurements] = test_set.values(cid, prediction[:prediction_feature_id])
else
nr_unpredicted += 1
end
end
predictions.select!{|cid,p| p[:value] and p[:measurements]}
validation = self.new(
:model_id => validation_model.id,
:test_dataset_id => test_set.id,
:nr_instances => test_set.substances.size,
:nr_unpredicted => nr_unpredicted,
:predictions => predictions
)
validation.save
validation
end
def test_dataset
Dataset.find test_dataset_id
end
def training_dataset
Dataset.find training_dataset_id
end
end
class ClassificationTrainTest < TrainTest
include ClassificationStatistics
end
class RegressionTrainTest < TrainTest
include RegressionStatistics
end
end
end
|