I’m going to have fun with my AzureML session today at PASS Summit! More will follow on this post later; I am racing off to the keynote so I don’t have long :) I heard some folks weren’t sure whether to attend my session or Chris Webb’s session. I’m honestly flattered but I’m not in the same league as Chris! I’ve posted my notes here so that folks can go off and attend Chris’ session, if they are stuck between the two. Here is the order of things: Slide Deck AzureML Experiment R Code So, the slide deck is here: You can see this experiment in the AzureML Gallery . You may have to sign up for a Windows Live account to get a free AzureML studio account, and I recommend that you do. R Code Here’s a sample R code. I know it is simple, and there are better ways of doing this. However, remember that this is for instructional purposes in front of +/- 500 people so I want to be sure everyone has a grounding before we talk more complicated things. You may have to install the libraries first, if you haven’t done so. library(data.table) library(ggplot2) library(xtable) library(rpart) require(xtable) require(data.table) require(ggplot2) require(rpart) summary(adult.data) class(adult.data) # Let’s rename the columns names(adult.data)[1]<-“age” names(adult.data)[2]<-“workclass” names(adult.data)[3]<-“fnlwgt” names(adult.data)[4]<-“education” names(adult.data)[5]<-“education.num” names(adult.data)[6]<-“marital.status” names(adult.data)[7]<-“occupation” names(adult.data)[8]<-“relationship” names(adult.data)[9]<-“race” names(adult.data)[10]<-“sex” names(adult.data)[11]<-“capital.gain” names(adult.data)[12]<-“capital.loss” names(adult.data)[13]<-“hours.per.week” names(adult.data)[14]<-“country” names(adult.data)[15]<-“earning_level” # Let’s see if the columns renamed well # What is the maximum age of the adult? # How much data is missing? summary(adult.data) # How many rows do we have? # 32561 rows, 15 columns dim(adult.data) # There are lots of different ways to deal with missing data # That would be a session in itself! # For demo purposes, we are simply going to replace question marks, and remove rows which have anything missing. adult.data$workclass <- as.factor(gsub(“[?]”, NA, adult.data$workclass)) adult.data$education <- as.factor(gsub(“[?]”, NA, adult.data$education)) adult.data$marital.status <- as.factor(gsub(“[?]”, NA, adult.data$marital.status)) adult.data$occupation <- as.factor(gsub(“[?]”, NA, adult.data$occupation)) adult.data$relationship <- as.factor(gsub(“[?]”, NA, adult.data$relationship)) adult.data$race <- as.factor(gsub(“[?]”, NA, adult.data$race)) adult.data$sex <- as.factor(gsub(“[?]”, NA, adult.data$sex, fixed = TRUE)) adult.data$country <- as.factor(gsub(“[?]”, NA, adult.data$country)) is.na(adult.data) = adult.data==’?’ is.na(adult.data) = adult.data==’ ?’ adult.tidydata = na.omit(adult.data) # Let’s check out our new data set, called adult.tidydata summary(adult.tidydata) # How many rows do we have? # 32561 rows, 15 columns dim(adult.tidydata) # Let’s visualise the data boxplot(adult.tidydata$education.num~adult.tidydata$earning_level,outline=F,xlab=”Income Level”,ylab=”Education Level”,main=”Income Vs Education”) prop.table(table(adult.tidydata$earning_level,adult.tidydata$occupation),2) for (i in 1:ncol(adult.tidydata)-2) { if (is.factor(adult.tidydata[,i])){ pl =ggplot(adult.tidydata,aes_string(colnames(adult.tidydata)[i],fill=”earning_level”))+geom_bar(position=”dodge”) + theme(axis.text.x=element_text(angle=75)) print(pl) } } evalq({ plot <- ggplot(data = adult.tidydata, aes(x = hours.per.week, y = education.num, colour = hours.per.week)) plot <- plot + geom_point(alpha = 1/10) plot <- plot + ggtitle(“Hours per Week vs Level of Education”) plot <- plot + stat_smooth(method = “lm”, se = FALSE, colour = “red”, size = 1) plot <- plot + xlab(“Education Level”) + ylab(“Hours per Week worked”) plot <- plot + theme(legend.position = “none”) plot }) That’s all for now! More later. Jen xx
↧