Skip to content

Commit

Permalink
Adding the 2nd set of functionality and many more widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
jamartinh committed Nov 26, 2015
1 parent 0efff45 commit 94324ed
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion orangecontrib/spark/base/spark_ml_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class OWSparkEstimator(OWSparkTransformer):

def apply(self):
method_instance = self.method()
paramMap = self.build_param_map()
paramMap = self.build_param_map(method_instance)
self.out_model = method_instance.fit(self.in_df, params = paramMap)
self.send("Model", self.out_model)
10 changes: 6 additions & 4 deletions orangecontrib/spark/base/spark_ml_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,18 @@ def get_input(self, obj):
self.in_df = obj
self.refresh_method(self.gui_parameters['method'].get_value())

def build_param_map(self):
def build_param_map(self, method_instance):
paramMap = dict()
for k in self.method_parameters:
value = self.gui_parameters[k].get_usable_value()
name = self.gui_parameters[k].get_param_name(self.method.__name__, k)
paramMap[name] = value
# name = self.gui_parameters[k].get_param_name(self.method.__name__, k)
paramMap[pyspark.ml.param.Param(method_instance, k, '')] = value
print(k, value, type(value))
return paramMap

def apply(self):
method_instance = self.method()
paramMap = self.build_param_map()
paramMap = self.build_param_map(method_instance)

self.out_df = method_instance.transform(self.in_df, params = paramMap)
self.send("DataFrame", self.out_df)
13 changes: 9 additions & 4 deletions orangecontrib/spark/utils/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@ def update(self, values):

def get_usable_value(self):
val = self.get_value()
if val=='None' or val=='' or val is None:
return None
if val in ('True', 'False'):
return bool(val)

This comment has been minimized.

Copy link
@kernc

kernc Dec 1, 2015

Contributor
>>> bool('False')
True

Is this intended?

This comment has been minimized.

Copy link
@jamartinh

jamartinh via email Dec 1, 2015

Author Owner

try:
return float(val)
if float(val) == int(val):
return int(val)
else:
return float(val)
except ValueError:
return val

def get_param_name(self, parent, name):
return str(parent) + "__" + name


def create_auto_combobox(parent_widget, values, callback_func = None):
combo = QtGui.QComboBox(parent_widget)
Expand Down
32 changes: 18 additions & 14 deletions orangecontrib/spark/widgets/spark_ml_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ def __init__(self):
box = gui.widgetBox(self.controlArea, "features", addToLayout = False)
self.used_attrs = VariablesListItemModel()
self.used_attrs_view = VariablesListItemView(acceptedType = str)

self.used_attrs_view.setModel(self.used_attrs)
self.used_attrs_view.selectionModel().selectionChanged.connect(partial(self.update_interface_state, self.used_attrs_view))
box.layout().addWidget(self.used_attrs_view)
Expand Down Expand Up @@ -417,18 +416,18 @@ def set_data(self, data = None):
self.data = data
if self.data is not None:
self.in_df = self.data
self.used_attrs = VariablesListItemModel()
self.class_attrs = VariablesListItemModel()
self.meta_attrs = VariablesListItemModel()
#self.used_attrs.
#self.class_attrs = VariablesListItemModel()
#self.meta_attrs = VariablesListItemModel()
self.available_attrs.extend(sorted(self.in_df.columns))

else:
self.data = None
self.in_df = None
self.used_attrs = VariablesListItemModel()
self.class_attrs = VariablesListItemModel()
self.meta_attrs = VariablesListItemModel()
self.available_attrs = VariablesListItemModel()
#self.used_attrs = VariablesListItemModel()
#self.class_attrs = VariablesListItemModel()
#self.meta_attrs = VariablesListItemModel()
#self.available_attrs = VariablesListItemModel()

def update_domain_role_hints(self):
""" Update the domain hints to be stored in the widgets settings.
Expand Down Expand Up @@ -540,9 +539,9 @@ def update_completer_model(self, *_):
through either drag/drop or the left/right button actions.
"""
vars = list(self.available_attrs)
vars = [att for att in self.available_attrs]
items = [var for var in vars]
labels = list(vars)
labels = [label for label in vars]
items.extend(["%s" % item for item in labels])
items.extend(reduce(list.__add__, list(map(list, labels)), []))

Expand Down Expand Up @@ -570,12 +569,17 @@ def update_completer_prefix(self, filter):
def commit(self):
self.update_domain_role_hints()
if self.in_df is not None:
attributes = list(self.used_attrs)
class_var = list(self.class_attrs)
metas = list(self.meta_attrs)
print(self.used_attrs)
print(self.class_attrs)
print(self.meta_attrs)

attributes = [att for att in self.used_attrs._list]
class_var = [var for var in self.class_attrs._list]
metas = [meta for meta in self.meta_attrs._list]
VA = VectorAssembler(inputCols = attributes, outputCol = 'features')
self.out_df = VA.transform(self.in_df)
print(class_var, type(class_var))
print("class", class_var, type(class_var))
print("atributes", attributes)
if len(class_var):
self.out_df = self.out_df.withColumn('label', self.out_df[class_var[0]])

Expand Down

0 comments on commit 94324ed

Please sign in to comment.