Price bundling using Genetic Algorithm in R

Data set: Values that customers assigned for different products
Flow chart of GA
Result of experiment 1
Result of experiment 2
#Load Customer data
Customer <- read.csv(file.csv, sep = ",", header = T)
#Price <- c(35.0,75.0,64.0,75.0,82.0,92.0,100.0)
attach(Customer)
library(matrixStats)
Func <- function(x)
{
MarketSur <- cbind(Internet-x[1],TV-x[2],Cell.Phone-x[3],
Internet+TV-x[4], Internet+Cell.Phone-x[5],
TV+Cell.Phone-x[6], Internet+TV+Cell.Phone-x[7])
MaxSur <- rowMaxs(MarketSur)
Prod <- function(MarketSur)
{
s <- dim(MarketSur)
Mt <- vector("numeric", s[1])
for(i in 1:s[1]){
if(max(MarketSur[i,])<0)
{
Mt[i] <- 0
}
else
{
Mt[i] <- which.max(MarketSur[i,])
}

}
return(Mt)
}
Bt <- Prod(MarketSur)
Rev <- vector("numeric",77)
#Rev <- x[Bt]
for(i in 1:77){
if(Bt[i] == 0)
{
Rev[i] = 0
}
else{
Rev[i] = x[Bt[i]]
}
}
Pen <-vector("numeric",12)
Pen[1] <- x[1]-x[4]
Pen[2] <- x[1]-x[5]
Pen[3] <- x[1]-x[7]
Pen[4] <- x[2]-x[4]
Pen[5] <- x[2]-x[6]
Pen[6] <- x[2]-x[7]
Pen[7] <- x[3]-x[5]
Pen[8] <- x[3]-x[6]
Pen[9] <- x[3]-x[7]
Pen[10] <- x[4]-x[7]
Pen[11] <- x[5]-x[7]
Pen[12] <- x[6]-x[7]
for(i in 1:12)
{
if(Pen[i]>0)
{
Pen[i] <- Pen[i]
}
else
{
Pen[i] <- 0
}
}
TotalRev <- sum(Rev) - 500*sum(Pen,na.rm=F)
return(TotalRev)
}

#GAmodel <- rbga.bin(size = 7, popSize = 200, iters = 100, mutationChance = 0.01,
#elitism = T, evalFunc = EvalFunc)
## calculate the optimum solution using Genetic Algorithm
#numvar <- 7
#resultGA <- GA(EvalFunc, optimType="MAX", numVar, numPopulation=20,
#maxIter=100, rangeVar, Pm, Pc)
L <- c(30,30,30,30,30,30,30)
U <- c(100,100,100,100,100,100,100)
suggestedValue <-c(50,35,65,71,71,71,85)
GA <- ga(type = "real-valued", fitness = Func,
lower = L, upper = U,
popSize = 2000, maxiter = 500)
summary(GA)
plot(GA)

--

--

--

MBA, IIM Shillong

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Build a Dashboard Using Google Analytics Embed API Tool

Google’s Director of Research Has An Advice for Beginners in Data Science

Our Data4Governance Experience

L-R: John, Obinna and Tobi

Solving Cold User problem for Recommendation system using Multi-Armed Bandit

Linear Regression in Python; Predict The Bay Area’s Home Prices

Properties of OLS regression estimators

Peter Szaflarski On The Maturity of a Data-Centric Industry

Bayes’ Theorem in Plain English

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Himanshu Bhardwaj

Himanshu Bhardwaj

MBA, IIM Shillong

More from Medium

SciKitLearn with Simple Linear Regression

What these Parsons students wish you’d know before going to fashion school in NYC

Mean. Median. Mode. & More.

10 Kiwi Facts Every New Zealander Must Know