Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. url="http://freakonometrics.free.fr/german_credit.csv"
  2. credit=read.csv(url, header = TRUE, sep = ",")
  3.  
  4. str(credit)
  5.  
  6. F=c(1,2,4,5,7,8,9,10,11,12,13,15,16,17,18,19,20)
  7. for(i in F) credit[,i]=as.factor(credit[,i])
  8.  
  9. i_test=sample(1:nrow(credit),size=333)
  10. i_calibration=(1:nrow(credit))[-i_test]
  11.  
  12. LogisticModel <- glm(Creditability ~ .,
  13. family=binomial,
  14. data = credit[i_calibration,])
  15. summary(LogisticModel)
  16.  
  17.  
  18. install.packages("ROCR")
  19. library(ROCR)
  20.  
  21. fitLog <- predict(LogisticModel,type="response", newdata=credit[i_test,])
  22. pred = prediction( fitLog, credit$Creditability[i_test])
  23. perf <- performance(pred, "tpr", "fpr")
  24. plot(perf)
  25. AUCLog2=performance(pred, measure = "auc")@y.values[[1]]
  26. cat("AUC: ",AUCLog2,"\n")
  27.  
  28. install.packages("randomForest")
  29. library(randomForest)
  30. RF <- randomForest(Creditability ~ .,
  31. data = credit[i_calibration,])
  32. fitForet <- predict(RF,
  33. newdata=credit[i_test,],
  34. type="prob")[,2]
  35. pred = prediction( fitForet, credit$Creditability[i_test])
  36. perf <- performance(pred, "tpr", "fpr")
  37. plot(perf)
  38. AUCRF=performance(pred, measure = "auc")@y.values[[1]]
  39. cat("AUC: ",AUCRF,"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement