Commit 29db77ce authored by Anze Vavpetic's avatar Anze Vavpetic

Added subgroup builder widget. Added sublime project files to .gitignore.

parent 04145ed5
......@@ -12,6 +12,7 @@
.project
.settings
atlassian-ide-plugin.xml
*.sublime-*
# Project
/mothra/local_settings.py
......
......@@ -4,16 +4,20 @@ Subgroup discovery interaction views.
@author: Anze Vavpetic <anze.vavpetic@ijs.si>
'''
from django.shortcuts import render
import json
from library import SubgroupDiscovery
def build_subgroups(request, input_dict, output_dict, widget):
data = input_dict['data']
# Algorithms and the needed parameters
algorithms = {
'SD' : ['min_sup', 'g', 'beam', 'num_of_sg'],
'SD-Preprocess' : ['min_sup', 'g', 'beam', 'num_of_sg'],
'Apriori-SD' : ['min_sup', 'min_conf', 'k', 'num_of_sg'],
'CN2-SD' : ['k', 'num_of_sg']
}
className = data.domain.class_var.name
classValues = data.domain.class_var.values
return render(request, 'interactions/build_subgroups.html', {'algorithms' : algorithms, 'className' : className, 'classValues' : classValues})
\ No newline at end of file
return render(request, 'interactions/build_subgroups.html',
{'widget':widget,
'algorithms' : SubgroupDiscovery.algorithms.keys(),
'parameters_info' : SubgroupDiscovery.parameter_info,
'all_parameters' : json.dumps(SubgroupDiscovery.parameter_info.keys()),
'settings' : json.dumps(SubgroupDiscovery.algorithms),
'className' : className,
'classValues' : classValues})
\ No newline at end of file
......@@ -3,9 +3,49 @@ Subgroup discovery library functions.
@author: Anze Vavpetic <anze.vavpetic@ijs.si>
'''
from SubgroupDiscovery.SD_learner_classifier import SD_learner
class SubgroupDiscovery:
# Available algorithms and their parameters
algorithms = {
'SD' : ['minSupport', 'g', 'beamWidth', 'max_rules'],
'SD-Preprocess' : ['minSupport', 'g', 'beamWidth', 'max_rules'],
'Apriori-SD' : ['minSupport', 'minConfidence', 'k', 'max_rules'],
'CN2-SD' : ['k', 'max_rules']
}
# Parameter default values and descriptions
parameter_info = {
'minSupport' : (0.1, 'Minimum support'),
'minConfidence' : (0.7, 'Minimum confidence'),
'g' : (1.0, 'Generalization parameter'),
'beamWidth' : (5, 'Beam width'),
'k' : (4, 'Number of times covered before removed'),
'max_rules' : (0, 'Maximum number of subgroups (0=no limitation)')
}
# Parameter data types
parameter_types = {
'minSupport' : float,
'minConfidence' : float,
'g' : float,
'beamWidth' : int,
'k' : int,
'max_rules' : int,
}
def build_subgroups(input_dict):
return input_dict
return {'rules' : None}
def build_subgroups_finished(input_dict):
# TODO
return {'rules' : None}
\ No newline at end of file
def build_subgroups_finished(postdata, input_dict, output_dict):
data = input_dict['data']
widget_id = postdata['widget_id'][0]
alg = postdata['algorithm'+widget_id][0]
params = {'name' : alg, 'algorithm' : alg}
for param in SubgroupDiscovery.algorithms[alg]:
value = postdata[param+widget_id][0]
if value != '':
params[param] = SubgroupDiscovery.parameter_types[param](value)
rules = SD_learner(**params)
return {'rules' : rules}
def subgroup_visualization(input_dict):
return input_dict
......@@ -4,3 +4,12 @@ Subgroup discovery visualization views.
@author: Anze Vavpetic <anze.vavpetic@ijs.si>
'''
from django.shortcuts import render
def subgroup_visualization(request, input_dict, output_dict, widget):
'''
Subgroup visualizations.
@author: Anze Vavpeltic, 2012
'''
return render(request, 'visualizations/subgroup_visualization.html', {})
\ No newline at end of file
<div id="widgetinteract-{{widget.pk}}" rel="{{widget.pk}}" class="widgetinteractdialog" title="{{widget.name}} wants your input!">
<form id="interactionform-{{widget.pk}}" name="interactionform-{{widget.pk}}">
<select id="algorithm{{widget.pk}}">
{% for alg, params in algorithms.items %}
<option value="{{alg}}">alg</option>
{% endfor %}
</select>
<label for="min_sup{{widget.pk}}">Minimum support [%]</label><input type="number" id="min_sup{{widget.pk}}" name="min_sup{{widget.pk}}"/>
<label for="g{{widget.pk}}">Generalization parameter</label><input type="number" id="g{{widget.pk}}" name="g{{widget.pk}}"/>
<label for="beam{{widget.pk}}">Beam width</label><input type="number" id="beam{{widget.pk}}" name="beam{{widget.pk}}"/>
<label for="min_conf{{widget.pk}}">Minimum confidence [%]</label><input type="number" id="min_conf{{widget.pk}}" name="min_conf{{widget.pk}}"/>
<label for="k{{widget.pk}}">Number of times covered before removed</label><input type="number" id="k{{widget.pk}}" name="k{{widget.pk}}"/>
<label for="num_of_sg{{widget.pk}}">Maximum number of subgroups (0=no limitation)</label><input type="number" id="num_of_sg{{widget.pk}}" name="num_of_sg{{widget.pk}}"/>
<input type="hidden" name="widget_id" value="{{widget.pk}}">
<div id="widgetinteract-{{widget.pk}}" rel="{{widget.pk}}" class="widgetinteractdialog" title="{{widget.name}} interaction" width="700" height="500">
<form>
<label for="algorithm{{widget.pk}}">Algorithm</label>
<select id="algorithm{{widget.pk}}" name="algorithm{{widget.pk}}">
{% for alg in algorithms %}
<option value="{{alg}}" {% if forloop.first %}selected="selected"{% endif %}>{{alg}}</option>
{% endfor %}
</select>
{% for param, info in parameters_info.items %}
<label for="{{param}}{{widget.pk}}">{{info.1}}</label><input type="number" id="{{param}}{{widget.pk}}" name="{{param}}{{widget.pk}}" value="{{info.0}}"/>
{% endfor %}
<input type="hidden" name="widget_id" value="{{widget.pk}}">
<label for="class{{widget.pk}}">Class</label>
<select id="class{{widget.pk}}">
{% for class in classValues %}
<option value="{{class}}">{{class}}</option>
{% endfor %}
</select>
</form>
<script type="textt/javascript">
$('#algorithm{{widget.pk}}').change(function () {
var selection = $(this).val();
console.log(selection);
});
<script type="text/javascript">
var all_parameters = {{all_parameters|safe}};
var settings = {{settings|safe}};
function toggle_params(alg) {
// Go through all parameters and appropriately disable/enable
parameters = settings[alg];
for (i in all_parameters) {
if (parameters.indexOf(all_parameters[i]) != -1) {
$('#' + all_parameters[i] + '{{widget.pk}}').show();
$('label[for=' + all_parameters[i] + '{{widget.pk}}]').show();
} else {
$('#' + all_parameters[i] + '{{widget.pk}}').hide();
$('label[for=' + all_parameters[i] + '{{widget.pk}}]').hide();
}
}
}
// Toggle for default selection
toggle_params($('select#algorithm{{widget.pk}} > option:selected').val());
$('#algorithm{{widget.pk}}').change(function () {
var alg = $(this).val();
toggle_params(alg);
});
</script>
</div>
\ No newline at end of file
<div id="widgetvisualization-{{widget.pk}}" rel="{{widget.pk}}" class="widgetvisualizationdialog" title="{{widget.name}} visualization" width="600px" height="600px">
<div style="width:580px;">
Select the attribute to perform sensitivity analysis on.<br><br>
<form>
<div id="radio" style="margin-bottom: 10px; text-align: center;">
{% for att in attributes %}
<input type="radio" class="target_att" name="target{{widget.pk}}" id="target{{widget.pk}}{{att}}" value="{{att}}" {% if forloop.first %}checked="checked"{% endif %}> <label for="target{{widget.pk}}{{att}}">{{att}}</label></input>
{% endfor %}
</div>
<input type="hidden" name="widget_id" value="{{widget.pk}}"/>
</form>
<script type="text/javascript">
$(function () {
// Pretty radio buttons.
$("#radio").buttonset();
// Load data points.
var data_points = {{ data_points|safe }};
var chart;
$(document).ready(function(){
plot("{{attributes.0}}");
});
// Handles radio button selection events.
$("form input[class=target_att]").change(function () {
var target_att = $("form input[class=target_att]:checked").val();
plot(target_att);
});
// Plots for the selected attribute.
function plot(target_att) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 40
},
title: {
text: 'Sensitivity analysis',
x: -20 //center
},
subtitle: {
text: 'Changing weight for attribute: ' + target_att,
x: -20
},
xAxis: {
title: {
text: 'Weight of \'' + target_att + '\''
}
},
yAxis: {
title: {
text: 'Score'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y.toFixed(3);
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: data_points[target_att],
credits: {
enabled: false
},
});
}
});
</script>
<div id="container" style="min-width: 580px; min-height: 480px margin: 0 auto"></div>
</div>
</div>
\ No newline at end of file
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