Revanth reddy Katanguri

Revanth reddy Katanguri

Data Enthusiast- R, python, Hadoop, Hive, SQL, Sqoop
Dallas/Fort Worth Area
-> Passionate Data Scientist and Big Data enthusiast having 2 years of Professional work experience with implementing Data Science, Big Data solutions in solving problems related to Predictive modelling, Data processing using tools- R, python, Hadoop, Hive, SQL, Sqoop. -> Professional and Academic work experience with working on Machine learning models- Classification, Regression, Clustering, Support vector Machine, Decision trees, Random forest, Principal component analysis(PCA), Neural Networks, XgBoost. -> Hands on experience in using various R packages- dplyr, tidyr, python libraries- Numpy, Scipy, Pandas, Scikit-learn, Visualization packages like ggplot2, Seaborn, Bokeh. -> Strong experience and knowledge in using Hadoop, HDFS, Writing Complex Hive queries, Sqoop imports, hands on experience in using Cloudera distribution. -> Excellent written and articulation skills with a strong character and a committed team player.
[No canvas support]

Project: Coupon purchase prediction

Faculty Feedback

Prashanth G

Practice Lead - Healthcare at TCS

His project is excellent. The approach and the quality of execution deserves to be commended and his performance certified.

Project Demo

Problem Statement:

  • Designed a recommendation engine for Ponpare, Japan’s leading joint coupon site which predicts the 5 most likely coupons the customer will buy out of 310 available coupons.
  • Performed the computation, log transformations, feature engineering and Data exploration to identify the insights and conclusions from complex data.
  • Built an algorithm implementing the concept of Cosine Similarity which recommends the 5 coupons the customer will most likely to buy.

Dataset:

coupon_detail_train.csv
coupon_list_train.csv
coupon_list_test.csv
user_list.csv
coupon_area_train.csv
coupon_visit_train.csv
coupon_detail_train.csv

plot(cars)
library(ggplot2)
library(dplyr)
setwd('C:\\Users\\Revanth K\\Documents\\coupon purchase prediction')
#read in all the input data
cpdtr <- read.csv("coupon_detail_train.csv")
cpltr <- read.csv("coupon_list_train.csv")
cplte <- read.csv("coupon_list_test.csv")
ulist <- read.csv("user_list.csv")
cpatr <- read.csv("coupon_area_train.csv", stringsAsFactors = FALSE)
cpvtr <- read.csv("coupon_visit_train.csv", stringsAsFactors = FALSE)
cpdtr <- read.csv("coupon_detail_train.csv", stringsAsFactors = FALSE)
barplot(table(ulist$SEX_ID),
        names.arg = c('FEMALE', 'MALE'),main = 'gender distributiion',col = '#ffd1dc')
hist(ulist$AGE,main = 'Age- distribution',xlab= NULL,col='#aec6cf')
age_groups <- c(20, 30, 40, 50, 60, 70, 80)
ulist$AGE_GROUP <- cut(ulist$AGE, age_groups, include.lowest = TRUE)
plot(ulist$AGE_GROUP,ulist$SEX_ID, main = 'Age Group and Gender', xlab = 'Age Group', ylab = 'Gender')
names(ulist)
par(mfrow=c(1,1))
library(ggplot2)
ggplot(ulist, aes(x=AGE, fill=SEX_ID)) +
  geom_histogram(binwidth=5, position='dodge')
### Registered date (by sex_id
ulist$REG_DATE <- as.Date(ulist$REG_DATE)
ulist$WITHDRAW_DATE <- as.Date(ulist$WITHDRAW_DATE)
ggplot(ulist, aes(x=ulist$REG_DATE, fill=SEX_ID)) +
  geom_histogram(binwidth=25, position='dodge')
ggplot(ulist, aes(x=ulist$WITHDRAW_DATE, fill=SEX_ID)) +
  geom_histogram(binwidth=25, position='dodge')
NA
ulist$LAST_DATE <- ulist$WITHDRAW_DATE
ulist[is.na(ulist$LAST_DATE),]$LAST_DATE <- max(ulist[is.na(ulist$WITHDRAW_DATE) == FALSE,]$WITHDRAW_DATE)
ulist$DURATION <- ulist$LAST_DATE - ulist$REG_DATE
ulist$DURATION <- as.numeric(ulist$DURATION, units = "days")
summary(ulist$DURATION)
ggplot(ulist, aes(x=ulist$DURATION, fill=SEX_ID)) +
  geom_histogram(binwidth=25, position='dodge')
user_frequency = as.data.frame.table(sort(table(ulist$PREF_NAME)))
colnames(user_frequency) <- c("PREF_NAME", "FREQUENCY")
print(user_frequency)
cpvtr$sex = ulist[match(cpvtr$USER_ID_hash,ulist$USER_ID_hash),"SEX_ID"]
purchased_gender <- table(cpvtr$PURCHASE_FLG,cpvtr$sex)
barplot(prop.table(purchased_gender,1), legend.text = TRUE,
        main = 'Purchages by Gender', 
        col = c('red','yellow'),
        beside = TRUE,
        xlab = 'Purchased',
        ylab = 'Proportion')
cpvtr$age = ulist[match(cpvtr$USER_ID_hash,ulist$USER_ID_hash),"AGE"]
purchased_age <- table(cpvtr$PURCHASE_FLG,cut(cpvtr$age,breaks = seq(10,100,by=10)))
barplot(purchased_age, legend.text = TRUE,
        main = 'Purchages by Age', 
        col = c('red','yellow'),
        beside = TRUE,
        xlab = 'Purchased',
        ylab = 'Proportion')
cpdtr$age = ulist[match(cpdtr$USER_ID_hash,ulist$USER_ID_hash),"AGE"]
subset_age_10 = cpdtr[(as.numeric(cpdtr$age) > 10
                                     & as.numeric(cpdtr$age) <= 20) ,]
pie(table(subset_age_10$COUPON_ID_hash))
subset_age_20 = cpdtr[(as.numeric(cpdtr$age) > 20
                                     & as.numeric(cpdtr$age) <= 30) ,]
pie(table(subset_age_20$COUPON_ID_hash))
subset_age_30 = cpdtr[(as.numeric(cpdtr$age) > 30
                                     & as.numeric(cpdtr$age) <= 40) ,]
pie(table(subset_age_30$COUPON_ID_hash))
subset_age_40 = cpdtr[(as.numeric(cpdtr$age) > 40
                                     & as.numeric(cpdtr$age) <= 50) ,]
pie(table(subset_age_40$COUPON_ID_hash))
subset_age_50 = cpdtr[(as.numeric(cpdtr$age) > 50
                                     & as.numeric(cpdtr$age) <= 60) ,]
pie(table(subset_age_50$COUPON_ID_hash))
subset_age_60 = cpdtr[(as.numeric(cpdtr$age) > 60
                                     & as.numeric(cpdtr$age) <= 70) ,]
pie(table(subset_age_60$COUPON_ID_hash))
subset_age_70 = cpdtr[(as.numeric(cpdtr$age) > 70) ,]
pie(table(subset_age_70$COUPON_ID_hash))
### Coupon List
barplot(table(cpltr$USABLE_DATE_MON),
# names.args = c('No', 'Yes')
main = 'Coupon usable on Monday?',
col = '#fdfd96')
barplot(table(cpltr$USABLE_DATE_TUE),
        
        main = 'Coupon usable on Tuesday?',
        col = '#fdfd96')
barplot(table(cpltr$USABLE_DATE_WED),
        
        main = 'Coupon usable on Wednesday?',
        col = '#fdfd96')
barplot(table(cpltr$USABLE_DATE_THU),
        
        main = 'Coupon usable on Thursday?',
        col = '#fdfd96')
barplot(table(cpltr$USABLE_DATE_FRI),
        
        main = 'Coupon usable on Friday?',
        col = '#fdfd96')
barplot(table(cpltr$USABLE_DATE_SAT),
        
        main = 'Coupon usable on Saturday?',
        col = '#fdfd96')
barplot(table(cpltr$USABLE_DATE_SUN),
        
        main = 'Coupon usable on Sunday?',
        col = '#fdfd96')
ggplot(cpltr, aes(x = CATALOG_PRICE, y = DISCOUNT_PRICE)) + geom_point() + 
  labs(x = 'Catalogue Price', y = 'Discount Price', title = 'Catalogue and Discount Prices')
barplot(table(cpatr$PREF_NAME),
        main = 'Coupon Listing Areas (Prefectures)')
couponPrefectures <- as.data.frame(table(cpatr$PREF_NAME))
colnames(couponPrefectures) <- c("Prefecture', 'Frequency')
arrange(couponPrefectures, desc(Frequency))
#making of the train set
train <- merge(cpdtr,cpltr)
train <- train[,c("COUPON_ID_hash","USER_ID_hash",
                  "GENRE_NAME","DISCOUNT_PRICE","PRICE_RATE",
                  "USABLE_DATE_MON","USABLE_DATE_TUE","USABLE_DATE_WED","USABLE_DATE_THU",
                  "USABLE_DATE_FRI","USABLE_DATE_SAT","USABLE_DATE_SUN","USABLE_DATE_HOLIDAY",
                  "USABLE_DATE_BEFORE_HOLIDAY","large_area_name","ken_name","small_area_name")]
#combine the test set with the train
cplte$USER_ID_hash <- "dummyuser"
cpchar <- cplte[,c('COUPON_ID_hash','USER_ID_hash',
                   'GENRE_NAME','DISCOUNT_PRICE','PRICE_RATE',
                   'USABLE_DATE_MON','USABLE_DATE_TUE','USABLE_DATE_WED','USABLE_DATE_THU',
                   'USABLE_DATE_FRI','USABLE_DATE_SAT','USABLE_DATE_SUN','USABLE_DATE_HOLIDAY',
                   'USABLE_DATE_BEFORE_HOLIDAY','large_area_name','ken_name','small_area_name')]
train <- rbind(train,cpchar)
#NA imputation
train[is.na(train)] <- 1
#feature engineering
train$DISCOUNT_PRICE <- 1/log10(train$DISCOUNT_PRICE)
train$PRICE_RATE <- (train$PRICE_RATE*train$PRICE_RATE)/(100*100)
#convert the factors to columns of 0's and 1's
train <- cbind(train[,c(1,2)],model.matrix(~ -1 + .,train[,-c(1,2)],
                                           contrasts.arg=lapply(train[,names(which(sapply(train[,-c(1,2)], is.factor)==TRUE))], contrasts, contrasts=FALSE)))
#separate the test from train
test <- train[train$USER_ID_hash=='dummyuser',]
test <- test[,-2]
train <- train[train$USER_ID_hash!='dummyuser',]
#data frame of user characteristics
uchar <- aggregate(.~USER_ID_hash, data=train[,-1],FUN=mean)
uchar$DISCOUNT_PRICE <- 1
uchar$PRICE_RATE <- 1
#Weight Matrix: GENRE_NAME DISCOUNT_PRICE PRICE_RATE USABLE_DATE_ large_area_name ken_name small_area_name
library(Matrix)
require(Matrix)
W <- as.matrix(Diagonal(x=c(rep(2.05,13), rep(2,1), rep(-0.13,1), rep(0,9), rep(0.5,9), rep(1.01,47), rep(4.75,55))))
# We are goingto learn  is how to use a well-known similarity measure (Cosine similarity) to clacualte the similarity between different coupons
#STEP1: conver the dat to dot product in matrix format
# STEP2:
#calculation of cosine similairties of users and coupons
score = as.matrix(uchar[,2:ncol(uchar)]) %*% W %*% t(as.matrix(test[,2:ncol(test)]))
#order the list of coupons according to similairties and take only first 10 coupons
uchar$PURCHASED_COUPONS <- do.call(rbind, lapply(1:nrow(uchar),FUN=function(i){
  purchased_cp <- paste(test$COUPON_ID_hash[order(score[i,], decreasing = TRUE)][1:10],collapse=" ")
  return(purchased_cp)
}))
#make submission
submission <- merge(ulist, uchar, all.x=TRUE)
submission <- submission[,c("USER_ID_hash","PURCHASED_COUPONS")]
write.csv(submission, file="cosine_sim.csv", row.names=FALSE)
# Create master translation table from Japanese to English
coupon_list_train = read.csv("coupon_list_train.csv", as.is=T) # Source file the English list is keyed by
trans = data.frame(
  jp=unique(c(coupon_list_train$GENRE_NAME, coupon_list_train$CAPSULE_TEXT,
              coupon_list_train$large_area_name, coupon_list_train$ken_name,
              coupon_list_train$small_area_name)),
  en=c("Food","Hair salon","Spa","Relaxation","Beauty","Nail and eye salon","Delivery service","Lesson","Gift card","Other coupon","Leisure","Hotel and Japanese hotel","Health and medical","Other","Hotel","Japanese hotel","Vacation rental","Lodge","Resort inn","Guest house","Japanse guest house","Public hotel","Beauty","Event","Web service","Class","Correspondence course","Kanto","Kansai","East Sea","Hokkaido","Kyushu-Okinawa","Northeast","Shikoku","Chugoku","Hokushinetsu","Saitama Prefecture","Chiba Prefecture","Tokyo","Kyoto","Aichi Prefecture","Kanagawa Prefecture","Fukuoka Prefecture","Tochigi Prefecture","Osaka prefecture","Miyagi Prefecture","Fukushima Prefecture","Oita Prefecture","Kochi Prefecture","Hiroshima Prefecture","Niigata Prefecture","Okayama Prefecture","Ehime Prefecture","Kagawa Prefecture","Tokushima Prefecture","Hyogo Prefecture","Gifu Prefecture","Miyazaki Prefecture","Nagasaki Prefecture","Ishikawa Prefecture","Yamagata Prefecture","Shizuoka Prefecture","Aomori Prefecture","Okinawa","Akita","Nagano Prefecture","Iwate Prefecture","Kumamoto Prefecture","Yamaguchi Prefecture","Saga Prefecture","Nara Prefecture","Mie","Gunma Prefecture","Wakayama Prefecture","Yamanashi Prefecture","Tottori Prefecture","Kagoshima prefecture","Fukui Prefecture","Shiga Prefecture","Toyama Prefecture","Shimane Prefecture","Ibaraki Prefecture","Saitama","Chiba","Shinjuku, Takadanobaba Nakano - Kichijoji","Kyoto","Ebisu, Meguro Shinagawa","Ginza Shinbashi, Tokyo, Ueno","Aichi","Kawasaki, Shonan-Hakone other","Fukuoka","Tochigi","Minami other","Shibuya, Aoyama, Jiyugaoka","Ikebukuro Kagurazaka-Akabane","Akasaka, Roppongi, Azabu","Yokohama","Miyagi","Fukushima","Much","Kochi","Tachikawa Machida, Hachioji other","Hiroshima","Niigata","Okayama","Ehime","Kagawa","Northern","Tokushima","Hyogo","Gifu","Miyazaki","Nagasaki","Ishikawa","Yamagata","Shizuoka","Aomori","Okinawa","Akita","Nagano","Iwate","Kumamoto","Yamaguchi","Saga","Nara","Triple","Gunma","Wakayama","Yamanashi","Tottori","Kagoshima","Fukui","Shiga","Toyama","Shimane","Ibaraki"),
  stringsAsFactors = F)
# Append data with translated columns...
# COUPON_LIST_TRAIN.CSV
coupon_list_train = read.csv('coupon_list_train.csv', as.is=T) # Read data file to translate
names(trans)=c('jp','en_capsule') # Rename column
coupon_list_train=merge(coupon_list_train,trans,by.x="CAPSULE_TEXT",by.y='jp',all.x=T) # Join translation onto original data
names(trans)=c('jp','en_genre'); coupon_list_train=merge(coupon_list_train,trans,by.x='GENRE_NAME',by.y='jp',all.x=T)
names(trans)=c('jp','en_small_area'); coupon_list_train=merge(coupon_list_train,trans,by.x='small_area_name',by.y='jp',all.x=T)
names(trans)=c('jp','en_ken'); coupon_list_train=merge(coupon_list_train,trans,by.x='ken_name',by.y='jp',all.x=T)
names(trans)=c('jp','en_large_area'); coupon_list_train=merge(coupon_list_train,trans,by.x='large_area_name',by.y='jp',all.x=T)
write.csv(coupon_list_train, 'coupon_list_train_en.csv', row.names = F)
# COUPON_LIST_TRAIN.CSV
coupon_area_train = read.csv('coupon_area_train.csv', as.is=T) 
names(trans)=c('jp','en_small_area'); coupon_area_train=merge(coupon_area_train,trans,by.x='SMALL_AREA_NAME',by.y='jp',all.x=T)
names(trans)=c('jp','en_pref'); coupon_area_train=merge(coupon_area_train,trans,by.x='PREF_NAME',by.y='jp',all.x=T)
write.csv(coupon_area_train, 'coupon_area_train_en.csv', row.names = F)
processing person-icon