Created
July 3, 2016 15:30
-
-
Save flovv/5ec358c17c4e4a735f5e4b39f3435dea to your computer and use it in GitHub Desktop.
Analyzing AirBnB demographics
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
## gather data: | |
require(Roxford) | |
images <- list.files("sample bilder/") | |
facekey = "API KEY" | |
for(i in images[1:200]){ | |
dff <- getFaceResponse(paste0("sample bilder/",i), facekey) | |
if(nrow(dff)>0){ | |
dff$image <- i | |
df <- smartbind(df, dff) | |
} | |
### free API requires some delay... | |
Sys.sleep(11) | |
} | |
################################################# | |
## blog post - results | |
res <- dff | |
require(Rmisc) | |
require(jpeg) | |
require(ggplot2) | |
require(ggthemes) | |
imgs <- list.files() | |
imgs <- imgs[grep("jpg", imgs)] | |
imgs <- unique(imgs) | |
par(mar=rep(0,4)) | |
layout(matrix(1:150, ncol=15, byrow=TRUE)) | |
for(i in 1:150) { | |
img <- readJPEG(imgs[i]) | |
plot(NA,xlim=0:1,ylim=0:1,xaxt="n",yaxt="n") | |
rasterImage(img,0,0,1,1) | |
} | |
ggplot(res, aes(faceAttributes.age, color=Gender, fill=Gender)) + geom_density(alpha=0.5) + theme_economist() + xlab("Age") | |
dfc <- summarySE(res, groupvars = "Gender", measurevar = c("faceAttributes.age")) | |
ggplot(dfc, aes(Gender, faceAttributes.age)) + geom_point()+geom_errorbar(aes(ymin=faceAttributes.age-se, ymax=faceAttributes.age+se), width=.1) +theme_economist() | |
dfc <- summarySE(res, groupvars = "Gender", measurevar = c("faceRectangle.width")) | |
ggplot(dfc, aes(Gender, faceRectangle.width)) + geom_point()+geom_errorbar(aes(ymin=faceRectangle.width-se, ymax=faceRectangle.width+se), width=.1) +theme_economist() | |
dfc <- summarySE(res, groupvars = "Gender", measurevar = c("faceAttributes.smile"), na.rm=T) | |
ggplot(dfc, aes(Gender, faceAttributes.smile)) + geom_point()+geom_errorbar(aes(ymin=faceAttributes.smile-se, ymax=faceAttributes.smile+se), width=.1) +theme_economist() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment