Guest User

Untitled

a guest
Nov 18th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. ###### MICE PACKAGE ######
  2. library(mice)
  3. library(class)
  4. library(missForest)
  5.  
  6. MyData <- iris
  7. #generate random "2%" missing values
  8. MissingData <- prodNA(MyData[-5], noNA = 0.02)
  9. #using mic to impute iris Data set
  10. #using method pmm (Predictive Mean Matching) for numeric variables
  11. ImputedData <- mice(MissingData, m=3, maxit = 20, method = 'pmm', seed = 222)
  12. MytestData <- complete(ImputedData,1) #testdata
  13. #using k-NN classifier
  14. predict_species_class<- knn(train = MyData[-5], test = MytestData, cl=MyData$Species , k = 3,prob=TRUE)
  15. #using confusion matrix to look the performance of k-NN classifier
  16. confusionMatrix(MyData$Species,predict_species_class)
  17. #Root mean square error between imputed Data and MytestData
  18. RMSE(MyData[-5],MytestData)
  19.  
  20.  
  21. ###### MICE PACKAGE ######
  22. library(mice)
  23. library(class)
  24. library(missForest)
  25.  
  26. MyData <- iris
  27. #generate random "5%" missing values
  28. MissingData <- prodNA(MyData[-5], noNA = 0.05)
  29. #using mic to impute iris Data set
  30. #using method pmm (Predictive Mean Matching) for numeric variables
  31. ImputedData <- mice(MissingData, m=3, maxit = 20, method = 'pmm', seed = 222)
  32. MytestData <- complete(ImputedData,1) #testdata
  33. #using k-NN classifier
  34. predict_species_class<- knn(train = MyData[-5], test = MytestData, cl=MyData$Species , k = 3,prob=TRUE)
  35. #using confusion matrix to look the performance of k-NN classifier
  36. confusionMatrix(MyData$Species,predict_species_class)
  37. #Root mean square error between imputed Data and MytestData
  38. RMSE(MyData[-5],MytestData)
  39.  
  40.  
  41. ###### MICE PACKAGE ######
  42. library(mice)
  43. library(class)
  44. library(missForest)
  45.  
  46. MyData <- iris
  47. #generate random "10%" missing values
  48. MissingData <- prodNA(MyData[-5], noNA = 0.1)
  49. #using mic to impute iris Data set
  50. #using method pmm (Predictive Mean Matching) for numeric variables
  51. ImputedData <- mice(MissingData, m=3, maxit = 20, method = 'pmm', seed = 222)
  52. MytestData <- complete(ImputedData,1) #testdata
  53. #using k-NN classifier
  54. predict_species_class<- knn(train = MyData[-5], test = MytestData, cl=MyData$Species , k = 3,prob=TRUE)
  55. #using confusion matrix to look the performance of k-NN classifier
  56. confusionMatrix(MyData$Species,predict_species_class)
  57. #Root mean square error between imputed Data and MytestData
  58. RMSE(MyData[-5],MytestData)
  59.  
  60.  
  61. ###### MICE PACKAGE ######
  62. library(mice)
  63. library(class)
  64. library(missForest)
  65.  
  66. MyData <- iris
  67. #generate random "15%" missing values
  68. MissingData <- prodNA(MyData[-5], noNA = 0.15)
  69. #using mic to impute iris Data set
  70. #using method pmm (Predictive Mean Matching) for numeric variables
  71. ImputedData <- mice(MissingData, m=3, maxit = 20, method = 'pmm', seed = 222)
  72. MytestData <- complete(ImputedData,1) #testdata
  73. #using k-NN classifier
  74. predict_species_class<- knn(train = MyData[-5], test = MytestData, cl=MyData$Species , k = 3,prob=TRUE)
  75. #using confusion matrix to look the performance of k-NN classifier
  76. confusionMatrix(MyData$Species,predict_species_class)
  77. #Root mean square error between imputed Data and MytestData
  78. RMSE(MyData[-5],MytestData)
  79.  
  80.  
  81. ###### MICE PACKAGE ######
  82. library(mice)
  83. library(class)
  84. library(missForest)
  85.  
  86. MyData <- iris
  87. #generate random "20%" missing values
  88. MissingData <- prodNA(MyData[-5], noNA = 0.2)
  89. #using mic to impute iris Data set
  90. #using method pmm (Predictive Mean Matching) for numeric variables
  91. ImputedData <- mice(MissingData, m=3, maxit = 20, method = 'pmm', seed = 222)
  92. MytestData <- complete(ImputedData,1) #testdata
  93. #using k-NN classifier
  94. predict_species_class<- knn(train = MyData[-5], test = MytestData, cl=MyData$Species , k = 3,prob=TRUE)
  95. #using confusion matrix to look the performance of k-NN classifier
  96. confusionMatrix(MyData$Species,predict_species_class)
  97. #Root mean square error between imputed Data and MytestData
  98. RMSE(MyData[-5],MytestData)
  99.  
  100.  
  101.  
  102.  
  103. ###### MICE PACKAGE ######
  104. library(mice)
  105. library(class)
  106. library(missForest)
  107.  
  108. MyData <- iris
  109. #generate random "25%" missing values
  110. MissingData <- prodNA(MyData[-5], noNA = 0.25)
  111. #using mic to impute iris Data set
  112. #using method pmm (Predictive Mean Matching) for numeric variables
  113. ImputedData <- mice(MissingData, m=3, maxit = 20, method = 'pmm', seed = 222)
  114. MytestData <- complete(ImputedData,1) #testdata
  115. #using k-NN classifier
  116. predict_species_class<- knn(train = MyData[-5], test = MytestData, cl=MyData$Species , k = 3,prob=TRUE)
  117. #using confusion matrix to look the performance of k-NN classifier
  118. confusionMatrix(MyData$Species,predict_species_class)
  119. #Root mean square error between imputed Data and MytestData
  120. RMSE(MyData[-5],MytestData)
Add Comment
Please, Sign In to add comment