summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2016-04-26 17:38:15 +0200
committerChristoph Helma <helma@in-silico.ch>2016-04-26 17:38:15 +0200
commitcfc64a2966ab38698e499f0b44f41208ee77a07f (patch)
tree408d4518e808a3e52a96e9e68cfe0723404dbf8b /test
parent6890687df6de0a6eaa3d35c6be66639614ea2ef2 (diff)
first nanomaterial prediction
Diffstat (limited to 'test')
-rw-r--r--test/nanoparticles.rb40
-rw-r--r--test/setup.rb4
-rw-r--r--test/validation.rb2
3 files changed, 40 insertions, 6 deletions
diff --git a/test/nanoparticles.rb b/test/nanoparticles.rb
index 46073a9..31bb903 100644
--- a/test/nanoparticles.rb
+++ b/test/nanoparticles.rb
@@ -11,9 +11,38 @@ class NanoparticleTest < MiniTest::Test
p dataset_ids.collect{|d| {d => Dataset.find(d).name}}
dataset_ids.collect do |d|
d = Dataset.find(d)
- p d.name
- puts d.to_csv
+ #p d.name
+ #puts d.to_csv
+ end
+ end
+
+ def test_summaries
+ features = Feature.all.to_a
+ #p features.collect do |f|
+ #f if f.category == "TOX"
+ #end.to_a.flatten.size
+ toxcounts = {}
+ pccounts = {}
+ Nanoparticle.all.each do |np|
+ np.toxicities.each do |t,v|
+ toxcounts[t] ||= 0
+ toxcounts[t] += 1#v.uniq.size
+ end
+ np.physchem_descriptors.each do |t,v|
+ pccounts[t] ||= 0
+ pccounts[t] += 1#v.uniq.size
+ end
end
+ #puts counts.keys.collect{|i| Feature.find(i)}.to_yaml
+ #pccounts.each{|e,n| p Feature.find(e),n if n > 100}
+ #p toxcounts.collect{|e,n| Feature.find(e).name if n > 1}.uniq
+ toxcounts.each{|e,n| p Feature.find(e),n if n > 100}
+ end
+
+
+ def test_import_ld
+ skip
+ dataset_ids = Import::Enanomapper.import_ld
end
def test_export
@@ -24,11 +53,14 @@ class NanoparticleTest < MiniTest::Test
def test_create_model
training_dataset = Dataset.find_or_create_by(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles")
- model = Model::LazarRegression.create(training_dataset, :prediction_algorithm => "OpenTox::Algorithm::Regression.local_physchem_regression", :neighbor_algorithm => "nanoparticle_neighbors")
+ feature = Feature.find_or_create_by(name: "7.99 Toxicity (other) ICP-AES", category: "TOX", unit: "mL/ug(Mg)")
+ model = Model::LazarRegression.create(feature, training_dataset, {:prediction_algorithm => "OpenTox::Algorithm::Regression.local_physchem_regression", :neighbor_algorithm => "nanoparticle_neighbors"})
nanoparticle = training_dataset.nanoparticles[-34]
+ #p nanoparticle.neighbors
prediction = model.predict nanoparticle
p prediction
- refute_nil prediction[:value]
+ #p prediction
+ #refute_nil prediction[:value]
end
end
diff --git a/test/setup.rb b/test/setup.rb
index e7c32b4..6c97282 100644
--- a/test/setup.rb
+++ b/test/setup.rb
@@ -5,5 +5,5 @@ require_relative '../lib/lazar.rb'
include OpenTox
TEST_DIR ||= File.expand_path(File.dirname(__FILE__))
DATA_DIR ||= File.join(TEST_DIR,"data")
-$mongo.database.drop
-$gridfs = $mongo.database.fs
+#$mongo.database.drop
+#$gridfs = $mongo.database.fs
diff --git a/test/validation.rb b/test/validation.rb
index baee2d1..cbc7d09 100644
--- a/test/validation.rb
+++ b/test/validation.rb
@@ -9,6 +9,7 @@ class ValidationTest < MiniTest::Test
model = Model::LazarClassification.create dataset.features.first, dataset
cv = ClassificationCrossValidation.create model
assert cv.accuracy > 0.7, "Accuracy (#{cv.accuracy}) should be larger than 0.7, this may occur due to an unfavorable training/test set split"
+ assert cv.weighted_accuracy > cv.accuracy, "Weighted accuracy (#{cv.weighted_accuracy}) should be larger than accuracy (#{cv.accuracy})."
end
def test_default_regression_crossvalidation
@@ -85,6 +86,7 @@ class ValidationTest < MiniTest::Test
assert_equal 14, loo.nr_unpredicted
refute_empty loo.confusion_matrix
assert loo.accuracy > 0.77
+ assert loo.weighted_accuracy > loo.accuracy, "Weighted accuracy (#{loo.weighted_accuracy}) should be larger than accuracy (#{loo.accuracy})."
end
def test_regression_loo_validation