This dataset is rich with information about the brain and body weights of animals, along with average sleep per day, gestation period, maximum life expectancy, exposure to danger during sleep, overall danger quotient etc.
For this week’s assignment, I’m only looking at brain and body weight with overall danger quotient using the LinearClassification example that we looked at in class. As I learn about working with the data in these libraries, I’d like to work with this data more. The data rates the potential of the animal being in danger on a scale of 1 – 5, with 1 being the least amount of danger and 5 being the most. The animals with a danger rating of 4 and 5 are put in the group that has the least amount of danger, and any rating 3 or below is put in the group that is in the most amount of danger.
From the data set, the danger quotient is calculated based on their likelihood to become prey and how exposed the animal is where they naturally sleep.
Here I’ve integrated the data, and you can see that most of the animals in the most danger fall on the side of the average of smaller body and brain weights, although there are several animals that are not rated as being in danger that fall on the smaller scale side.
In the print screen, the animal species, brain weight and danger quotient can be seen.
import linearclassifier.*;
import processing.data.*;
Table data;
LinearClassifier classifier;
void setup() {
size(1300, 600);
data = new Table(this, “animals.csv”);
classifier = new LinearClassifier(this);
ArrayList
ArrayList
ArrayList
ArrayList
data.removeTitleRow();
for (TableRow row : data) {
ArrayList
ArrayList
println(row.getString(0) + ” weighs ” +row.getFloat(1) + “kgs, ” + “brain ” + row.getFloat(2) + “g, ” + “and is a ” + row.getFloat(10) + ” on a scale of 1 beaing in the least amount of danger to 5 in the most.”);
name.add(row.getString(0));
entry.add(row.getFloat(1));
entry.add(row.getFloat(2));
// put the Pvector in the right ArrayList for animals in the most danger or animals in the least danger
if (row.getFloat(3) > 3) {
mostDanger.add(entry);
mostDangerName.add(name);
}
else {
leastDanger.add(entry);
}
}
// pass the data to the classifier
classifier.loadSet1(leastDanger);
classifier.loadSet2(mostDanger);
ArrayList
scales.add(new PVector(50, 1200));
scales.add(new PVector(550, 25));
classifier.setOutputScale(scales);
}
void draw() {
background(255);
noStroke();
// display the data
fill(220, 173, 200);
classifier.drawSet1();
fill(200, 173, 220);
classifier.drawSet2();
fill(0);
text(“ANIMAL BODY & BRAIN WEIGHT WITH DANGER RATING”, width/3, 50);
// get the average of each set
ArrayList
ArrayList
// draw them as black boxes
fill(220, 173, 200);
strokeWeight(3);
ellipseMode(CENTER);
ellipse(set1Ave.get(0), set1Ave.get(1), 10, 10);
text(“Average body & brain weight\nof animals in the least danger”, set1Ave.get(0)+10, set1Ave.get(1)+10);
fill(200, 173, 220);
ellipse(set2Ave.get(0), set2Ave.get(1), 10, 10);
text(“Average body & brain weight\nof animals in the most danger”, set2Ave.get(0)+10, set2Ave.get(1)+10);
strokeWeight(1);
stroke(0);
line(50, 550, width, 550);
stroke(0);
line(50, 0, 50, 550);
fill(0);
text(“0″, 40, 565);
// draw a line perpendicualr to the line
stroke(197, 193, 170);
drawPerpindicularLine(set1Ave.get(0), set1Ave.get(1), set2Ave.get(0), set2Ave.get(1));
noStroke();
if (classifier.isInSet1(new PVector(mouseX, mouseY))) {
text(“not in danger”, mouseX+7, mouseY-10);
fill(220, 173, 200);
}
else {
text(“You’re in DANGER”, mouseX+7, mouseY-10);
fill(200, 173, 220);
}
ellipse(mouseX, mouseY, 10, 10);
PVector p = classifier.getUnscaledPoint(new PVector(mouseX, mouseY));
text(“bodyWeight: ” + round(p.x) + “kg\nbrainWeight: ” + round(p.y) + “grms”, mouseX+7, mouseY+7);
saveFrame(“line-######.tif”);
}
void drawPerpindicularLine(float x1, float y1, float x2, float y2) {
PVector axis = PVector.sub(new PVector(x1, y1), new PVector(x2, y2));
PVector perp = axis.cross(new PVector(0, 0, 1));
perp.setMag(500);
PVector lineStart = PVector.sub(classifier.getCenterPoint(), perp);
PVector lineEnd = PVector.add(classifier.getCenterPoint(), perp);
line(lineStart.x, lineStart.y, lineEnd.x, lineEnd.y);
}


