Last active
September 22, 2015 14:41
-
-
Save fabiomainardi/29b8692cf08716972133 to your computer and use it in GitHub Desktop.
Association Rules for Data Scientist skills
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source | target | value | |
---|---|---|---|
Hive | SQL | 0.755102040816 | |
MatLab | Python | 0.875 | |
Hive | Python | 0.734693877551 | |
STATA | SQL | 0.761904761905 | |
R | Python | 0.70618556701 | |
STATA | Python | 0.714285714286 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<script src="http://d3js.org/d3.v3.js"></script> | |
<style> | |
path.link { | |
fill: none; | |
stroke: #666; | |
stroke-width: 1.5px; | |
} | |
circle { | |
fill: #ccc; | |
stroke: #fff; | |
stroke-width: 1.5px; | |
} | |
text { | |
fill: #000; | |
font: 20px sans-serif; | |
font-weight:bold; | |
pointer-events: none; | |
} | |
#tooltip { | |
position: absolute; | |
width: 220px; | |
height: auto; | |
padding: 10px; | |
background-color: yellow; | |
-webkit-border-radius: 10px; | |
-moz-border-radius: 10px; | |
border-radius: 10px; | |
-webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4); | |
-moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4); | |
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4); | |
pointer-events: none; | |
} | |
#tooltip.hidden { | |
display: none; | |
} | |
#tooltip p { | |
margin: 0; | |
font-family: sans-serif; | |
font-size: 16px; | |
line-height: 20px; | |
} | |
</style> | |
<body> | |
<div id="tooltip" class="hidden"> | |
<p><strong></strong></p> | |
<p><span id="value">1</span></p> | |
</div> | |
<script> | |
// get the data | |
d3.csv("arules.csv", function(error, links) { | |
var nodes = {}; | |
// Compute the distinct nodes from the links. | |
links.forEach(function(link) { | |
link.source = nodes[link.source] || | |
(nodes[link.source] = {name: link.source}); | |
link.target = nodes[link.target] || | |
(nodes[link.target] = {name: link.target}); | |
link.value = +link.value; | |
}); | |
var width = 960, | |
height = 500; | |
var force = d3.layout.force() | |
.nodes(d3.values(nodes)) | |
.links(links) | |
.size([width, height]) | |
.linkDistance(250) | |
.charge(-400) | |
.on("tick", tick) | |
.start(); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
svg.append("svg:defs").selectAll("marker") | |
.data(["end"]) | |
.enter().append("svg:marker") | |
.attr("id", String) | |
.attr("viewBox", "0 -5 10 10") | |
.attr("refX", 15) | |
.attr("refY", -1.5) | |
.attr("markerWidth", 6) | |
.attr("markerHeight", 6) | |
.attr("orient", "auto") | |
.append("svg:path") | |
.attr("d", "M0,-5L10,0L0,5"); | |
var path = svg.append("svg:g").selectAll("path") | |
.data(force.links()) | |
.enter() | |
.append("svg:path") | |
.attr("class", function(d) { return "link " + d.type; }) | |
.attr("class", "link") | |
.attr("marker-end", "url(#end)") | |
.on("mouseover", function(d) { | |
d3.select("#tooltip") | |
.select("#value") | |
.text(d3.round(d.value*100, 2)+"%"); | |
d3.select("#tooltip").classed("hidden", false); | |
}) | |
.on("mouseout", function(d) { | |
d3.select("#tooltip").classed("hidden", true); | |
}); | |
var node = svg.selectAll(".node") | |
.data(force.nodes()) | |
.enter().append("g") | |
.attr("class", "node") | |
.call(force.drag); | |
node.append("circle") | |
.attr("r", 10) | |
.style("fill","blue") | |
.style("opacity",0.5); | |
// add the text | |
node.append("text") | |
.attr("x", 12) | |
.attr("dy", ".35em") | |
.text(function(d) { return d.name; }); | |
// add the curvy lines | |
function tick() { | |
path.attr("d", function(d) { | |
var dx = d.target.x - d.source.x, | |
dy = d.target.y - d.source.y, | |
dr = Math.sqrt(dx * dx + dy * dy); | |
return "M" + | |
d.source.x + "," + | |
d.source.y + "A" + | |
dr + "," + dr + " 0 0,1 " + | |
d.target.x + "," + | |
d.target.y; | |
}); | |
node | |
.attr("transform", function(d) { | |
return "translate(" + d.x + "," + d.y + ")"; }); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment