Skip to content

Instantly share code, notes, and snippets.

@nikolaithomas
Last active October 26, 2016 03:20
Show Gist options
  • Save nikolaithomas/ddd1b06b2cf415b58cc1aed73ed61c79 to your computer and use it in GitHub Desktop.
Save nikolaithomas/ddd1b06b2cf415b58cc1aed73ed61c79 to your computer and use it in GitHub Desktop.
mcnulty final
license: mit
Actual,Predicted,Confidence_normalized,imgUrl
0,0,0.014955142,http://www.redblossomtea.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/a/ba-100-1.jpg
1,0,0.199559333,
1,1,0.594591007,
2,0,0,
2,2,0.682210652,
3,0,0.347541547,
3,1,0.652952275,
3,3,0.386802151,
4,0,0.534413801,
4,4,0.770168054,
5,0,1,
5,5,0.345548961,
6,0,0.346621013,
7,0,0.573602484,
7,4,0.726804982,
7,7,0.524313313,
0,1,0.573602484,
Actual,Predicted,Confidence_normalized
0,0,0.299697933
0,4,1
0,5,0.432652726
0,6,0.443227392
0,7,0.455102805
0,3,0.444684024
0,2,0.403101826
4,0,0.406487648
4,4,0
4,5,0.284477277
4,6,0.280719094
4,7,0.274893436
4,3,0.496643319
4,2,0.293679153
5,0,0.433716002
5,4,0.998369998
5,5,0.207986847
5,6,0.416305338
5,7,0.460646308
5,3,0.540239246
5,2,0.45308161
6,0,0.434879403
6,4,0.445326549
6,5,0.390645314
6,6,0.340528373
6,7,0.383087459
6,3,0.427022749
6,2,0.383897373
7,0,0.402489556
7,4,0.816825521
7,5,0.368983821
7,6,0.361731407
7,7,0.351746564
7,3,0.554670263
7,2,0.390133064
3,0,0.43355172
3,4,0.74111397
3,5,0.539503192
3,6,0.419981066
3,7,0.42367371
3,3,0.03655673
3,2,0.378642669
2,0,0.40272688
2,4,0.575995781
2,5,0.390469475
2,6,0.354191033
2,7,0.345439347
2,3,0.441281112
2,2,0.278624636
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<style>
rect.bordered {
stroke: #E6E6E6;
stroke-width:2px;
}
text.mono {
font-size: 9pt;
font-family: Consolas, courier;
//fill: #aaa;
}
text.axis-workweek {
fill: #000;
}
text.axis-worktime {
fill: #000;
}
#tooltip {
position: absolute;
z-index: 10;
visibility: hidden; /* Change this to hide and show */
background-color: #f7f7f7;
padding: 3px 12px;
font-family: sans-serif;
border: 1px solid #bbbbbb;
box-shadow: 1px 1px 4px #bbbbbb;
}
.tooltip_title {
font-weight: bold;
font-size: 14px;
margin: 5px 0;
max-width: 300px;
word-wrap: normal;
}
.tooltip_body {
font-weight: normal;
margin: 5px 0;
}
.tooltip_img {
max-width: 240px;
}
</style>
<script src="http://d3js.org/d3.v3.js"></script>
</head>
<body>
<div id="tooltip"></div>
<div id="chart"></div>
<div id="dataset-picker">
</div>
<script type="text/javascript">
var margin = { top: 85, right: 0, bottom: 100, left: 100 },
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom,
gridSize = Math.floor(width / 24),
legendElementWidth = gridSize,
buckets = 5,
colors = ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"], // alternatively colorbrewer.YlGnBu[9]
Actual = ["Anger", "Contempt", "Neutral", "Surprise", "Disgust", "Fear", "Happiness","Sadness"],
Predicted = [ "Anger", "Contempt", "Neutral", "Surprise", "Disgust", "Fear", "Happiness", "Sadness"];
datasets = ["FisherFace_CK", "SVM_CK","RandomForestCK","MLP_CK","FisherFace_Kaggle"];
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var ActualLabels = svg.selectAll(".ActualLabel")
.data(Actual)
.enter().append("text")
.text(function (d) { return d; })
.attr("x", 0)
.attr("y", function (d, i) { return i * gridSize; })
.style("text-anchor", "end")
.attr("transform", "translate(-7," + gridSize / 1.5 + ")")
.attr("class", function (d, i) { return ((i >= 0 && i <= 4) ? "ActualLabel mono axis axis-workweek" : "ActualLabel mono axis"); });
var PredictedLabels = svg.selectAll(".PredictedLabel")
.data(Predicted)
.enter()
.append("g")
.attr("transform", function(d, i) {
return "translate(" + [i * gridSize + gridSize / 2, 0] + ")rotate(-45)";
})
.append("text")
.text(function(d) { return d; })
.attr("x", 1 )
.attr("y", -4)
// .style("text-anchor", "center")
.attr("class", function(d, i) { return ((i >= 7 && i <= 16) ? "PredictedLabel mono axis axis-worktime" : "PredictedLabel mono axis"); });
var heatmapChart = function(tsvFile) {
d3.csv(tsvFile,
function(d) {
return {
Actual: +d.Actual,
Predicted: +d.Predicted,
Confidence_normalized: +d.Confidence_normalized,
imgUrl: d.imgUrl
};
},
function(error, data) {
var colorScale = d3.scale.quantile()
.domain([0, d3.max(data, function (d) { return d.Confidence_normalized; })])
.range(colors);
svg.selectAll("rect").remove();
var cards = svg.selectAll(".Predicted")
.data(data, function(d) {return d.Actual+':'+d.Predicted;});
cards.append("title");
cards.enter().append("rect")
.attr("x", function(d) { return (d.Predicted ) * gridSize; })
.attr("y", function(d) { return (d.Actual) * gridSize; })
.attr("rx", 4)
.attr("ry", 4)
.attr("class", "hour bordered")
.attr("width", gridSize)
.attr("height", gridSize)
.style("fill", colors[0])
.on("mouseover", function(d, i) {
console.log(d);
tooltip.html("");
tooltip.append("h3").attr("class", "tooltip_title");
tooltip.append("img").attr("class", "tooltip_img");
tooltip.select(".tooltip_title")
//.text("TODO Title");
tooltip.select("img")
.attr("src", d.imgUrl);
tooltip.append("pre").attr("class", "tooltip_body");
tooltip.select(".tooltip_body")
.text("Confidence: " + d.Confidence_normalized + "\n");
return tooltip.style("visibility", "visible");
})
.on("mousemove", function(d) {
return tooltip.style("top", (d3.event.pageY-52) + "px").style("left", (d3.event.pageX+18) + "px");
})
.on("mouseout", function() {
return tooltip.style("visibility", "hidden");
});
cards.transition().duration(1000)
.style("fill", function(d) { return colorScale(d.Confidence_normalized); });
cards.select("title").text(function(d) { return d.Confidence_normalized; });
cards.exit().remove();
var legend = svg.selectAll(".legend")
.data([].concat(colorScale.quantiles()), function(d) { return d; });
legend.enter().append("g")
.attr("class", "legend");
legend.append("rect")
.attr("x", function(d, i) { return legendElementWidth * i; })
.attr("y", height)
.attr("width", legendElementWidth)
.attr("stroke", "grey")
.attr("height", gridSize / 2)
.style("fill", function(d, i) { return colors[i]; });
var legendFormatter = d3.format(".2n");
legend.append("text")
.attr("class", "mono")
.text(function(d) { return legendFormatter(d); })
.attr("x", function(d, i) { return legendElementWidth * i; })
.attr("y", height + gridSize);
legend.exit().remove();
});
};
heatmapChart(datasets[0]);
var datasetpicker = d3.select("#dataset-picker").selectAll(".dataset-button")
.data(datasets);
datasetpicker.enter()
.append("input")
.attr("value", function(d){ return d })
.attr("type", "button")
.attr("class", "dataset-button")
.on("click", function(d) {
heatmapChart(d);
})
var tooltip = d3.select("div#tooltip")
.style("visibility", "hidden");
svg.append("text")
.attr("x", 150)
.attr("y", -60)
.attr("text-anchor", "middle")
.style("font-size", "18px")
.style("font-family", "Consolas, courier")
.style("text-decoration", "bold")
.text("Predicted Emotion");
svg.append("text")
.attr("x", -145)
.attr("y", -90)
.attr("text-anchor", "middle")
.style("font-size", "18px")
.attr("transform", function(d, i) {
return "translate(" + [i * gridSize + gridSize / 2, 0] + ")rotate(-90)";
})
.style("font-family", "Consolas, courier")
.style("text-decoration", "bold")
.text("Image Label");
svg.append("text")
.attr("x", -45)
.attr("y", 325)
.attr("text-anchor", "middle")
.style("font-size", "14px")
.attr("transform", function(d, i) {
//return "translate(" + [i * gridSize + gridSize / 2, 0] + ")rotate(-90)";
})
.style("font-family", "Consolas, courier")
.style("text-decoration", "bold")
.text("Confidence:");
</script>
</body>
</html>
Actual,Predicted,Confidence_normalized
0,0,0.91198209276272102
0,1,0.0077302262045740944
0,2,0.03615994455938059
0,3,0.029360000646310308
0,4,0.005914453211335143
0,5,3.6483864158022061e-07
0,6,0.0087721006761341275
0,7,8.0818536123535484e-05
1,0,0.43003709748750424
1,1,0.50650413102563752
1,2,0.010573144260419115
1,3,3.8140715586186304e-07
1,4,1.6459723279490767e-07
1,5,5.7437678665906779e-07
1,6,0.052228386621377819
1,7,0.0006561229852089424
2,0,0.59333201699999993
2,1,1.1922666666840036e-09
2,2,0.40398995600666665
2,3,9.1336758339684996e-09
2,4,6.1533333475516954e-07
2,5,1.9346099066666673e-09
2,6,2.3500000696159836e-07
2,7,0.0026771634782533998
3,0,0.10261598016696556
3,1,0.083577438164286172
3,2,0.0066559326595120472
3,3,0.77456624995095236
3,4,0.00053651401111349552
3,5,2.5838810079841564e-05
3,6,0.027239993185873848
3,7,0.0047820526001952617
4,0,0.42230655868888889
4,1,2.2112234380123178e-06
4,2,0.090644937752781859
4,3,3.0462111167612452e-08
4,4,0.096841737222222224
4,5,0.20815630691910508
4,6,0.18129800815201527
4,7,0.00075021602511240017
5,0,0.00075926168977166416
5,1,9.5879855039285395e-05
5,2,0.001217040768870953
5,3,0.00057354872501025962
5,4,3.4432880135887489e-07
5,5,0.91516353008333329
5,6,0.041705396431451804
5,7,0.040485003090655135
6,0,0.49986023287440301
6,1,0.2015880478466951
6,2,0.00013988758853105543
6,3,4.2707220853960002e-11
6,4,6.0518560166017e-10
6,5,5.4202100912281705e-11
6,6,0.29841182779856579
6,7,2.1474912302759722e-09
7,0,0.10955740190354224
7,1,0.0344178986902057
7,2,0.021711266702719698
7,3,1.4173689193393909e-08
7,4,0.024307453709982649
7,5,3.5602406537495211e-09
7,6,0.027812665189238174
7,7,0.78219329451724584
Actual,Predicted,Confidence_normalized
0,0,0.663421052632
1,0,0.578125
2,0,0.709166666667
3,0,0.440952380952
4,0,0.533888888889
5,0,0.400476190476
5,5,0.343333333333
6,0,0.6085
7,0,0.406086956522
7,7,0.353333333333
Actual,Predicted,Confidence_normalized,imgUrl
0,0,0.79359217878947375
0,1,0.045314406754385923
0,2,0.034156341631578935
0,3,0.030410056368421045
0,4,0.015635139894736839
0,5,0.012521239666666675
0,6,0.035412914517543845
0,7,0.032957722403508763
1,0,0.43124483556249987
1,1,0.34074230962500002
1,2,0.040777015187499994
1,3,0.040159710374999998
1,4,0.016789129437500001
1,5,0.015118788250000001
1,6,0.081709983250000007
1,7,0.033458228312500005
2,0,0.65414181816666661
2,1,0.028309247666666666
2,2,0.14355844966666667
2,3,0.012650853000000002
2,4,0.019639656333333335
2,5,0.027755638833333332
2,6,0.011100898666666666
2,7,0.10284343783333333
3,0,0.13597165933333333
3,1,0.052982843571428573
3,2,0.031067408333333334
3,3,0.6901277690952381
3,4,0.019192391999999999
3,5,0.017385797047619049
3,6,0.038150698142857146
3,7,0.015121432428571427
4,0,0.43720568799999998
4,1,0.0295705
4,2,0.03768636344444444
4,3,0.011608452333333331
4,4,0.29983264655555558
4,5,0.057066402111111109
4,6,0.062217017222222219
4,7,0.064812930222222218
5,0,0.064609245916666669
5,1,0.031805982708333326
5,2,0.027477513291666662
5,3,0.031316259416666672
5,4,0.016681497083333333
5,5,0.7941782727083333
5,6,0.017256496666666666
5,7,0.016674732333333334
6,0,0.46978566410000006
6,1,0.17150032420000003
6,2,0.020823560800000002
6,3,0.031246785399999998
6,4,0.037168016200000001
6,5,0.010641271800000001
6,6,0.21393400220000003
6,7,0.044900375799999996
7,0,0.13365087765517245
7,1,0.040840696344827586
7,2,0.018095903862068968
7,3,0.015459458862068967
7,4,0.040979790206896551
7,5,0.0073733630344827586
7,6,0.039498268793103447
7,7,0.90410164127586228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment