"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

June 17, 2016

June 15, 2016

Day #26 - R - Moving Weighted Average

Example code based on two day workshop on Azure ML module. Simple example storing and accessing data from Azure workspace


computeAverage<-function(Inputdate)
{
print(Inputdate)
setwd("E:/RNotes/RData/")
TrafficData <- read.csv(file = "Test3.txt")
head(TrafficData)
TrafficData$BusinessDate1 = as.Date(TrafficData$BusinessDate, format = "%Y/%m/%d")
x = as.Date(Inputdate)-7
a = TrafficData[TrafficData$BusinessDate1==x,]$TrafficCount
y = as.Date(x)-14
b = TrafficData[TrafficData$BusinessDate1==y,]$TrafficCount
z = as.Date(x)-21
c = TrafficData[TrafficData$BusinessDate1==z,]$TrafficCount
wt <- c(.25,.50,.25)
x <- c(c,b,a)
print('mean')
print(mean(x))
xm <- weighted.mean(x, wt)
xm
print('weighted mean')
print(xm)
return(xm)
}
m=computeAverage('2016-01-29')
print(m)
#Save Dataset from below configuration
#SiteName,BusinessDate,DayofWeek,HourofWeek,TrafficCount
#Site20,2016/01/01,Monday,14,59
#Site20,2016/01/08,Monday,14,19
#Site20,2016/01/15,Monday,14,84
#Site20,2016/01/22,Monday,14,31
library("AzureML")
computeAverage<-function(Inputdate,TrafficData)
{
head(TrafficData)
TrafficData$BusinessDate1 = as.Date(TrafficData$BusinessDate, format = "%Y/%m/%d")
x = as.Date(Inputdate)-7
a = TrafficData[TrafficData$BusinessDate1==x,]$TrafficCount
y = as.Date(x)-14
b = TrafficData[TrafficData$BusinessDate1==y,]$TrafficCount
z = as.Date(x)-21
c = TrafficData[TrafficData$BusinessDate1==z,]$TrafficCount
wt <- c(.25,.50,.25)
x <- c(c,b,a)
print('mean')
print(mean(x))
xm <- weighted.mean(x, wt)
xm
print('weighted mean')
print(xm)
return(xm)
}
ws <- workspace(
id = "c54ad6b088114cd5aef68ebc8dedb1d0",
auth = "eede31e0b9f5463a8c3fcd59a6156a1f",
api_endpoint = "https://studioapi.azureml.net"
)
TrafficData <- download.datasets(
dataset = ws,
name = "TrafficDataset"
)
m=computeAverage('2016-01-29',TrafficData)
print(m)

Happy Learning!!!

June 01, 2016

Day #25 - Data Transformations in R

This post is on performing Data Transformations in R. This would be part of feature modelling. Advanced PCA will be done during later stages



#Data for column attributes
Y0 = 1:20 + rnorm(100,sd=3)
Y1 = 1:20 + rnorm(100,sd=2)
Y2 = 1:20 + rnorm(100,sd=2)
Y3 = 1:20 + rnorm(100,sd=2)
Y4 = 1:20 + rnorm(100,sd=2)
Y5 = 1:20 + rnorm(100,sd=3)
Y6 = 1:10 + rnorm(100,sd=3)
Y7 = 1:10 + rnorm(100,sd=2)
Y8 = 1:20 + rnorm(100,sd=1)
#Create Data Frame
data <- data.frame(Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8)
#sample few records
head(data)
#Ways to normalize Data
data$Y0 = (x-min(data$Y0))/(max(data$Y0)-min(data$Y0))
#Raises Y to the power of 3
data$Y1 <- (data$Y1)^3
#Takes the ninth root of Y
data$Y2 <- (data$Y2)^(1/9)
#Takes the natural logarithm (ln) of Y
data$Y3 <- log(data$Y3)
#Takes the base-10 logarithm of Y
data$Y4 <- log10(data$Y4)
#Raises the constant e to the power of Y
data$Y5 <- exp(data$Y5)
#Finds the absolute value of Y
data$Y6 <- abs(data$Y6)
#Calculates the sine of Y
data$Y7 <- sin(data$Y7)
#Calculates the inverse sine (arcsine) of Y
data$Y8 <- asin(data$Y8)
#check modified data
head(data)
Data Normalization in Python

Happy Learning!!!