customer <- read.csv("http://artificium.us/assignments/55.data-analytics/a-55-103/customertxndata.csv")
str(customer)
## 'data.frame':    22800 obs. of  5 variables:
##  $ numvisits: int  7 20 22 24 1 13 23 14 11 24 ...
##  $ numtxns  : int  0 1 1 2 0 1 2 1 1 2 ...
##  $ OS       : chr  "Android" "iOS" "iOS" "iOS" ...
##  $ gender   : chr  "Male" NA "Female" "Female" ...
##  $ rev      : num  0 577 850 1050 0 ...

Data Analysis

There were 22800 customers and the mean number of visits per customer was 12.49. The total transaction amount is 1.0372524^{7} dollars. The median revenue was US$ 344.65 (sdv = 425.99). Most of the visitors were Male.

As it shown above, the male customers’ total revenue is higher than female customers.

cor(customer$numvisits, customer$rev)
## [1] 0.7388448

The Pearson correlation coefficient r ranges from -1 to +1. As it shown above, we got 0.7388 as the correlation coefficient, which means that the number of visits and revenue have a strong positive relationship. In other words, the more visits customers pay to the store can bring in more revenue.

Test Missing Values

any(is.na(customer$numvisits))
## [1] FALSE
any(is.na(customer$numtxns))
## [1] TRUE
any(is.na(customer$OS))
## [1] FALSE
any(is.na(customer$gender))
## [1] TRUE
any(is.na(customer$rev))
## [1] FALSE

According to the result above, the column “numtxns” (the number of transactions of that customer) and the column “gender” have missing values.

Since the column “numtxns” is a numeric column, I would replace missing values with mean, which is 0.993; and since the column “gender” is a categorical column, I would replace missing value with mode, which is Male.

# transaction
customer$numtxns[is.na(customer$numtxns)] <- round(meanTransaction)
# gender
customer$gender[is.na(customer$gender)] <- commonGender

There were 22800 customers and the mean number of visits per customer was 12.49. The total transaction amount is 1.0372524^{7} dollars. The median revenue was US$ 344.65 (sdv = 425.99). Most of the visitors were Male.

There is no difference between the previous descriptive markdown and the new one.

Split into training set and test set

totalRows <- nrow(customer)
trainingSet <- customer[seq(1, totalRows, by=2),]
validationSet <- customer[seq(2, totalRows, by=2),]
## 
##  Welch Two Sample t-test
## 
## data:  trainingSet$rev and validationSet$rev
## t = -1.8875, df = 22790, p-value = 0.0591
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -21.70830   0.40925
## sample estimates:
## mean of x mean of y 
##  449.6105  460.2600

The mean revenue for the training set is 449.61 while the mean revenue for the validation set is 460.26. The later one is a bit larger than the former one, but according to the t-test result, since the p-value is bigger than 0.05, we must conclude that there is NO statistically significant difference between the two.

set.seed(77654)

training_set <- sample(seq_len(nrow(customer)), size=floor(.6*nrow(customer)), replace=F)
remaining <- customer[-training_set,]

testing_set <- sample(seq_len(nrow(remaining)), size=floor(.5*nrow(remaining)), replace=F)
validation_set <- sample(seq_len(nrow(customer)), size=floor(.5*nrow(remaining)), replace=F)