Skip to content

Instantly share code, notes, and snippets.

@cseidman

cseidman/buildSp.R Secret

Created Jan 24, 2018
Embed
What would you like to do?
builldsp
library(sqlrutils) # Contains the utiity that lets us create a stored procedure automatically from R code
buildCustomerTree <- function(trainingDs) {
#
# Make factors out of these numbers otherwise they get treated as continuos values
#
trainingDs$TotalChildren <- as.factor(trainingDs$TotalChildren)
trainingDs$NumberChildrenAtHome <- as.factor(trainingDs$NumberChildrenAtHome)
trainingDs$NumberCarsOwned <- as.factor(trainingDs$NumberCarsOwned)
trainingDs$YearsSinceFirstPurchase <- as.factor(trainingDs$YearsSinceFirstPurchase)
trainingDs$AgeRanges <- cut(
trainingDs$Age,breaks=c(0,30,50,70,90),
labels=c("11-30","31-50","51-70","71+")
)
trainingDs$IncomeCategories <- cut(
x=trainingDs$YearlyIncome,
breaks=c(0,20000,50000,70000,100000,250000),
labels=c("Low","Lower","Middle","Upper","Wealthy")
)
tr <- rxDTree(
IsCardUser~
Gender+
Occupation+
MaritalStatus+
IsHomeOwner+
TotalChildren+
NumberCarsOwned+
AgeRanges+
CommuteDistance+
IncomeCategories+
CountryRegionCode+
Education,
data=trainingDs,
method="class",
overwrite = TRUE,
reportProgress = 0,
cp = 0.03
)
trained_model <- rxSerializeModel(tr)
return(list(trained_model=trained_model))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.