Last active
December 19, 2015 01:58
-
-
Save dylanjf/5879356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###"naive bayesian" approach... if matched in training to test, return the probability that the person | |
was accepted over all training examples### | |
#concatenate all base variables except for RESOURCE | |
train_person = paste(amazon_Xtrain[,2],amazon_Xtrain[,3],amazon_Xtrain[,4], | |
amazon_Xtrain[,5],amazon_Xtrain[,6],amazon_Xtrain[,7],amazon_Xtrain[,8], sep = "") | |
test_person = paste(amazon_Xtest[,2],amazon_Xtest[,3],amazon_Xtest[,4], | |
amazon_Xtest[,5],amazon_Xtest[,6],amazon_Xtest[,7],amazon_Xtest[,8], sep = "") | |
#map probability by person | |
amazon_Xtrain_person_action = as.data.frame(cbind(train_person, amazon_Ytrain)) | |
colnames(amazon_Xtrain_person_action) = c("person", "action") | |
amazon_Xtrain_person_action$action = as.integer(amazon_Xtrain_person_action$action) - 1 #sets 2 level factor range to [0,1] | |
probability = aggregate(action ~ person, data = amazon_Xtrain_person_action, mean) | |
amazon_Xtrain_person_action$probability = probability[,2][match(amazon_Xtrain_person_action[,1], probability[,1])] | |
#apply prediction to matched entries | |
nb_predict = numeric() | |
nb_predict = amazon_Xtrain_person_action$probability[match(test_person,train_person)] | |
#fill in NA's with best model's predictions | |
nb_predict[which(!complete.cases(nb_predict))] = best_pred[,11][which(!complete.cases(nb_predict))] | |
nb_predict = as.matrix(nb_predict) | |
write.csv(nb_predict, "C:/Users/dylanjf/Desktop/amazon/submission14.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment