Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Clients matrix with data from clientes.txt file
- PATH= "Desktop/Business Intelligence/Tareas/Tarea 2/clientes.txt"
- clients=read.table(PATH, sep = " ")
- #Matrix with only 15 first columns of the original matrix
- names <- c("ClientSubtype", "HouseNum", "HouseInhabitantsNum", "AvgAge", "ClientType", "Religion", "CivilState", "FamilyType", "ScholarEducation", "JobType", "SocialClass", "HouseType", "CarsNum", "HealthType", "AvgIncome")
- M<-clients[,1:15]
- colnames(M) <- names
- #Exercise 1 - Find relevant variables
- stdM <- scale(M)
- corM <- cor(stdM)
- varM <- apply(M, 2, var)
- #Remove variables and transform data into categorical values
- M$ClientSubtype<-NULL #"ClientSubType" was removed due to its high correlation with "ClientType"
- M$HouseNum<-factor(M$HouseNum, labels= c("1","2","3","4","5","6","7","8","10"))
- M$HouseInhabitantsNum<-NULL #factor(M$HouseInhabitantsNum, labels= c("1","2","3","4","5"))
- M$AvgAge<-factor(M$AvgAge, labels = c("20-30","30-40","40-50","50-60","60-70","70-80"))
- M$ClientType<-factor(M$ClientType, labels = c("Successful hedonists", "Driven Growers","Average Family","Career Loners","Living well","Cruising Seniors","Retired and Religeous","Family with grown ups","Conservative families","Farmers"))
- M$Religion<-factor(M$Religion, labels = c("Catholic","Protestant","Other","No religion"))
- M$CivilState<-factor(M$CivilState, labels = c("Married", "cohabitation", "Others"))
- M$FamilyType<-factor(M$FamilyType, labels = c("Single", "Family without children", "Family with children"))
- M$ScholarEducation<-NULL #factor(M$ScholarEducation, labels = c("High", "Mid", "Low"))
- M$JobType<-factor(M$JobType, labels = c("High position", "Enterprising", "Farmer","Middle management", "Qualified worker", "Unqualified worker"))
- M$SocialClass<-factor(M$SocialClass, labels = c("A", "B1", "B2", "C", "D"))
- M$HouseType<-factor(M$HouseType, labels = c("Tenant", "Owner"))
- M$CarsNum<-factor(M$CarsNum, labels = c("One", "Two", "No car"))
- M$HealthType<-factor(M$HealthType, labels = c("Fonasa", "Isapre"))
- M$AvgIncome<-factor(M$AvgIncome, labels = c("Low", "Mid Low", "Medium", "Mid High", "High"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement