Commit 28dda806 authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

Merge branch 'mapped-classifier-bugfix' into dev

parents d6fcd74f 4154207f
...@@ -4,6 +4,7 @@ from django.db.models.signals import post_save ...@@ -4,6 +4,7 @@ from django.db.models.signals import post_save
import workflows.library import workflows.library
import time import time
import random
from picklefield.fields import PickledObjectField from picklefield.fields import PickledObjectField
...@@ -215,7 +216,7 @@ class Workflow(models.Model): ...@@ -215,7 +216,7 @@ class Workflow(models.Model):
#check if we have an input #check if we have an input
input_seed = int(fi.outputs.all()[2].outer_input.value) input_seed = int(fi.outputs.all()[2].outer_input.value)
else: else:
input_seed = 0 input_seed = random.randint(0, 10**9)
# Special case when reading from a DB # Special case when reading from a DB
input_type = input_list.__class__.__name__ input_type = input_list.__class__.__name__
...@@ -236,7 +237,7 @@ class Workflow(models.Model): ...@@ -236,7 +237,7 @@ class Workflow(models.Model):
if hasattr(input_list, "get_items_ref"): if hasattr(input_list, "get_items_ref"):
import orange import orange
# Orange table on input, so we cannot do slices # Orange table on input, so we cannot do slices
indices = orange.MakeRandomIndicesCV(input_list, randseed=input_seed, folds=input_fold) indices = orange.MakeRandomIndicesCV(input_list, randseed=input_seed, folds=input_fold, stratified=orange.MakeRandomIndices.Stratified)
for i in range(input_fold): for i in range(input_fold):
output_train = input_list.select(indices, i, negate=1) output_train = input_list.select(indices, i, negate=1)
output_test = input_list.select(indices, i) output_test = input_list.select(indices, i)
...@@ -264,7 +265,6 @@ class Workflow(models.Model): ...@@ -264,7 +265,6 @@ class Workflow(models.Model):
if hasattr(input_list, "get_items_ref"): if hasattr(input_list, "get_items_ref"):
output_test = folds[i][1] output_test = folds[i][1]
output_train = folds[i][0] output_train = folds[i][0]
print len(output_train), len(output_test)
else: else:
output_train = folds[:i] + folds[i+1:] output_train = folds[:i] + folds[i+1:]
output_test = folds[i] output_test = folds[i]
...@@ -281,11 +281,9 @@ class Workflow(models.Model): ...@@ -281,11 +281,9 @@ class Workflow(models.Model):
fo.unfinish() # resets widgets, (read all widgets.finished=false) fo.unfinish() # resets widgets, (read all widgets.finished=false)
proper_output = fi.outputs.all()[0] # inner output proper_output = fi.outputs.all()[0] # inner output
proper_output.value = output_train proper_output.value = output_train
print len(output_train.orng_tables[context.target_table])
proper_output.save() proper_output.save()
proper_output = fi.outputs.all()[1] # inner output proper_output = fi.outputs.all()[1] # inner output
proper_output.value = output_test proper_output.value = output_test
print len(output_test.orng_tables[context.target_table])
proper_output.save() proper_output.save()
fi.finished=True # set the input widget as finished fi.finished=True # set the input widget as finished
fi.save() fi.save()
......
...@@ -94,15 +94,16 @@ class DBContext: ...@@ -94,15 +94,16 @@ class DBContext:
con.close() con.close()
self.orng_tables = None self.orng_tables = None
if in_memory: self.in_memory = in_memory
self.orng_tables = self.read_into_orange()
def read_into_orange(self): def read_into_orange(self):
conv = converters.Orange_Converter(self) conv = converters.Orange_Converter(self)
tables = { tables = {
self.target_table: conv.target_Orange_table() self.target_table: conv.target_Orange_table()
} }
tables.update(zip(self.tables[1:], conv.other_Orange_tables())) other_tbl_names = [table for table in self.tables if table != self.target_table]
other_tables = dict(zip(other_tbl_names, conv.other_Orange_tables()))
tables.update(other_tables)
return tables return tables
def update(self, postdata): def update(self, postdata):
...@@ -128,6 +129,8 @@ class DBContext: ...@@ -128,6 +129,8 @@ class DBContext:
self.cols[table] = postdata.get('%s_columns%s' % (table, widget_id), []) self.cols[table] = postdata.get('%s_columns%s' % (table, widget_id), [])
if table == self.target_table and self.target_att not in self.cols[table]: if table == self.target_table and self.target_att not in self.cols[table]:
raise Exception('The selected target attribute ("%s") is not among the columns selected for the target table ("%s").' % (self.target_att, self.target_table)) raise Exception('The selected target attribute ("%s") is not among the columns selected for the target table ("%s").' % (self.target_att, self.target_table))
if self.in_memory:
self.orng_tables = self.read_into_orange()
def fmt_cols(self, cols): def fmt_cols(self, cols):
return ','.join(["`%s`" % col for col in cols]) return ','.join(["`%s`" % col for col in cols])
......
...@@ -228,11 +228,10 @@ class Orange_Converter(Converter): ...@@ -228,11 +228,10 @@ class Orange_Converter(Converter):
def target_Orange_table(self): def target_Orange_table(self):
table, cls_att = self.db.target_table, self.db.target_att table, cls_att = self.db.target_table, self.db.target_att
return self.convert_table(table, cls_att) return self.convert_table(table, cls_att=cls_att)
def other_Orange_tables(self): def other_Orange_tables(self):
target_table = self.db.target_table target_table = self.db.target_table
return[ self.convert_table(table,None) for table in self.db.tables if table!=target_table] return[ self.convert_table(table,None) for table in self.db.tables if table!=target_table]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment