글

라벨이 r code_dm인 게시물 표시

결측값(missing value) handling

Boston data [missing vlaue generation] 1. deleting the observations 2. deleting the variable [missing vlaue handling] 3. imputation with mean/median/mode 4. prediction  4.1 KNN imputation  4.2 rpart : decision tree 5. evaluation verification  5.1 mean imputation  5.2 KNN imputation  5.3 rpart R Code  ### Missing Values  ####### # initialize the data  # load the data install.packages("MASS") library(MASS) data(Boston) dim(Boston) original <- Boston  # backup original data # Introduce missing values set.seed(100) Boston[sample(1:nrow(Boston), 40), "rad"] <- NA Boston[sample(1:nrow(Boston), 40), "ptratio"] <- NA head(Boston) # 1. Deleting the observations, if na exist na.omit action, when use lm, omit is default # lm(medv ~ ptratio + rad, data=Boston, na.action=na.omit) lm(medv ~ ptratio + rad, data=Boston) ## 2. Deleting the variable ## when variable missing is many, the variable elim...

판별분석

# 판별분석 실행 library(MASS) alcohol.lda <- lda(TYPE~. , data=alcohol.data)   # TYPE은 그룹변수, 나머지 변수 모두 사용 alcohol.lda