Commit 46a455c9 authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

added select subgroups widget

parent 94122987
...@@ -233,3 +233,7 @@ html[xmlns] .dataTables_wrapper { ...@@ -233,3 +233,7 @@ html[xmlns] .dataTables_wrapper {
.dataTables_filter input { .dataTables_filter input {
margin-bottom: 5px; margin-bottom: 5px;
} }
.selected_subgroup {
font-weight: bold;
font-size: 30pt;
}
\ No newline at end of file
...@@ -22,22 +22,18 @@ def build_subgroups(request, input_dict, output_dict, widget): ...@@ -22,22 +22,18 @@ def build_subgroups(request, input_dict, output_dict, widget):
'className' : className, 'className' : className,
'classValues' : classValues}) 'classValues' : classValues})
def subgroup_bar_visualization(request, input_dict, output_dict, widget): def select_subgroups(request, input_dict, output_dict, widget):
''' '''
Subgroup bar visualization. Subgroup selection.
@author: Anze Vavpetic, 2012 @author: Anze Vavpetic, 2012
''' '''
sd_rules = input_dict['rules'] sd_rules = input_dict['rules']
rules = sd_rules.rules rules = sd_rules.rules
P, N = float(len(sd_rules.targetClassRule.TP)), float(len(sd_rules.targetClassRule.FP)) P, N = float(len(sd_rules.targetClassRule.TP)), float(len(sd_rules.targetClassRule.FP))
fpr = [-len(rule.FP)/N for rule in rules] subgroups = [(rule.id, rule.ruleToString(), len(rule.FP), len(rule.TP)) for rule in rules]
tpr = [len(rule.TP)/P for rule in rules] return render(request, 'interactions/select_subgroups.html', {
subgroups = [rule.ruleToString() for rule in rules]
return render(request, 'visualizations/subgroup_bar_visualization.html', {
'widget' : widget, 'widget' : widget,
'model_name' : sd_rules.algorithmName, 'model_name' : sd_rules.algorithmName,
'fpr' : json.dumps(fpr), 'subgroups' : subgroups
'tpr' : json.dumps(tpr),
'subgroups' : json.dumps(subgroups)
}) })
\ No newline at end of file
...@@ -3,7 +3,9 @@ Subgroup discovery library functions. ...@@ -3,7 +3,9 @@ Subgroup discovery library functions.
@author: Anze Vavpetic <anze.vavpetic@ijs.si> @author: Anze Vavpetic <anze.vavpetic@ijs.si>
''' '''
import json
from SubgroupDiscovery.SD_learner_classifier import SD_learner from SubgroupDiscovery.SD_learner_classifier import SD_learner
from SubgroupDiscovery.SDRule import SDRules
class SubgroupDiscovery: class SubgroupDiscovery:
# Available algorithms and their parameters # Available algorithms and their parameters
...@@ -47,14 +49,23 @@ def build_subgroups_finished(postdata, input_dict, output_dict): ...@@ -47,14 +49,23 @@ def build_subgroups_finished(postdata, input_dict, output_dict):
params[param] = SubgroupDiscovery.parameter_types[param](value) params[param] = SubgroupDiscovery.parameter_types[param](value)
learner = SD_learner(**params) learner = SD_learner(**params)
classifier = learner(data) classifier = learner(data)
return {'rules' : classifier.getRules(classValue), 'classifier' : learner} rules = classifier.getRules(classValue)
# add id's
for i, rule in enumerate(rules.rules):
rule.id = i
return {'rules' : rules, 'classifier' : learner}
def subgroup_bar_visualization(input_dict): def subgroup_bar_visualization(input_dict):
return {'rules' : None} return {'rules' : None}
def subgroup_bar_finished(postdata, input_dict, output_dict):
# Todo
return None
def subgroup_roc_visualization(input_dict): def subgroup_roc_visualization(input_dict):
return {'rules' : []} return {'rules' : []}
\ No newline at end of file
def select_subgroups(input_dict):
return {'sel_rules' : []}
def select_subgroups_finished(postdata, input_dict, output_dict):
sd_rules = input_dict['rules']
selected_subgroups = [int(i) for i in json.loads(postdata['selected_subgroup_ids'][0])]
rules = SDRules(filter(lambda r: r.id in selected_subgroups, sd_rules.rules), sd_rules.targetClassRule, sd_rules.algorithmName)
return {'sel_rules' : rules}
\ No newline at end of file
...@@ -26,4 +26,25 @@ def subgroup_roc_visualization(request, input_dict, output_dict, widget): ...@@ -26,4 +26,25 @@ def subgroup_roc_visualization(request, input_dict, output_dict, widget):
return render(request, 'visualizations/subgroup_roc_visualization.html', { return render(request, 'visualizations/subgroup_roc_visualization.html', {
'widget' : widget, 'widget' : widget,
'roc_data' : json.dumps(roc_data), 'roc_data' : json.dumps(roc_data),
})
def subgroup_bar_visualization(request, input_dict, output_dict, widget):
'''
Subgroup bar visualization.
@author: Anze Vavpetic, 2012
'''
sd_rules = input_dict['rules']
rules = sd_rules.rules
P, N = float(len(sd_rules.targetClassRule.TP)), float(len(sd_rules.targetClassRule.FP))
fpr = [-len(rule.FP)/N for rule in rules]
tpr = [len(rule.TP)/P for rule in rules]
subgroups = [rule.ruleToString() for rule in rules]
return render(request, 'visualizations/subgroup_bar_visualization.html', {
'widget' : widget,
'model_name' : sd_rules.algorithmName,
'fpr' : json.dumps(fpr),
'tpr' : json.dumps(tpr),
'subgroups' : json.dumps(subgroups),
'rules' : [(i, descr) for i, descr in enumerate(subgroups)]
}) })
\ No newline at end of file
<div id="widgetinteract-{{widget.pk}}" rel="{{widget.pk}}" class="widgetinteractdialog" title="{{widget.name}} interaction" width="700px" height="670px">
<div style="width:620px; margin: 0 auto;">
<form>
Model: {{model_name}}<br/>
Select one or more subgroups to output:
<ol id="selected_subgroups{{widget.pk}}">
{% for id, descr, fp, tp in subgroups %}
<li class="ui-widget-content" id="{{id}}">{{ descr }} FP={{fp}}, TP={{tp}}</li>
{% endfor %}
</ol>
<input type="hidden" name="selected_subgroup_ids" id="selected_subgroup_ids" value=""/>
<input type="hidden" name="widget_id" value="{{widget.pk}}"/>
</form>
<style>
#selected_subgroups{{widget.pk}} .ui-selecting { background: #FECA40; }
#selected_subgroups{{widget.pk}} .ui-selected { background: #F39814; color: white; }
#selected_subgroups{{widget.pk}} { list-style-type: none; margin: 0; padding: 0; width: 100%; }
#selected_subgroups{{widget.pk}} li { margin: 3px; padding: 0.4em; font-size: 1.2em; }
</style>
<script type="text/javascript">
$(function () {
// Empty list on load
$('#selected_subgroup_ids').val(JSON.stringify([]));
$("#selected_subgroups{{widget.pk}}").selectable({filter : "li"}, {
stop: function() {
var selected = [];
$('.ui-selected', this).each(function(){
selected.push($(this).attr("id"));
});
$('#selected_subgroup_ids').val(JSON.stringify(selected));
}
}
);
$('#selected_subgroups{{widget.pk}}').selectable().on('mousedown', '*', function(e){
if (e.ctrlKey)
e.metaKey = e.ctrlKey;
});
});
</script>
</div>
</div>
\ No newline at end of file
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
$(document).ready(function(){ $(document).ready(function(){
plot(); plot();
}); });
// Plots for the selected attribute. // Plots for the selected attribute.
function plot() { function plot() {
// Weights barchart // Weights barchart
......
Markdown is supported
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