getwd()
## [1] "C:/Users/KoRoad/Desktop/빅데이터 분석 교육"
setwd("c:/data")
getwd()
## [1] "c:/data"
ls()
## character(0)
library(dplyr)
## 
## 다음의 패키지를 부착합니다: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
set.seed(1)
data("iris")
library(caret)
## 필요한 패키지를 로딩중입니다: ggplot2
## 필요한 패키지를 로딩중입니다: lattice
idx<-createDataPartition(iris$Species,p=0.8,list=FALSE)
train<-iris[idx,] #반복적으로 사용함
test<-iris[-idx,] #반복적으로 사용함
nrow(train)
## [1] 120
nrow(test)
## [1] 30
#6:2:2 분할
set.seed(2)
data("iris")
idx<-createDataPartition(iris$Species,p=0.6,list=FALSE)
train<-iris[idx,]
valid_test<-iris[-idx,]
idx2<-createDataPartition(valid_test$Species,p=0.5,list=FALSE)
valid<-valid_test[idx2,]
test<-valid_test[-idx2,]
nrow(train)/nrow(iris)
## [1] 0.6
nrow(valid)/nrow(iris)
## [1] 0.2
nrow(test)/nrow(iris)
## [1] 0.2
#Z-score 표준화
data("iris")
zs_iris<-preProcess(iris,method = c("center","scale"))
zs_iris
## Created from 150 samples and 5 variables
## 
## Pre-processing:
##   - centered (4)
##   - ignored (1)
##   - scaled (4)
zs_iris_p<-predict(zs_iris,iris)

library(psych)
## 
## 다음의 패키지를 부착합니다: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
describe(zs_iris_p[,1:4])
##              vars   n mean sd median trimmed  mad   min  max range  skew
## Sepal.Length    1 150    0  1  -0.05   -0.04 1.25 -1.86 2.48  4.35  0.31
## Sepal.Width     2 150    0  1  -0.13   -0.03 1.02 -2.43 3.08  5.51  0.31
## Petal.Length    3 150    0  1   0.34    0.00 1.05 -1.56 1.78  3.34 -0.27
## Petal.Width     4 150    0  1   0.13   -0.02 1.36 -1.44 1.71  3.15 -0.10
##              kurtosis   se
## Sepal.Length    -0.61 0.08
## Sepal.Width      0.14 0.08
## Petal.Length    -1.42 0.08
## Petal.Width     -1.36 0.08
library(caret)
data("iris")
sca_iris<-preProcess(iris,method = "range") # 데이터를 [0,1] 사이의 값으로 조정
sca_iris
## Created from 150 samples and 5 variables
## 
## Pre-processing:
##   - ignored (1)
##   - re-scaling to [0, 1] (4)
sca_iris_p<-predict(sca_iris,iris)
head(sca_iris_p)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1   0.22222222   0.6250000   0.06779661  0.04166667  setosa
## 2   0.16666667   0.4166667   0.06779661  0.04166667  setosa
## 3   0.11111111   0.5000000   0.05084746  0.04166667  setosa
## 4   0.08333333   0.4583333   0.08474576  0.04166667  setosa
## 5   0.19444444   0.6666667   0.06779661  0.04166667  setosa
## 6   0.30555556   0.7916667   0.11864407  0.12500000  setosa
library(psych)
describe(sca_iris_p)
##              vars   n mean   sd median trimmed  mad min max range  skew
## Sepal.Length    1 150 0.43 0.23   0.42    0.42 0.29   0   1     1  0.31
## Sepal.Width     2 150 0.44 0.18   0.42    0.43 0.19   0   1     1  0.31
## Petal.Length    3 150 0.47 0.30   0.57    0.47 0.31   0   1     1 -0.27
## Petal.Width     4 150 0.46 0.32   0.50    0.45 0.43   0   1     1 -0.10
## Species*        5 150 2.00 0.82   2.00    2.00 1.48   1   3     2  0.00
##              kurtosis   se
## Sepal.Length    -0.61 0.02
## Sepal.Width      0.14 0.01
## Petal.Length    -1.42 0.02
## Petal.Width     -1.36 0.03
## Species*        -1.52 0.07
# BoxCox는 옵션임 해도 되고 안해도 되고(성능을 높이기 위해서 하는 전처리 작업)
library(caret)
data("iris")
bc_iris<-preProcess(iris,method = "BoxCox")
bc_iris
## Created from 150 samples and 5 variables
## 
## Pre-processing:
##   - Box-Cox transformation (4)
##   - ignored (1)
## 
## Lambda estimates for Box-Cox transformation:
## -0.1, 0.3, 0.9, 0.6
bc_iris_t<-predict(bc_iris,iris)
head(bc_iris_t)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1     1.629241    1.520660          1.4  -1.0321154  setosa
## 2     1.589235    1.301297          1.4  -1.0321154  setosa
## 3     1.547563    1.391905          1.3  -1.0321154  setosa
## 4     1.526056    1.347113          1.5  -1.0321154  setosa
## 5     1.609438    1.561856          1.4  -1.0321154  setosa
## 6     1.686399    1.680826          1.7  -0.7048667  setosa
par(mfrow=c(1,2)) #화면분활 어떻게 할지 정하는것
plot(density(x=iris$Sepal.Width))
plot(density(x=bc_iris_t$Sepal.Width)) #좌우대칭 형태로 바뀜

#PCA(분산이 최대로 되는 주성분 분석-차원축소)
library(caret)
data("iris")
pca_iris<-preProcess(iris,method = "pca")
pca_iris
## Created from 150 samples and 5 variables
## 
## Pre-processing:
##   - centered (4)
##   - ignored (1)
##   - principal component signal extraction (4)
##   - scaled (4)
## 
## PCA needed 2 components to capture 95 percent of the variance
pca_iris_p<-predict(pca_iris,iris)
head(pca_iris_p)
##   Species       PC1        PC2
## 1  setosa -2.257141 -0.4784238
## 2  setosa -2.074013  0.6718827
## 3  setosa -2.356335  0.3407664
## 4  setosa -2.291707  0.5953999
## 5  setosa -2.381863 -0.6446757
## 6  setosa -2.068701 -1.4842053
# 더미 변수 생성

library(earth)
## 필요한 패키지를 로딩중입니다: Formula
## 필요한 패키지를 로딩중입니다: plotmo
## 필요한 패키지를 로딩중입니다: plotrix
## 
## 다음의 패키지를 부착합니다: 'plotrix'
## The following object is masked from 'package:psych':
## 
##     rescale
## 필요한 패키지를 로딩중입니다: TeachingDemos
data("etitanic")
library(dplyr)
glimpse(etitanic)
## Rows: 1,046
## Columns: 6
## $ pclass   <fct> 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1st, 1…
## $ survived <int> 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1…
## $ sex      <fct> female, male, female, male, female, male, female, male, femal…
## $ age      <dbl> 29.0000, 0.9167, 2.0000, 30.0000, 25.0000, 48.0000, 63.0000, …
## $ sibsp    <int> 0, 1, 1, 1, 1, 0, 1, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1…
## $ parch    <int> 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1…
dummies<-dummyVars(survived~.,data=etitanic)
dummies
## Dummy Variable Object
## 
## Formula: survived ~ .
## 6 variables, 2 factors
## Variables and levels will be separated by '.'
## A less than full rank encoding is used
head(predict(dummies,newdata = etitanic))
##   pclass.1st pclass.2nd pclass.3rd sex.female sex.male     age sibsp parch
## 1          1          0          0          1        0 29.0000     0     0
## 2          1          0          0          0        1  0.9167     1     2
## 3          1          0          0          1        0  2.0000     1     2
## 4          1          0          0          0        1 30.0000     1     2
## 5          1          0          0          1        0 25.0000     1     2
## 6          1          0          0          0        1 48.0000     0     0
#결측치 대체
data("airquality")
colSums(is.na(airquality)) # 결측값 갯수 확인
##   Ozone Solar.R    Wind    Temp   Month     Day 
##      37       7       0       0       0       0
library(RANN)
head(airquality)
##   Ozone Solar.R Wind Temp Month Day
## 1    41     190  7.4   67     5   1
## 2    36     118  8.0   72     5   2
## 3    12     149 12.6   74     5   3
## 4    18     313 11.5   62     5   4
## 5    NA      NA 14.3   56     5   5
## 6    28      NA 14.9   66     5   6
knn_im<-preProcess(airquality[1:4],method = "knnImpute") #결측값 대체
head(predict(knn_im,airquality))
##         Ozone     Solar.R       Wind       Temp Month Day
## 1 -0.03423409  0.04517615 -0.7259482 -1.1497140     5   1
## 2 -0.18580489 -0.75430487 -0.5556388 -0.6214670     5   2
## 3 -0.91334473 -0.41008388  0.7500660 -0.4101682     5   3
## 4 -0.73145977  1.41095624  0.4378323 -1.6779609     5   4
## 5 -0.69508278 -0.92308420  1.2326091 -2.3118573     5   5
## 6 -0.42831817 -0.28349938  1.4029185 -1.2553634     5   6
knn_im_p<-predict(knn_im,airquality)
colSums(is.na(knn_im_p))
##   Ozone Solar.R    Wind    Temp   Month     Day 
##       0       0       0       0       0       0
median_im<-preProcess(airquality[1:4],method = "medianImpute") #결측값을 중앙값으로 대체
head(predict(median_im,airquality))
##   Ozone Solar.R Wind Temp Month Day
## 1  41.0     190  7.4   67     5   1
## 2  36.0     118  8.0   72     5   2
## 3  12.0     149 12.6   74     5   3
## 4  18.0     313 11.5   62     5   4
## 5  31.5     205 14.3   56     5   5
## 6  28.0     205 14.9   66     5   6
#Scatter Plots
library(mlbench)
data("BostonHousing")
glimpse(BostonHousing)
## Rows: 506
## Columns: 14
## $ crim    <dbl> 0.00632, 0.02731, 0.02729, 0.03237, 0.06905, 0.02985, 0.08829,…
## $ zn      <dbl> 18.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.5, 12.5, 12.5, 12.5, 12.5, 1…
## $ indus   <dbl> 2.31, 7.07, 7.07, 2.18, 2.18, 2.18, 7.87, 7.87, 7.87, 7.87, 7.…
## $ chas    <fct> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ nox     <dbl> 0.538, 0.469, 0.469, 0.458, 0.458, 0.458, 0.524, 0.524, 0.524,…
## $ rm      <dbl> 6.575, 6.421, 7.185, 6.998, 7.147, 6.430, 6.012, 6.172, 5.631,…
## $ age     <dbl> 65.2, 78.9, 61.1, 45.8, 54.2, 58.7, 66.6, 96.1, 100.0, 85.9, 9…
## $ dis     <dbl> 4.0900, 4.9671, 4.9671, 6.0622, 6.0622, 6.0622, 5.5605, 5.9505…
## $ rad     <dbl> 1, 2, 2, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,…
## $ tax     <dbl> 296, 242, 242, 222, 222, 222, 311, 311, 311, 311, 311, 311, 31…
## $ ptratio <dbl> 15.3, 17.8, 17.8, 18.7, 18.7, 18.7, 15.2, 15.2, 15.2, 15.2, 15…
## $ b       <dbl> 396.90, 396.90, 392.83, 394.63, 396.90, 394.12, 395.60, 396.90…
## $ lstat   <dbl> 4.98, 9.14, 4.03, 2.94, 5.33, 5.21, 12.43, 19.15, 29.93, 17.10…
## $ medv    <dbl> 24.0, 21.6, 34.7, 33.4, 36.2, 28.7, 22.9, 27.1, 16.5, 18.9, 15…
x<-BostonHousing[,c("age","lstat","tax")]
y<-BostonHousing$medv
featurePlot(x,y=BostonHousing$medv,plot = "scatter",layout=c(3,1))

#변수선택
library(mlbench)
library(dplyr)
library(caret)
data(PimaIndiansDiabetes)
glimpse(PimaIndiansDiabetes)
## Rows: 768
## Columns: 9
## $ pregnant <dbl> 6, 1, 8, 1, 0, 5, 3, 10, 2, 8, 4, 10, 10, 1, 5, 7, 0, 7, 1, 1…
## $ glucose  <dbl> 148, 85, 183, 89, 137, 116, 78, 115, 197, 125, 110, 168, 139,…
## $ pressure <dbl> 72, 66, 64, 66, 40, 74, 50, 0, 70, 96, 92, 74, 80, 60, 72, 0,…
## $ triceps  <dbl> 35, 29, 0, 23, 35, 0, 32, 0, 45, 0, 0, 0, 0, 23, 19, 0, 47, 0…
## $ insulin  <dbl> 0, 0, 0, 94, 168, 0, 88, 0, 543, 0, 0, 0, 0, 846, 175, 0, 230…
## $ mass     <dbl> 33.6, 26.6, 23.3, 28.1, 43.1, 25.6, 31.0, 35.3, 30.5, 0.0, 37…
## $ pedigree <dbl> 0.627, 0.351, 0.672, 0.167, 2.288, 0.201, 0.248, 0.134, 0.158…
## $ age      <dbl> 50, 31, 32, 21, 33, 30, 26, 29, 53, 54, 30, 34, 57, 59, 51, 3…
## $ diabetes <fct> pos, neg, pos, neg, pos, neg, pos, neg, pos, pos, neg, pos, n…
PimaIndiansDiabetes %>% count(diabetes)
##   diabetes   n
## 1      neg 500
## 2      pos 268
control<-trainControl(method = "repeatedcv",number = 5) #repeatedcv -> cv 가능
model<-train(diabetes~.,data=PimaIndiansDiabetes,method="rf",
             preProcess=c("center","scale"),trControl=control)
model
## Random Forest 
## 
## 768 samples
##   8 predictor
##   2 classes: 'neg', 'pos' 
## 
## Pre-processing: centered (8), scaled (8) 
## Resampling: Cross-Validated (5 fold, repeated 1 times) 
## Summary of sample sizes: 615, 614, 614, 615, 614 
## Resampling results across tuning parameters:
## 
##   mtry  Accuracy   Kappa    
##   2     0.7694848  0.4809709
##   5     0.7577710  0.4552707
##   8     0.7538664  0.4471454
## 
## Accuracy was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 2.
importance<-varImp(model,scale = FALSE)
print(importance)
## rf variable importance
## 
##          Overall
## glucose    91.28
## mass       57.41
## age        46.74
## pedigree   42.62
## pressure   31.33
## pregnant   29.25
## insulin    24.83
## triceps    23.59
plot(importance)

model1<-train(diabetes~.,data=PimaIndiansDiabetes,method="knn",
             preProcess=c("center","scale"),trControl=control)
model1
## k-Nearest Neighbors 
## 
## 768 samples
##   8 predictor
##   2 classes: 'neg', 'pos' 
## 
## Pre-processing: centered (8), scaled (8) 
## Resampling: Cross-Validated (5 fold, repeated 1 times) 
## Summary of sample sizes: 615, 615, 614, 614, 614 
## Resampling results across tuning parameters:
## 
##   k  Accuracy   Kappa    
##   5  0.7291147  0.3818076
##   7  0.7448010  0.4207935
##   9  0.7422205  0.4098283
## 
## Accuracy was used to select the optimal model using the largest value.
## The final value used for the model was k = 7.
data("Sonar")
glimpse(Sonar)
## Rows: 208
## Columns: 61
## $ V1    <dbl> 0.0200, 0.0453, 0.0262, 0.0100, 0.0762, 0.0286, 0.0317, 0.0519, …
## $ V2    <dbl> 0.0371, 0.0523, 0.0582, 0.0171, 0.0666, 0.0453, 0.0956, 0.0548, …
## $ V3    <dbl> 0.0428, 0.0843, 0.1099, 0.0623, 0.0481, 0.0277, 0.1321, 0.0842, …
## $ V4    <dbl> 0.0207, 0.0689, 0.1083, 0.0205, 0.0394, 0.0174, 0.1408, 0.0319, …
## $ V5    <dbl> 0.0954, 0.1183, 0.0974, 0.0205, 0.0590, 0.0384, 0.1674, 0.1158, …
## $ V6    <dbl> 0.0986, 0.2583, 0.2280, 0.0368, 0.0649, 0.0990, 0.1710, 0.0922, …
## $ V7    <dbl> 0.1539, 0.2156, 0.2431, 0.1098, 0.1209, 0.1201, 0.0731, 0.1027, …
## $ V8    <dbl> 0.1601, 0.3481, 0.3771, 0.1276, 0.2467, 0.1833, 0.1401, 0.0613, …
## $ V9    <dbl> 0.3109, 0.3337, 0.5598, 0.0598, 0.3564, 0.2105, 0.2083, 0.1465, …
## $ V10   <dbl> 0.2111, 0.2872, 0.6194, 0.1264, 0.4459, 0.3039, 0.3513, 0.2838, …
## $ V11   <dbl> 0.1609, 0.4918, 0.6333, 0.0881, 0.4152, 0.2988, 0.1786, 0.2802, …
## $ V12   <dbl> 0.1582, 0.6552, 0.7060, 0.1992, 0.3952, 0.4250, 0.0658, 0.3086, …
## $ V13   <dbl> 0.2238, 0.6919, 0.5544, 0.0184, 0.4256, 0.6343, 0.0513, 0.2657, …
## $ V14   <dbl> 0.0645, 0.7797, 0.5320, 0.2261, 0.4135, 0.8198, 0.3752, 0.3801, …
## $ V15   <dbl> 0.0660, 0.7464, 0.6479, 0.1729, 0.4528, 1.0000, 0.5419, 0.5626, …
## $ V16   <dbl> 0.2273, 0.9444, 0.6931, 0.2131, 0.5326, 0.9988, 0.5440, 0.4376, …
## $ V17   <dbl> 0.3100, 1.0000, 0.6759, 0.0693, 0.7306, 0.9508, 0.5150, 0.2617, …
## $ V18   <dbl> 0.2999, 0.8874, 0.7551, 0.2281, 0.6193, 0.9025, 0.4262, 0.1199, …
## $ V19   <dbl> 0.5078, 0.8024, 0.8929, 0.4060, 0.2032, 0.7234, 0.2024, 0.6676, …
## $ V20   <dbl> 0.4797, 0.7818, 0.8619, 0.3973, 0.4636, 0.5122, 0.4233, 0.9402, …
## $ V21   <dbl> 0.5783, 0.5212, 0.7974, 0.2741, 0.4148, 0.2074, 0.7723, 0.7832, …
## $ V22   <dbl> 0.5071, 0.4052, 0.6737, 0.3690, 0.4292, 0.3985, 0.9735, 0.5352, …
## $ V23   <dbl> 0.4328, 0.3957, 0.4293, 0.5556, 0.5730, 0.5890, 0.9390, 0.6809, …
## $ V24   <dbl> 0.5550, 0.3914, 0.3648, 0.4846, 0.5399, 0.2872, 0.5559, 0.9174, …
## $ V25   <dbl> 0.6711, 0.3250, 0.5331, 0.3140, 0.3161, 0.2043, 0.5268, 0.7613, …
## $ V26   <dbl> 0.6415, 0.3200, 0.2413, 0.5334, 0.2285, 0.5782, 0.6826, 0.8220, …
## $ V27   <dbl> 0.7104, 0.3271, 0.5070, 0.5256, 0.6995, 0.5389, 0.5713, 0.8872, …
## $ V28   <dbl> 0.8080, 0.2767, 0.8533, 0.2520, 1.0000, 0.3750, 0.5429, 0.6091, …
## $ V29   <dbl> 0.6791, 0.4423, 0.6036, 0.2090, 0.7262, 0.3411, 0.2177, 0.2967, …
## $ V30   <dbl> 0.3857, 0.2028, 0.8514, 0.3559, 0.4724, 0.5067, 0.2149, 0.1103, …
## $ V31   <dbl> 0.1307, 0.3788, 0.8512, 0.6260, 0.5103, 0.5580, 0.5811, 0.1318, …
## $ V32   <dbl> 0.2604, 0.2947, 0.5045, 0.7340, 0.5459, 0.4778, 0.6323, 0.0624, …
## $ V33   <dbl> 0.5121, 0.1984, 0.1862, 0.6120, 0.2881, 0.3299, 0.2965, 0.0990, …
## $ V34   <dbl> 0.7547, 0.2341, 0.2709, 0.3497, 0.0981, 0.2198, 0.1873, 0.4006, …
## $ V35   <dbl> 0.8537, 0.1306, 0.4232, 0.3953, 0.1951, 0.1407, 0.2969, 0.3666, …
## $ V36   <dbl> 0.8507, 0.4182, 0.3043, 0.3012, 0.4181, 0.2856, 0.5163, 0.1050, …
## $ V37   <dbl> 0.6692, 0.3835, 0.6116, 0.5408, 0.4604, 0.3807, 0.6153, 0.1915, …
## $ V38   <dbl> 0.6097, 0.1057, 0.6756, 0.8814, 0.3217, 0.4158, 0.4283, 0.3930, …
## $ V39   <dbl> 0.4943, 0.1840, 0.5375, 0.9857, 0.2828, 0.4054, 0.5479, 0.4288, …
## $ V40   <dbl> 0.2744, 0.1970, 0.4719, 0.9167, 0.2430, 0.3296, 0.6133, 0.2546, …
## $ V41   <dbl> 0.0510, 0.1674, 0.4647, 0.6121, 0.1979, 0.2707, 0.5017, 0.1151, …
## $ V42   <dbl> 0.2834, 0.0583, 0.2587, 0.5006, 0.2444, 0.2650, 0.2377, 0.2196, …
## $ V43   <dbl> 0.2825, 0.1401, 0.2129, 0.3210, 0.1847, 0.0723, 0.1957, 0.1879, …
## $ V44   <dbl> 0.4256, 0.1628, 0.2222, 0.3202, 0.0841, 0.1238, 0.1749, 0.1437, …
## $ V45   <dbl> 0.2641, 0.0621, 0.2111, 0.4295, 0.0692, 0.1192, 0.1304, 0.2146, …
## $ V46   <dbl> 0.1386, 0.0203, 0.0176, 0.3654, 0.0528, 0.1089, 0.0597, 0.2360, …
## $ V47   <dbl> 0.1051, 0.0530, 0.1348, 0.2655, 0.0357, 0.0623, 0.1124, 0.1125, …
## $ V48   <dbl> 0.1343, 0.0742, 0.0744, 0.1576, 0.0085, 0.0494, 0.1047, 0.0254, …
## $ V49   <dbl> 0.0383, 0.0409, 0.0130, 0.0681, 0.0230, 0.0264, 0.0507, 0.0285, …
## $ V50   <dbl> 0.0324, 0.0061, 0.0106, 0.0294, 0.0046, 0.0081, 0.0159, 0.0178, …
## $ V51   <dbl> 0.0232, 0.0125, 0.0033, 0.0241, 0.0156, 0.0104, 0.0195, 0.0052, …
## $ V52   <dbl> 0.0027, 0.0084, 0.0232, 0.0121, 0.0031, 0.0045, 0.0201, 0.0081, …
## $ V53   <dbl> 0.0065, 0.0089, 0.0166, 0.0036, 0.0054, 0.0014, 0.0248, 0.0120, …
## $ V54   <dbl> 0.0159, 0.0048, 0.0095, 0.0150, 0.0105, 0.0038, 0.0131, 0.0045, …
## $ V55   <dbl> 0.0072, 0.0094, 0.0180, 0.0085, 0.0110, 0.0013, 0.0070, 0.0121, …
## $ V56   <dbl> 0.0167, 0.0191, 0.0244, 0.0073, 0.0015, 0.0089, 0.0138, 0.0097, …
## $ V57   <dbl> 0.0180, 0.0140, 0.0316, 0.0050, 0.0072, 0.0057, 0.0092, 0.0085, …
## $ V58   <dbl> 0.0084, 0.0049, 0.0164, 0.0044, 0.0048, 0.0027, 0.0143, 0.0047, …
## $ V59   <dbl> 0.0090, 0.0052, 0.0095, 0.0040, 0.0107, 0.0051, 0.0036, 0.0048, …
## $ V60   <dbl> 0.0032, 0.0044, 0.0078, 0.0117, 0.0094, 0.0062, 0.0103, 0.0053, …
## $ Class <fct> R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R…
summary(Sonar)
##        V1                V2                V3                V4         
##  Min.   :0.00150   Min.   :0.00060   Min.   :0.00150   Min.   :0.00580  
##  1st Qu.:0.01335   1st Qu.:0.01645   1st Qu.:0.01895   1st Qu.:0.02438  
##  Median :0.02280   Median :0.03080   Median :0.03430   Median :0.04405  
##  Mean   :0.02916   Mean   :0.03844   Mean   :0.04383   Mean   :0.05389  
##  3rd Qu.:0.03555   3rd Qu.:0.04795   3rd Qu.:0.05795   3rd Qu.:0.06450  
##  Max.   :0.13710   Max.   :0.23390   Max.   :0.30590   Max.   :0.42640  
##        V5                V6                V7               V8         
##  Min.   :0.00670   Min.   :0.01020   Min.   :0.0033   Min.   :0.00550  
##  1st Qu.:0.03805   1st Qu.:0.06703   1st Qu.:0.0809   1st Qu.:0.08042  
##  Median :0.06250   Median :0.09215   Median :0.1070   Median :0.11210  
##  Mean   :0.07520   Mean   :0.10457   Mean   :0.1217   Mean   :0.13480  
##  3rd Qu.:0.10028   3rd Qu.:0.13412   3rd Qu.:0.1540   3rd Qu.:0.16960  
##  Max.   :0.40100   Max.   :0.38230   Max.   :0.3729   Max.   :0.45900  
##        V9               V10              V11              V12        
##  Min.   :0.00750   Min.   :0.0113   Min.   :0.0289   Min.   :0.0236  
##  1st Qu.:0.09703   1st Qu.:0.1113   1st Qu.:0.1293   1st Qu.:0.1335  
##  Median :0.15225   Median :0.1824   Median :0.2248   Median :0.2490  
##  Mean   :0.17800   Mean   :0.2083   Mean   :0.2360   Mean   :0.2502  
##  3rd Qu.:0.23342   3rd Qu.:0.2687   3rd Qu.:0.3016   3rd Qu.:0.3312  
##  Max.   :0.68280   Max.   :0.7106   Max.   :0.7342   Max.   :0.7060  
##       V13              V14              V15              V16        
##  Min.   :0.0184   Min.   :0.0273   Min.   :0.0031   Min.   :0.0162  
##  1st Qu.:0.1661   1st Qu.:0.1752   1st Qu.:0.1646   1st Qu.:0.1963  
##  Median :0.2640   Median :0.2811   Median :0.2817   Median :0.3047  
##  Mean   :0.2733   Mean   :0.2966   Mean   :0.3202   Mean   :0.3785  
##  3rd Qu.:0.3513   3rd Qu.:0.3862   3rd Qu.:0.4529   3rd Qu.:0.5357  
##  Max.   :0.7131   Max.   :0.9970   Max.   :1.0000   Max.   :0.9988  
##       V17              V18              V19              V20        
##  Min.   :0.0349   Min.   :0.0375   Min.   :0.0494   Min.   :0.0656  
##  1st Qu.:0.2059   1st Qu.:0.2421   1st Qu.:0.2991   1st Qu.:0.3506  
##  Median :0.3084   Median :0.3683   Median :0.4350   Median :0.5425  
##  Mean   :0.4160   Mean   :0.4523   Mean   :0.5048   Mean   :0.5630  
##  3rd Qu.:0.6594   3rd Qu.:0.6791   3rd Qu.:0.7314   3rd Qu.:0.8093  
##  Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
##       V21              V22              V23              V24        
##  Min.   :0.0512   Min.   :0.0219   Min.   :0.0563   Min.   :0.0239  
##  1st Qu.:0.3997   1st Qu.:0.4069   1st Qu.:0.4502   1st Qu.:0.5407  
##  Median :0.6177   Median :0.6649   Median :0.6997   Median :0.6985  
##  Mean   :0.6091   Mean   :0.6243   Mean   :0.6470   Mean   :0.6727  
##  3rd Qu.:0.8170   3rd Qu.:0.8320   3rd Qu.:0.8486   3rd Qu.:0.8722  
##  Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
##       V25              V26              V27              V28        
##  Min.   :0.0240   Min.   :0.0921   Min.   :0.0481   Min.   :0.0284  
##  1st Qu.:0.5258   1st Qu.:0.5442   1st Qu.:0.5319   1st Qu.:0.5348  
##  Median :0.7211   Median :0.7545   Median :0.7456   Median :0.7319  
##  Mean   :0.6754   Mean   :0.6999   Mean   :0.7022   Mean   :0.6940  
##  3rd Qu.:0.8737   3rd Qu.:0.8938   3rd Qu.:0.9171   3rd Qu.:0.9003  
##  Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
##       V29              V30              V31              V32        
##  Min.   :0.0144   Min.   :0.0613   Min.   :0.0482   Min.   :0.0404  
##  1st Qu.:0.4637   1st Qu.:0.4114   1st Qu.:0.3456   1st Qu.:0.2814  
##  Median :0.6808   Median :0.6071   Median :0.4904   Median :0.4296  
##  Mean   :0.6421   Mean   :0.5809   Mean   :0.5045   Mean   :0.4390  
##  3rd Qu.:0.8521   3rd Qu.:0.7352   3rd Qu.:0.6420   3rd Qu.:0.5803  
##  Max.   :1.0000   Max.   :1.0000   Max.   :0.9657   Max.   :0.9306  
##       V33              V34              V35              V36        
##  Min.   :0.0477   Min.   :0.0212   Min.   :0.0223   Min.   :0.0080  
##  1st Qu.:0.2579   1st Qu.:0.2176   1st Qu.:0.1794   1st Qu.:0.1543  
##  Median :0.3912   Median :0.3510   Median :0.3127   Median :0.3211  
##  Mean   :0.4172   Mean   :0.4032   Mean   :0.3926   Mean   :0.3848  
##  3rd Qu.:0.5561   3rd Qu.:0.5961   3rd Qu.:0.5934   3rd Qu.:0.5565  
##  Max.   :1.0000   Max.   :0.9647   Max.   :1.0000   Max.   :1.0000  
##       V37              V38              V39              V40        
##  Min.   :0.0351   Min.   :0.0383   Min.   :0.0371   Min.   :0.0117  
##  1st Qu.:0.1601   1st Qu.:0.1743   1st Qu.:0.1740   1st Qu.:0.1865  
##  Median :0.3063   Median :0.3127   Median :0.2835   Median :0.2781  
##  Mean   :0.3638   Mean   :0.3397   Mean   :0.3258   Mean   :0.3112  
##  3rd Qu.:0.5189   3rd Qu.:0.4405   3rd Qu.:0.4349   3rd Qu.:0.4244  
##  Max.   :0.9497   Max.   :1.0000   Max.   :0.9857   Max.   :0.9297  
##       V41              V42              V43              V44        
##  Min.   :0.0360   Min.   :0.0056   Min.   :0.0000   Min.   :0.0000  
##  1st Qu.:0.1631   1st Qu.:0.1589   1st Qu.:0.1552   1st Qu.:0.1269  
##  Median :0.2595   Median :0.2451   Median :0.2225   Median :0.1777  
##  Mean   :0.2893   Mean   :0.2783   Mean   :0.2465   Mean   :0.2141  
##  3rd Qu.:0.3875   3rd Qu.:0.3842   3rd Qu.:0.3245   3rd Qu.:0.2717  
##  Max.   :0.8995   Max.   :0.8246   Max.   :0.7733   Max.   :0.7762  
##       V45               V46               V47               V48         
##  Min.   :0.00000   Min.   :0.00000   Min.   :0.00000   Min.   :0.00000  
##  1st Qu.:0.09448   1st Qu.:0.06855   1st Qu.:0.06425   1st Qu.:0.04512  
##  Median :0.14800   Median :0.12135   Median :0.10165   Median :0.07810  
##  Mean   :0.19723   Mean   :0.16063   Mean   :0.12245   Mean   :0.09142  
##  3rd Qu.:0.23155   3rd Qu.:0.20037   3rd Qu.:0.15443   3rd Qu.:0.12010  
##  Max.   :0.70340   Max.   :0.72920   Max.   :0.55220   Max.   :0.33390  
##       V49               V50               V51                V52          
##  Min.   :0.00000   Min.   :0.00000   Min.   :0.000000   Min.   :0.000800  
##  1st Qu.:0.02635   1st Qu.:0.01155   1st Qu.:0.008425   1st Qu.:0.007275  
##  Median :0.04470   Median :0.01790   Median :0.013900   Median :0.011400  
##  Mean   :0.05193   Mean   :0.02042   Mean   :0.016069   Mean   :0.013420  
##  3rd Qu.:0.06853   3rd Qu.:0.02527   3rd Qu.:0.020825   3rd Qu.:0.016725  
##  Max.   :0.19810   Max.   :0.08250   Max.   :0.100400   Max.   :0.070900  
##       V53                V54                V55               V56          
##  Min.   :0.000500   Min.   :0.001000   Min.   :0.00060   Min.   :0.000400  
##  1st Qu.:0.005075   1st Qu.:0.005375   1st Qu.:0.00415   1st Qu.:0.004400  
##  Median :0.009550   Median :0.009300   Median :0.00750   Median :0.006850  
##  Mean   :0.010709   Mean   :0.010941   Mean   :0.00929   Mean   :0.008222  
##  3rd Qu.:0.014900   3rd Qu.:0.014500   3rd Qu.:0.01210   3rd Qu.:0.010575  
##  Max.   :0.039000   Max.   :0.035200   Max.   :0.04470   Max.   :0.039400  
##       V57               V58                V59                V60          
##  Min.   :0.00030   Min.   :0.000300   Min.   :0.000100   Min.   :0.000600  
##  1st Qu.:0.00370   1st Qu.:0.003600   1st Qu.:0.003675   1st Qu.:0.003100  
##  Median :0.00595   Median :0.005800   Median :0.006400   Median :0.005300  
##  Mean   :0.00782   Mean   :0.007949   Mean   :0.007941   Mean   :0.006507  
##  3rd Qu.:0.01043   3rd Qu.:0.010350   3rd Qu.:0.010325   3rd Qu.:0.008525  
##  Max.   :0.03550   Max.   :0.044000   Max.   :0.036400   Max.   :0.043900  
##  Class  
##  M:111  
##  R: 97  
##         
##         
##         
## 
Sonar %>% count(Class)
##   Class   n
## 1     M 111
## 2     R  97
set.seed(998) #setseed 함수 지정 안해주면 완전 무작위
inTraining<-createDataPartition(y=Sonar$Class,p=.75,list = FALSE) #inTraining 대신 idx
training<-Sonar[inTraining,]
testing<-Sonar[-inTraining,]
inTraining
##        Resample1
##   [1,]         1
##   [2,]         2
##   [3,]         3
##   [4,]         5
##   [5,]         6
##   [6,]         7
##   [7,]         9
##   [8,]        10
##   [9,]        12
##  [10,]        13
##  [11,]        16
##  [12,]        18
##  [13,]        20
##  [14,]        21
##  [15,]        23
##  [16,]        24
##  [17,]        25
##  [18,]        26
##  [19,]        27
##  [20,]        29
##  [21,]        30
##  [22,]        31
##  [23,]        33
##  [24,]        34
##  [25,]        36
##  [26,]        37
##  [27,]        38
##  [28,]        39
##  [29,]        40
##  [30,]        41
##  [31,]        42
##  [32,]        45
##  [33,]        46
##  [34,]        47
##  [35,]        48
##  [36,]        49
##  [37,]        50
##  [38,]        52
##  [39,]        53
##  [40,]        54
##  [41,]        55
##  [42,]        57
##  [43,]        58
##  [44,]        59
##  [45,]        60
##  [46,]        62
##  [47,]        63
##  [48,]        65
##  [49,]        66
##  [50,]        67
##  [51,]        69
##  [52,]        70
##  [53,]        71
##  [54,]        72
##  [55,]        74
##  [56,]        77
##  [57,]        78
##  [58,]        79
##  [59,]        80
##  [60,]        81
##  [61,]        82
##  [62,]        83
##  [63,]        84
##  [64,]        85
##  [65,]        86
##  [66,]        87
##  [67,]        88
##  [68,]        89
##  [69,]        90
##  [70,]        93
##  [71,]        95
##  [72,]        96
##  [73,]        97
##  [74,]        98
##  [75,]        99
##  [76,]       100
##  [77,]       102
##  [78,]       104
##  [79,]       106
##  [80,]       107
##  [81,]       108
##  [82,]       109
##  [83,]       112
##  [84,]       113
##  [85,]       114
##  [86,]       115
##  [87,]       116
##  [88,]       117
##  [89,]       118
##  [90,]       119
##  [91,]       120
##  [92,]       123
##  [93,]       124
##  [94,]       125
##  [95,]       126
##  [96,]       127
##  [97,]       129
##  [98,]       130
##  [99,]       132
## [100,]       133
## [101,]       135
## [102,]       137
## [103,]       138
## [104,]       139
## [105,]       140
## [106,]       142
## [107,]       143
## [108,]       144
## [109,]       145
## [110,]       146
## [111,]       147
## [112,]       148
## [113,]       149
## [114,]       150
## [115,]       151
## [116,]       152
## [117,]       154
## [118,]       155
## [119,]       157
## [120,]       158
## [121,]       159
## [122,]       160
## [123,]       162
## [124,]       163
## [125,]       164
## [126,]       165
## [127,]       166
## [128,]       167
## [129,]       169
## [130,]       171
## [131,]       172
## [132,]       173
## [133,]       174
## [134,]       176
## [135,]       177
## [136,]       178
## [137,]       179
## [138,]       180
## [139,]       182
## [140,]       183
## [141,]       184
## [142,]       186
## [143,]       188
## [144,]       190
## [145,]       191
## [146,]       192
## [147,]       193
## [148,]       195
## [149,]       196
## [150,]       198
## [151,]       200
## [152,]       201
## [153,]       202
## [154,]       203
## [155,]       204
## [156,]       206
## [157,]       207
NROW(training)
## [1] 157
NROW(testing)
## [1] 51
set.seed(825)
rffit<-train(Class~.,data=training,
             method="rf",
             preProc=c("center","scale"))
rffit
## Random Forest 
## 
## 157 samples
##  60 predictor
##   2 classes: 'M', 'R' 
## 
## Pre-processing: centered (60), scaled (60) 
## Resampling: Bootstrapped (25 reps) 
## Summary of sample sizes: 157, 157, 157, 157, 157, 157, ... 
## Resampling results across tuning parameters:
## 
##   mtry  Accuracy   Kappa    
##    2    0.7869345  0.5637847
##   31    0.7772599  0.5465693
##   60    0.7626313  0.5153456
## 
## Accuracy was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 2.
rffit1<-train(Class~.,data=training,
             method="knn",
             preProc=c("center","scale"))
rffit1
## k-Nearest Neighbors 
## 
## 157 samples
##  60 predictor
##   2 classes: 'M', 'R' 
## 
## Pre-processing: centered (60), scaled (60) 
## Resampling: Bootstrapped (25 reps) 
## Summary of sample sizes: 157, 157, 157, 157, 157, 157, ... 
## Resampling results across tuning parameters:
## 
##   k  Accuracy   Kappa    
##   5  0.7421023  0.4741816
##   7  0.7197420  0.4301948
##   9  0.7119170  0.4136557
## 
## Accuracy was used to select the optimal model using the largest value.
## The final value used for the model was k = 5.
rffit2<-train(Class~.,data=training,
             method="rpart",
             preProc=c("center","scale"))
rffit2
## CART 
## 
## 157 samples
##  60 predictor
##   2 classes: 'M', 'R' 
## 
## Pre-processing: centered (60), scaled (60) 
## Resampling: Bootstrapped (25 reps) 
## Summary of sample sizes: 157, 157, 157, 157, 157, 157, ... 
## Resampling results across tuning parameters:
## 
##   cp          Accuracy   Kappa    
##   0.04109589  0.7285611  0.4489088
##   0.12328767  0.7341192  0.4594893
##   0.53424658  0.6088256  0.1998663
## 
## Accuracy was used to select the optimal model using the largest value.
## The final value used for the model was cp = 0.1232877.
fitControl<-trainControl(method = "cv",
                         number = 5,
                         classProbs = TRUE,
                         summaryFunction = twoClassSummary)
fitControl
## $method
## [1] "cv"
## 
## $number
## [1] 5
## 
## $repeats
## [1] NA
## 
## $search
## [1] "grid"
## 
## $p
## [1] 0.75
## 
## $initialWindow
## NULL
## 
## $horizon
## [1] 1
## 
## $fixedWindow
## [1] TRUE
## 
## $skip
## [1] 0
## 
## $verboseIter
## [1] FALSE
## 
## $returnData
## [1] TRUE
## 
## $returnResamp
## [1] "final"
## 
## $savePredictions
## [1] FALSE
## 
## $classProbs
## [1] TRUE
## 
## $summaryFunction
## function (data, lev = NULL, model = NULL) 
## {
##     if (length(lev) > 2) {
##         stop(paste("Your outcome has", length(lev), "levels. The twoClassSummary() function isn't appropriate."))
##     }
##     requireNamespaceQuietStop("pROC")
##     if (!all(levels(data[, "pred"]) == lev)) {
##         stop("levels of observed and predicted data do not match")
##     }
##     rocObject <- try(pROC::roc(data$obs, data[, lev[1]], direction = ">", 
##         quiet = TRUE), silent = TRUE)
##     rocAUC <- if (inherits(rocObject, "try-error")) 
##         NA
##     else rocObject$auc
##     out <- c(rocAUC, sensitivity(data[, "pred"], data[, "obs"], 
##         lev[1]), specificity(data[, "pred"], data[, "obs"], lev[2]))
##     names(out) <- c("ROC", "Sens", "Spec")
##     out
## }
## <bytecode: 0x00000242b4759308>
## <environment: namespace:caret>
## 
## $selectionFunction
## [1] "best"
## 
## $preProcOptions
## $preProcOptions$thresh
## [1] 0.95
## 
## $preProcOptions$ICAcomp
## [1] 3
## 
## $preProcOptions$k
## [1] 5
## 
## $preProcOptions$freqCut
## [1] 19
## 
## $preProcOptions$uniqueCut
## [1] 10
## 
## $preProcOptions$cutoff
## [1] 0.9
## 
## 
## $sampling
## NULL
## 
## $index
## NULL
## 
## $indexOut
## NULL
## 
## $indexFinal
## NULL
## 
## $timingSamps
## [1] 0
## 
## $predictionBounds
## [1] FALSE FALSE
## 
## $seeds
## [1] NA
## 
## $adaptive
## $adaptive$min
## [1] 5
## 
## $adaptive$alpha
## [1] 0.05
## 
## $adaptive$method
## [1] "gls"
## 
## $adaptive$complete
## [1] TRUE
## 
## 
## $trim
## [1] FALSE
## 
## $allowParallel
## [1] TRUE
set.seed(825)
rmfit1<-train(Class~.,data=training,
             method="rf",
             trControl=fitControl,
             verbose=FALSE,
             metric="ROC")
rmfit1
## Random Forest 
## 
## 157 samples
##  60 predictor
##   2 classes: 'M', 'R' 
## 
## No pre-processing
## Resampling: Cross-Validated (5 fold) 
## Summary of sample sizes: 125, 125, 125, 127, 126 
## Resampling results across tuning parameters:
## 
##   mtry  ROC        Sens       Spec     
##    2    0.9317665  0.9176471  0.7533333
##   31    0.9252381  0.8816176  0.7247619
##   60    0.9146569  0.8580882  0.7514286
## 
## ROC was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 2.
set.seed(825)
customGrid<-expand.grid(mtry=1:10)
rffit2<-train(Class~.,data=training,method="rf",trControl=fitControl,
              tuneGrid=customGrid,metric="ROC")
rffit2
## Random Forest 
## 
## 157 samples
##  60 predictor
##   2 classes: 'M', 'R' 
## 
## No pre-processing
## Resampling: Cross-Validated (5 fold) 
## Summary of sample sizes: 125, 125, 125, 127, 126 
## Resampling results across tuning parameters:
## 
##   mtry  ROC        Sens       Spec     
##    1    0.9287640  0.9411765  0.6847619
##    2    0.9371078  0.9058824  0.7533333
##    3    0.9399545  0.9058824  0.7380952
##    4    0.9392787  0.8823529  0.7657143
##    5    0.9365546  0.8941176  0.7523810
##    6    0.9297094  0.8941176  0.7523810
##    7    0.9347584  0.8941176  0.7238095
##    8    0.9331863  0.8816176  0.7800000
##    9    0.9364741  0.8816176  0.7390476
##   10    0.9285399  0.8823529  0.7390476
## 
## ROC was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 3.
rffit4<-train(Class~.,data=training,method="rf",trControl=fitControl,
              tuneLength=20)
## Warning in train.default(x, y, weights = w, ...): The metric "Accuracy" was not
## in the result set. ROC will be used instead.
rffit4
## Random Forest 
## 
## 157 samples
##  60 predictor
##   2 classes: 'M', 'R' 
## 
## No pre-processing
## Resampling: Cross-Validated (5 fold) 
## Summary of sample sizes: 127, 126, 125, 125, 125 
## Resampling results across tuning parameters:
## 
##   mtry  ROC        Sens       Spec     
##    2    0.9374335  0.8808824  0.7019048
##    5    0.9254167  0.9044118  0.7276190
##    8    0.9241842  0.8455882  0.7009524
##   11    0.9250525  0.8338235  0.7409524
##   14    0.9129272  0.8463235  0.7400000
##   17    0.9240091  0.8698529  0.7276190
##   20    0.9094608  0.8220588  0.7409524
##   23    0.9132633  0.8220588  0.7276190
##   26    0.9062640  0.8220588  0.7276190
##   29    0.9029079  0.8220588  0.7409524
##   32    0.8990686  0.8345588  0.7409524
##   35    0.9054149  0.8220588  0.7276190
##   38    0.9019783  0.8110294  0.7542857
##   41    0.8873144  0.8102941  0.7266667
##   44    0.8927171  0.8102941  0.7409524
##   47    0.8916737  0.8227941  0.7542857
##   50    0.8927066  0.7867647  0.7409524
##   53    0.8905777  0.7985294  0.7409524
##   56    0.8901436  0.8110294  0.7542857
##   60    0.8954237  0.8227941  0.7542857
## 
## ROC was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 2.
predict(rmfit1,newdata = head(testing))
## [1] R M R M M M
## Levels: M R
predict(rmfit1,newdata = head(testing),type = 'prob')
##        M     R
## 4  0.446 0.554
## 8  0.630 0.370
## 11 0.088 0.912
## 14 0.506 0.494
## 15 0.546 0.454
## 17 0.620 0.380
library(caTools)
df<-read.csv("diagnosis.csv")
glimpse(df)
## Rows: 569
## Columns: 32
## $ id                      <int> 842302, 842517, 84300903, 84348301, 84358402, …
## $ diagnosis               <chr> "M", "M", "M", "M", "M", "M", "M", "M", "M", "…
## $ radius_mean             <dbl> 17.990, 20.570, 19.690, 11.420, 20.290, 12.450…
## $ texture_mean            <dbl> 10.38, 17.77, 21.25, 20.38, 14.34, 15.70, 19.9…
## $ perimeter_mean          <dbl> 122.80, 132.90, 130.00, 77.58, 135.10, 82.57, …
## $ area_mean               <dbl> 1001.0, 1326.0, 1203.0, 386.1, 1297.0, 477.1, …
## $ smoothness_mean         <dbl> 0.11840, 0.08474, 0.10960, 0.14250, 0.10030, 0…
## $ compactness_mean        <dbl> 0.27760, 0.07864, 0.15990, 0.28390, 0.13280, 0…
## $ concavity_mean          <dbl> 0.30010, 0.08690, 0.19740, 0.24140, 0.19800, 0…
## $ concave.points_mean     <dbl> 0.14710, 0.07017, 0.12790, 0.10520, 0.10430, 0…
## $ symmetry_mean           <dbl> 0.2419, 0.1812, 0.2069, 0.2597, 0.1809, 0.2087…
## $ fractal_dimension_mean  <dbl> 0.07871, 0.05667, 0.05999, 0.09744, 0.05883, 0…
## $ radius_se               <dbl> 1.0950, 0.5435, 0.7456, 0.4956, 0.7572, 0.3345…
## $ texture_se              <dbl> 0.9053, 0.7339, 0.7869, 1.1560, 0.7813, 0.8902…
## $ perimeter_se            <dbl> 8.589, 3.398, 4.585, 3.445, 5.438, 2.217, 3.18…
## $ area_se                 <dbl> 153.40, 74.08, 94.03, 27.23, 94.44, 27.19, 53.…
## $ smoothness_se           <dbl> 0.006399, 0.005225, 0.006150, 0.009110, 0.0114…
## $ compactness_se          <dbl> 0.049040, 0.013080, 0.040060, 0.074580, 0.0246…
## $ concavity_se            <dbl> 0.05373, 0.01860, 0.03832, 0.05661, 0.05688, 0…
## $ concave.points_se       <dbl> 0.015870, 0.013400, 0.020580, 0.018670, 0.0188…
## $ symmetry_se             <dbl> 0.03003, 0.01389, 0.02250, 0.05963, 0.01756, 0…
## $ fractal_dimension_se    <dbl> 0.006193, 0.003532, 0.004571, 0.009208, 0.0051…
## $ radius_worst            <dbl> 25.38, 24.99, 23.57, 14.91, 22.54, 15.47, 22.8…
## $ texture_worst           <dbl> 17.33, 23.41, 25.53, 26.50, 16.67, 23.75, 27.6…
## $ perimeter_worst         <dbl> 184.60, 158.80, 152.50, 98.87, 152.20, 103.40,…
## $ area_worst              <dbl> 2019.0, 1956.0, 1709.0, 567.7, 1575.0, 741.6, …
## $ smoothness_worst        <dbl> 0.1622, 0.1238, 0.1444, 0.2098, 0.1374, 0.1791…
## $ compactness_worst       <dbl> 0.6656, 0.1866, 0.4245, 0.8663, 0.2050, 0.5249…
## $ concavity_worst         <dbl> 0.71190, 0.24160, 0.45040, 0.68690, 0.40000, 0…
## $ concave.points_worst    <dbl> 0.26540, 0.18600, 0.24300, 0.25750, 0.16250, 0…
## $ symmetry_worst          <dbl> 0.4601, 0.2750, 0.3613, 0.6638, 0.2364, 0.3985…
## $ fractal_dimension_worst <dbl> 0.11890, 0.08902, 0.08758, 0.17300, 0.07678, 0…
df<-df %>% select(-id)
df$diagnosis<-as.factor(df$diagnosis)
prop.table(table(df$diagnosis))
## 
##         B         M 
## 0.6274165 0.3725835
any(is.na(df))
## [1] FALSE
set.seed(3)
inTraining<-createDataPartition(y=df$diagnosis,p=.75,list = FALSE)
training <- df[ inTraining,]
testing <- df[-inTraining,]
inTraining
##        Resample1
##   [1,]         1
##   [2,]         2
##   [3,]         3
##   [4,]         4
##   [5,]         5
##   [6,]         6
##   [7,]         7
##   [8,]         9
##   [9,]        10
##  [10,]        11
##  [11,]        12
##  [12,]        13
##  [13,]        14
##  [14,]        15
##  [15,]        16
##  [16,]        17
##  [17,]        18
##  [18,]        19
##  [19,]        21
##  [20,]        22
##  [21,]        23
##  [22,]        25
##  [23,]        26
##  [24,]        28
##  [25,]        29
##  [26,]        30
##  [27,]        31
##  [28,]        33
##  [29,]        35
##  [30,]        37
##  [31,]        38
##  [32,]        40
##  [33,]        41
##  [34,]        44
##  [35,]        45
##  [36,]        47
##  [37,]        49
##  [38,]        50
##  [39,]        51
##  [40,]        52
##  [41,]        53
##  [42,]        54
##  [43,]        58
##  [44,]        59
##  [45,]        60
##  [46,]        61
##  [47,]        62
##  [48,]        63
##  [49,]        64
##  [50,]        66
##  [51,]        69
##  [52,]        70
##  [53,]        71
##  [54,]        74
##  [55,]        75
##  [56,]        76
##  [57,]        77
##  [58,]        78
##  [59,]        79
##  [60,]        80
##  [61,]        82
##  [62,]        83
##  [63,]        84
##  [64,]        85
##  [65,]        87
##  [66,]        88
##  [67,]        89
##  [68,]        90
##  [69,]        92
##  [70,]        93
##  [71,]        95
##  [72,]        96
##  [73,]        97
##  [74,]        99
##  [75,]       101
##  [76,]       102
##  [77,]       103
##  [78,]       104
##  [79,]       105
##  [80,]       106
##  [81,]       107
##  [82,]       108
##  [83,]       109
##  [84,]       110
##  [85,]       112
##  [86,]       113
##  [87,]       115
##  [88,]       116
##  [89,]       117
##  [90,]       118
##  [91,]       119
##  [92,]       121
##  [93,]       123
##  [94,]       124
##  [95,]       125
##  [96,]       126
##  [97,]       127
##  [98,]       128
##  [99,]       129
## [100,]       131
## [101,]       132
## [102,]       134
## [103,]       135
## [104,]       139
## [105,]       142
## [106,]       144
## [107,]       145
## [108,]       146
## [109,]       147
## [110,]       148
## [111,]       149
## [112,]       150
## [113,]       151
## [114,]       152
## [115,]       153
## [116,]       154
## [117,]       156
## [118,]       157
## [119,]       158
## [120,]       159
## [121,]       161
## [122,]       162
## [123,]       163
## [124,]       165
## [125,]       166
## [126,]       168
## [127,]       169
## [128,]       170
## [129,]       171
## [130,]       172
## [131,]       173
## [132,]       174
## [133,]       175
## [134,]       176
## [135,]       177
## [136,]       178
## [137,]       179
## [138,]       180
## [139,]       181
## [140,]       184
## [141,]       185
## [142,]       186
## [143,]       188
## [144,]       190
## [145,]       194
## [146,]       195
## [147,]       197
## [148,]       198
## [149,]       199
## [150,]       201
## [151,]       202
## [152,]       203
## [153,]       204
## [154,]       205
## [155,]       206
## [156,]       207
## [157,]       209
## [158,]       210
## [159,]       211
## [160,]       212
## [161,]       213
## [162,]       215
## [163,]       216
## [164,]       218
## [165,]       220
## [166,]       221
## [167,]       222
## [168,]       223
## [169,]       224
## [170,]       225
## [171,]       226
## [172,]       227
## [173,]       228
## [174,]       229
## [175,]       230
## [176,]       231
## [177,]       232
## [178,]       233
## [179,]       234
## [180,]       236
## [181,]       238
## [182,]       239
## [183,]       240
## [184,]       241
## [185,]       242
## [186,]       243
## [187,]       244
## [188,]       246
## [189,]       247
## [190,]       248
## [191,]       249
## [192,]       251
## [193,]       252
## [194,]       254
## [195,]       256
## [196,]       257
## [197,]       258
## [198,]       259
## [199,]       260
## [200,]       261
## [201,]       262
## [202,]       263
## [203,]       264
## [204,]       265
## [205,]       266
## [206,]       267
## [207,]       268
## [208,]       269
## [209,]       270
## [210,]       274
## [211,]       275
## [212,]       276
## [213,]       277
## [214,]       278
## [215,]       279
## [216,]       280
## [217,]       281
## [218,]       282
## [219,]       283
## [220,]       284
## [221,]       285
## [222,]       287
## [223,]       288
## [224,]       290
## [225,]       291
## [226,]       292
## [227,]       294
## [228,]       296
## [229,]       297
## [230,]       298
## [231,]       299
## [232,]       300
## [233,]       301
## [234,]       303
## [235,]       306
## [236,]       308
## [237,]       309
## [238,]       310
## [239,]       311
## [240,]       312
## [241,]       313
## [242,]       314
## [243,]       315
## [244,]       316
## [245,]       318
## [246,]       319
## [247,]       320
## [248,]       321
## [249,]       322
## [250,]       323
## [251,]       324
## [252,]       326
## [253,]       327
## [254,]       329
## [255,]       330
## [256,]       331
## [257,]       333
## [258,]       334
## [259,]       336
## [260,]       337
## [261,]       338
## [262,]       339
## [263,]       340
## [264,]       342
## [265,]       343
## [266,]       346
## [267,]       347
## [268,]       348
## [269,]       349
## [270,]       350
## [271,]       351
## [272,]       354
## [273,]       356
## [274,]       357
## [275,]       358
## [276,]       359
## [277,]       360
## [278,]       362
## [279,]       363
## [280,]       364
## [281,]       365
## [282,]       366
## [283,]       368
## [284,]       369
## [285,]       370
## [286,]       371
## [287,]       372
## [288,]       373
## [289,]       378
## [290,]       381
## [291,]       382
## [292,]       383
## [293,]       388
## [294,]       390
## [295,]       392
## [296,]       393
## [297,]       394
## [298,]       395
## [299,]       396
## [300,]       397
## [301,]       398
## [302,]       400
## [303,]       406
## [304,]       407
## [305,]       409
## [306,]       410
## [307,]       411
## [308,]       412
## [309,]       413
## [310,]       417
## [311,]       418
## [312,]       420
## [313,]       422
## [314,]       424
## [315,]       425
## [316,]       427
## [317,]       429
## [318,]       430
## [319,]       433
## [320,]       436
## [321,]       437
## [322,]       439
## [323,]       440
## [324,]       441
## [325,]       442
## [326,]       443
## [327,]       444
## [328,]       445
## [329,]       446
## [330,]       448
## [331,]       449
## [332,]       450
## [333,]       451
## [334,]       452
## [335,]       453
## [336,]       454
## [337,]       457
## [338,]       458
## [339,]       459
## [340,]       460
## [341,]       461
## [342,]       462
## [343,]       463
## [344,]       464
## [345,]       465
## [346,]       466
## [347,]       467
## [348,]       468
## [349,]       469
## [350,]       470
## [351,]       471
## [352,]       472
## [353,]       474
## [354,]       475
## [355,]       477
## [356,]       478
## [357,]       481
## [358,]       483
## [359,]       484
## [360,]       486
## [361,]       487
## [362,]       488
## [363,]       489
## [364,]       491
## [365,]       492
## [366,]       493
## [367,]       494
## [368,]       495
## [369,]       498
## [370,]       500
## [371,]       502
## [372,]       503
## [373,]       504
## [374,]       505
## [375,]       507
## [376,]       508
## [377,]       509
## [378,]       510
## [379,]       511
## [380,]       512
## [381,]       513
## [382,]       514
## [383,]       515
## [384,]       516
## [385,]       517
## [386,]       518
## [387,]       519
## [388,]       520
## [389,]       521
## [390,]       522
## [391,]       523
## [392,]       524
## [393,]       525
## [394,]       528
## [395,]       529
## [396,]       530
## [397,]       531
## [398,]       532
## [399,]       533
## [400,]       536
## [401,]       538
## [402,]       539
## [403,]       541
## [404,]       543
## [405,]       544
## [406,]       545
## [407,]       546
## [408,]       547
## [409,]       548
## [410,]       549
## [411,]       550
## [412,]       551
## [413,]       552
## [414,]       553
## [415,]       556
## [416,]       557
## [417,]       558
## [418,]       559
## [419,]       560
## [420,]       561
## [421,]       562
## [422,]       564
## [423,]       565
## [424,]       566
## [425,]       567
## [426,]       568
## [427,]       569
my_trainControl<- trainControl(method = "cv",
                               number = 10,
                               classProbs = TRUE,
                               summaryFunction = twoClassSummary)
my_trainControl
## $method
## [1] "cv"
## 
## $number
## [1] 10
## 
## $repeats
## [1] NA
## 
## $search
## [1] "grid"
## 
## $p
## [1] 0.75
## 
## $initialWindow
## NULL
## 
## $horizon
## [1] 1
## 
## $fixedWindow
## [1] TRUE
## 
## $skip
## [1] 0
## 
## $verboseIter
## [1] FALSE
## 
## $returnData
## [1] TRUE
## 
## $returnResamp
## [1] "final"
## 
## $savePredictions
## [1] FALSE
## 
## $classProbs
## [1] TRUE
## 
## $summaryFunction
## function (data, lev = NULL, model = NULL) 
## {
##     if (length(lev) > 2) {
##         stop(paste("Your outcome has", length(lev), "levels. The twoClassSummary() function isn't appropriate."))
##     }
##     requireNamespaceQuietStop("pROC")
##     if (!all(levels(data[, "pred"]) == lev)) {
##         stop("levels of observed and predicted data do not match")
##     }
##     rocObject <- try(pROC::roc(data$obs, data[, lev[1]], direction = ">", 
##         quiet = TRUE), silent = TRUE)
##     rocAUC <- if (inherits(rocObject, "try-error")) 
##         NA
##     else rocObject$auc
##     out <- c(rocAUC, sensitivity(data[, "pred"], data[, "obs"], 
##         lev[1]), specificity(data[, "pred"], data[, "obs"], lev[2]))
##     names(out) <- c("ROC", "Sens", "Spec")
##     out
## }
## <bytecode: 0x00000242b4759308>
## <environment: namespace:caret>
## 
## $selectionFunction
## [1] "best"
## 
## $preProcOptions
## $preProcOptions$thresh
## [1] 0.95
## 
## $preProcOptions$ICAcomp
## [1] 3
## 
## $preProcOptions$k
## [1] 5
## 
## $preProcOptions$freqCut
## [1] 19
## 
## $preProcOptions$uniqueCut
## [1] 10
## 
## $preProcOptions$cutoff
## [1] 0.9
## 
## 
## $sampling
## NULL
## 
## $index
## NULL
## 
## $indexOut
## NULL
## 
## $indexFinal
## NULL
## 
## $timingSamps
## [1] 0
## 
## $predictionBounds
## [1] FALSE FALSE
## 
## $seeds
## [1] NA
## 
## $adaptive
## $adaptive$min
## [1] 5
## 
## $adaptive$alpha
## [1] 0.05
## 
## $adaptive$method
## [1] "gls"
## 
## $adaptive$complete
## [1] TRUE
## 
## 
## $trim
## [1] FALSE
## 
## $allowParallel
## [1] TRUE
glmnetfit <- train(diagnosis ~ ., data = training,
                   method = "glmnet",
                   trControl = fitControl,
                   verbose = FALSE,
                   metric = "ROC")
1
## [1] 1
glmnetfit
## glmnet 
## 
## 427 samples
##  30 predictor
##   2 classes: 'B', 'M' 
## 
## No pre-processing
## Resampling: Cross-Validated (5 fold) 
## Summary of sample sizes: 342, 341, 343, 341, 341 
## Resampling results across tuning parameters:
## 
##   alpha  lambda        ROC        Sens       Spec     
##   0.10   0.0007738036  0.9931304  0.9850454  0.9560484
##   0.10   0.0077380355  0.9941928  0.9962963  0.9372984
##   0.10   0.0773803551  0.9937380  0.9962963  0.9054435
##   0.55   0.0007738036  0.9930087  0.9850454  0.9497984
##   0.55   0.0077380355  0.9943107  0.9962963  0.9497984
##   0.55   0.0773803551  0.9931533  0.9962963  0.8741935
##   1.00   0.0007738036  0.9921904  0.9776380  0.9435484
##   1.00   0.0077380355  0.9941966  0.9962963  0.9370968
##   1.00   0.0773803551  0.9907960  0.9925926  0.8614919
## 
## ROC was used to select the optimal model using the largest value.
## The final values used for the model were alpha = 0.55 and lambda = 0.007738036.
my_trainControl<- trainControl(method = "cv",
                                number = 5,
                                classProbs = TRUE,
                                summaryFunction = twoClassSummary)
rffit <- train(diagnosis ~ ., data = training,
                method = "rf",
                trControl = fitControl,
                verbose = FALSE,
                metric = "ROC")
rffit
## Random Forest 
## 
## 427 samples
##  30 predictor
##   2 classes: 'B', 'M' 
## 
## No pre-processing
## Resampling: Cross-Validated (5 fold) 
## Summary of sample sizes: 342, 342, 341, 342, 341 
## Resampling results across tuning parameters:
## 
##   mtry  ROC        Sens       Spec     
##    2    0.9936561  0.9777079  0.9431452
##   16    0.9921875  0.9628232  0.9493952
##   30    0.9908927  0.9702306  0.9493952
## 
## ROC was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 2.
rffit$results %>% arrange(desc(ROC))
##   mtry       ROC      Sens      Spec       ROCSD     SensSD     SpecSD
## 1    2 0.9936561 0.9777079 0.9431452 0.007707757 0.02413230 0.02724200
## 2   16 0.9921875 0.9628232 0.9493952 0.008416396 0.03928495 0.02914161
## 3   30 0.9908927 0.9702306 0.9493952 0.009441040 0.02813250 0.02914161
library(lubridate)
## 
## 다음의 패키지를 부착합니다: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(dplyr)
library(nycflights13)
data("flights")
glimpse(flights)
## Rows: 336,776
## Columns: 19
## $ year           <int> 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2…
## $ month          <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ day            <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ dep_time       <int> 517, 533, 542, 544, 554, 554, 555, 557, 557, 558, 558, …
## $ sched_dep_time <int> 515, 529, 540, 545, 600, 558, 600, 600, 600, 600, 600, …
## $ dep_delay      <dbl> 2, 4, 2, -1, -6, -4, -5, -3, -3, -2, -2, -2, -2, -2, -1…
## $ arr_time       <int> 830, 850, 923, 1004, 812, 740, 913, 709, 838, 753, 849,…
## $ sched_arr_time <int> 819, 830, 850, 1022, 837, 728, 854, 723, 846, 745, 851,…
## $ arr_delay      <dbl> 11, 20, 33, -18, -25, 12, 19, -14, -8, 8, -2, -3, 7, -1…
## $ carrier        <chr> "UA", "UA", "AA", "B6", "DL", "UA", "B6", "EV", "B6", "…
## $ flight         <int> 1545, 1714, 1141, 725, 461, 1696, 507, 5708, 79, 301, 4…
## $ tailnum        <chr> "N14228", "N24211", "N619AA", "N804JB", "N668DN", "N394…
## $ origin         <chr> "EWR", "LGA", "JFK", "JFK", "LGA", "EWR", "EWR", "LGA",…
## $ dest           <chr> "IAH", "IAH", "MIA", "BQN", "ATL", "ORD", "FLL", "IAD",…
## $ air_time       <dbl> 227, 227, 160, 183, 116, 150, 158, 53, 140, 138, 149, 1…
## $ distance       <dbl> 1400, 1416, 1089, 1576, 762, 719, 1065, 229, 944, 733, …
## $ hour           <dbl> 5, 5, 5, 5, 6, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6…
## $ minute         <dbl> 15, 29, 40, 45, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 0…
## $ time_hour      <dttm> 2013-01-01 05:00:00, 2013-01-01 05:00:00, 2013-01-01 0…
View(flights)

today()
## [1] "2024-01-31"
now()
## [1] "2024-01-31 17:01:11 KST"
ymd("2024-01-31")
## [1] "2024-01-31"
mdy("january-1st-2024")
## [1] "2024-01-01"
dmy("31-jan-2024")
## [1] "2024-01-31"
flights %>%
  select(year, month, day, hour, minute)
## # A tibble: 336,776 × 5
##     year month   day  hour minute
##    <int> <int> <int> <dbl>  <dbl>
##  1  2013     1     1     5     15
##  2  2013     1     1     5     29
##  3  2013     1     1     5     40
##  4  2013     1     1     5     45
##  5  2013     1     1     6      0
##  6  2013     1     1     5     58
##  7  2013     1     1     6      0
##  8  2013     1     1     6      0
##  9  2013     1     1     6      0
## 10  2013     1     1     6      0
## # ℹ 336,766 more rows
flights %>%
  select(year, month, day, hour, minute) %>%
  mutate(departure = make_datetime(year, month, day, hour, minute))
## # A tibble: 336,776 × 6
##     year month   day  hour minute departure          
##    <int> <int> <int> <dbl>  <dbl> <dttm>             
##  1  2013     1     1     5     15 2013-01-01 05:15:00
##  2  2013     1     1     5     29 2013-01-01 05:29:00
##  3  2013     1     1     5     40 2013-01-01 05:40:00
##  4  2013     1     1     5     45 2013-01-01 05:45:00
##  5  2013     1     1     6      0 2013-01-01 06:00:00
##  6  2013     1     1     5     58 2013-01-01 05:58:00
##  7  2013     1     1     6      0 2013-01-01 06:00:00
##  8  2013     1     1     6      0 2013-01-01 06:00:00
##  9  2013     1     1     6      0 2013-01-01 06:00:00
## 10  2013     1     1     6      0 2013-01-01 06:00:00
## # ℹ 336,766 more rows
make_datetime_100<-function(year, month, day,time){
  make_datetime(year, month, day, time %/% 100, time %% 100)
}
flights %>%
  filter(!is.na(dep_time)|!is.na(arr_time)) %>%
  mutate(
    dep_time = make_datetime_100(year, month, day, dep_time),
    arr_time = make_datetime_100(year, month, day, arr_time),
    sched_dep_time = make_datetime_100(year, month, day, sched_dep_time),
    sched_arr_time = make_datetime_100(year, month, day, sched_arr_time))%>%
  select(origin, dest, ends_with("delay"), ends_with("time"))
## # A tibble: 328,521 × 9
##    origin dest  dep_delay arr_delay dep_time            sched_dep_time     
##    <chr>  <chr>     <dbl>     <dbl> <dttm>              <dttm>             
##  1 EWR    IAH           2        11 2013-01-01 05:17:00 2013-01-01 05:15:00
##  2 LGA    IAH           4        20 2013-01-01 05:33:00 2013-01-01 05:29:00
##  3 JFK    MIA           2        33 2013-01-01 05:42:00 2013-01-01 05:40:00
##  4 JFK    BQN          -1       -18 2013-01-01 05:44:00 2013-01-01 05:45:00
##  5 LGA    ATL          -6       -25 2013-01-01 05:54:00 2013-01-01 06:00:00
##  6 EWR    ORD          -4        12 2013-01-01 05:54:00 2013-01-01 05:58:00
##  7 EWR    FLL          -5        19 2013-01-01 05:55:00 2013-01-01 06:00:00
##  8 LGA    IAD          -3       -14 2013-01-01 05:57:00 2013-01-01 06:00:00
##  9 JFK    MCO          -3        -8 2013-01-01 05:57:00 2013-01-01 06:00:00
## 10 LGA    ORD          -2         8 2013-01-01 05:58:00 2013-01-01 06:00:00
## # ℹ 328,511 more rows
## # ℹ 3 more variables: arr_time <dttm>, sched_arr_time <dttm>, air_time <dbl>
datetime<-ymd_hms("2024-01-31 15:23:55")
year(datetime)
## [1] 2024
library(ggplot2)
data("economics")
glimpse(economics)
## Rows: 574
## Columns: 6
## $ date     <date> 1967-07-01, 1967-08-01, 1967-09-01, 1967-10-01, 1967-11-01, …
## $ pce      <dbl> 506.7, 509.8, 515.6, 512.2, 517.4, 525.1, 530.9, 533.6, 544.3…
## $ pop      <dbl> 198712, 198911, 199113, 199311, 199498, 199657, 199808, 19992…
## $ psavert  <dbl> 12.6, 12.6, 11.9, 12.9, 12.8, 11.8, 11.7, 12.3, 11.7, 12.3, 1…
## $ uempmed  <dbl> 4.5, 4.7, 4.6, 4.9, 4.7, 4.8, 5.1, 4.5, 4.1, 4.6, 4.4, 4.4, 4…
## $ unemploy <dbl> 2944, 2945, 2958, 3143, 3066, 3018, 2878, 3001, 2877, 2709, 2…
library(lubridate)
economics$year<-year(economics$date)
economics$month<-month(economics$date)
economics$dayr<-day(economics$date)
economics %>% group_by(year) %>% summarize(m=mean(pop))
## # A tibble: 49 × 2
##     year       m
##    <dbl>   <dbl>
##  1  1967 199200.
##  2  1968 200664.
##  3  1969 202649.
##  4  1970 204982.
##  5  1971 207589.
##  6  1972 209838.
##  7  1973 211857.
##  8  1974 213815.
##  9  1975 215891.
## 10  1976 217999.
## # ℹ 39 more rows
df<-read.csv("netflix.csv")
df %>% glimpse()
## Rows: 8,807
## Columns: 11
## $ show_id      <chr> "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s1…
## $ type         <chr> "Movie", "TV Show", "TV Show", "TV Show", "TV Show", "TV …
## $ title        <chr> "Dick Johnson Is Dead", "Blood & Water", "Ganglands", "Ja…
## $ director     <chr> "Kirsten Johnson", "", "Julien Leclercq", "", "", "Mike F…
## $ cast         <chr> "", "Ama Qamata, Khosi Ngema, Gail Mabalane, Thabang Mola…
## $ country      <chr> "United States", "South Africa", "", "", "India", "", "",…
## $ date_added   <chr> "25-Sep-21", "24-Sep-21", "24-Sep-21", "24-Sep-21", "24-S…
## $ release_year <int> 2020, 2021, 2021, 2021, 2021, 2021, 2021, 1993, 2021, 202…
## $ rating       <chr> "PG-13", "TV-MA", "TV-MA", "TV-MA", "TV-MA", "TV-MA", "PG…
## $ duration     <chr> "90 min", "2 Seasons", "1 Season", "1 Season", "2 Seasons…
## $ listed_in    <chr> "Documentaries", "International TV Shows, TV Dramas, TV M…
colSums(is.na(df))
##      show_id         type        title     director         cast      country 
##            0            0            0            0            0            0 
##   date_added release_year       rating     duration    listed_in 
##            0            0            0            0            0
df %>% count(date_added)
##               date_added   n
## 1                         10
## 2         April 15, 2018   1
## 3         April 16, 2019   1
## 4         April 17, 2016   1
## 5         April 20, 2017   1
## 6          April 4, 2017   1
## 7         August 1, 2017   1
## 8        August 13, 2018   1
## 9        August 21, 2017   1
## 10        August 4, 2017   3
## 11      December 1, 2018   1
## 12      December 1, 2019   2
## 13     December 14, 2018   2
## 14     December 15, 2015   1
## 15     December 15, 2017   2
## 16     December 15, 2018   1
## 17     December 18, 2014   1
## 18      December 2, 2017   1
## 19     December 23, 2018   1
## 20     December 25, 2015   1
## 21     December 28, 2016   1
## 22      December 3, 2019   1
## 23     December 31, 2015   1
## 24      February 1, 2015   1
## 25      February 1, 2017   1
## 26      February 1, 2019   3
## 27     February 24, 2018   1
## 28       January 1, 2016   1
## 29       January 1, 2018   3
## 30       January 1, 2020   1
## 31      January 11, 2019   1
## 32      January 12, 2019   1
## 33      January 13, 2016   1
## 34      January 17, 2018   1
## 35      January 28, 2018   1
## 36       January 8, 2018   1
## 37          July 1, 2017   4
## 38         July 12, 2019   1
## 39         July 20, 2018   2
## 40         July 26, 2019   1
## 41          June 1, 2017   2
## 42          June 1, 2018   1
## 43         June 30, 2015   1
## 44         March 1, 2017   1
## 45        March 15, 2019   1
## 46        March 16, 2016   1
## 47        March 20, 2018   1
## 48        March 22, 2015   1
## 49        March 31, 2017   1
## 50        March 31, 2018   2
## 51           May 1, 2018   1
## 52          May 18, 2017   1
## 53          May 19, 2018   1
## 54          May 26, 2016   1
## 55          May 28, 2016   1
## 56          May 31, 2015   1
## 57      November 1, 2016   2
## 58      November 1, 2017   3
## 59      November 1, 2019   2
## 60      November 3, 2015   1
## 61       October 1, 2019   2
## 62      October 31, 2018   1
## 63       October 5, 2017   1
## 64       October 8, 2013   1
## 65     September 1, 2019   1
## 66    September 16, 2018   1
## 67    September 22, 2016   1
## 68     September 7, 2016   1
## 69     September 8, 2015   1
## 70             01-Apr-14   1
## 71             01-Apr-16   7
## 72             01-Apr-17  27
## 73             01-Apr-18  44
## 74             01-Apr-19  28
## 75             01-Apr-20  43
## 76             01-Apr-21  32
## 77             01-Aug-16  14
## 78             01-Aug-17  39
## 79             01-Aug-18  37
## 80             01-Aug-19  26
## 81             01-Aug-20  21
## 82             01-Aug-21  38
## 83             01-Dec-12   1
## 84             01-Dec-15   3
## 85             01-Dec-16  20
## 86             01-Dec-17  26
## 87             01-Dec-18  28
## 88             01-Dec-19  25
## 89             01-Dec-20  28
## 90             01-Feb-14   1
## 91             01-Feb-16   2
## 92             01-Feb-17  18
## 93             01-Feb-18  19
## 94             01-Feb-19  38
## 95             01-Feb-20  15
## 96             01-Feb-21  13
## 97             01-Jan-08   1
## 98             01-Jan-16  32
## 99             01-Jan-17  19
## 100            01-Jan-18  52
## 101            01-Jan-19  37
## 102            01-Jan-20 109
## 103            01-Jan-21  49
## 104            01-Jul-16  12
## 105            01-Jul-17  38
## 106            01-Jul-18  40
## 107            01-Jul-19  52
## 108            01-Jul-20  21
## 109            01-Jul-21  60
## 110            01-Jun-15   1
## 111            01-Jun-16   8
## 112            01-Jun-17  31
## 113            01-Jun-18  12
## 114            01-Jun-19  18
## 115            01-Jun-20  24
## 116            01-Mar-16   4
## 117            01-Mar-17  21
## 118            01-Mar-18  75
## 119            01-Mar-19  30
## 120            01-Mar-20  17
## 121            01-Mar-21  11
## 122            01-May-16   3
## 123            01-May-17  25
## 124            01-May-18  41
## 125            01-May-19  16
## 126            01-May-20  24
## 127            01-May-21  33
## 128            01-Nov-10   1
## 129            01-Nov-13   2
## 130            01-Nov-16  14
## 131            01-Nov-17  30
## 132            01-Nov-18  60
## 133            01-Nov-19  89
## 134            01-Nov-20  33
## 135            01-Oct-11  11
## 136            01-Oct-15   1
## 137            01-Oct-16  23
## 138            01-Oct-17  47
## 139            01-Oct-18  71
## 140            01-Oct-19  60
## 141            01-Oct-20  33
## 142            01-Sep-13   2
## 143            01-Sep-16  20
## 144            01-Sep-17  38
## 145            01-Sep-18  22
## 146            01-Sep-19  30
## 147            01-Sep-20  26
## 148            01-Sep-21  56
## 149            02-Apr-17   2
## 150            02-Apr-18   2
## 151            02-Apr-19   4
## 152            02-Apr-20   2
## 153            02-Apr-21  11
## 154            02-Aug-13   1
## 155            02-Aug-16   1
## 156            02-Aug-18  25
## 157            02-Aug-19   7
## 158            02-Aug-20   2
## 159            02-Dec-15   1
## 160            02-Dec-16   4
## 161            02-Dec-17   2
## 162            02-Dec-18   3
## 163            02-Dec-19   1
## 164            02-Dec-20   6
## 165            02-Feb-17   1
## 166            02-Feb-18   4
## 167            02-Feb-19   6
## 168            02-Feb-21   2
## 169            02-Jan-18   3
## 170            02-Jan-19   2
## 171            02-Jan-20   3
## 172            02-Jan-21   2
## 173            02-Jul-18   2
## 174            02-Jul-19   3
## 175            02-Jul-20   3
## 176            02-Jul-21   9
## 177            02-Jun-16   1
## 178            02-Jun-17   5
## 179            02-Jun-18   2
## 180            02-Jun-19   4
## 181            02-Jun-20  11
## 182            02-Jun-21  51
## 183            02-Mar-16   1
## 184            02-Mar-17   2
## 185            02-Mar-18   4
## 186            02-Mar-19  10
## 187            02-Mar-20   1
## 188            02-Mar-21   3
## 189            02-May-17   2
## 190            02-May-18   1
## 191            02-May-19   7
## 192            02-May-20  11
## 193            02-Nov-16   2
## 194            02-Nov-18   6
## 195            02-Nov-19  14
## 196            02-Nov-20   2
## 197            02-Oct-15   1
## 198            02-Oct-17   1
## 199            02-Oct-18  17
## 200            02-Oct-19  12
## 201            02-Oct-20  11
## 202            02-Sep-15   1
## 203            02-Sep-16   2
## 204            02-Sep-17   3
## 205            02-Sep-18   3
## 206            02-Sep-20   5
## 207            02-Sep-21  14
## 208            03-Apr-18   3
## 209            03-Apr-19   4
## 210            03-Apr-20   4
## 211            03-Apr-21   1
## 212            03-Aug-17   1
## 213            03-Aug-18   4
## 214            03-Aug-19   1
## 215            03-Aug-20   1
## 216            03-Aug-21  10
## 217            03-Dec-16   3
## 218            03-Dec-18   3
## 219            03-Dec-19   4
## 220            03-Dec-20   5
## 221            03-Feb-17   2
## 222            03-Feb-19   1
## 223            03-Feb-20   3
## 224            03-Feb-21   5
## 225            03-Jan-17   1
## 226            03-Jan-19   2
## 227            03-Jan-20   3
## 228            03-Jan-21   1
## 229            03-Jul-18   4
## 230            03-Jul-19   2
## 231            03-Jul-20   9
## 232            03-Jul-21   1
## 233            03-Jun-16   1
## 234            03-Jun-17   3
## 235            03-Jun-19   2
## 236            03-Jun-20   3
## 237            03-Jun-21   8
## 238            03-Mar-17   1
## 239            03-Mar-19   2
## 240            03-Mar-20   8
## 241            03-Mar-21   2
## 242            03-May-18   1
## 243            03-May-19  10
## 244            03-May-20   1
## 245            03-Nov-17   2
## 246            03-Nov-18   2
## 247            03-Nov-20   4
## 248            03-Oct-17   2
## 249            03-Oct-18   3
## 250            03-Oct-19   2
## 251            03-Oct-20   4
## 252            03-Sep-18   1
## 253            03-Sep-20   4
## 254            03-Sep-21   5
## 255            04-Apr-17   1
## 256            04-Apr-18   3
## 257            04-Apr-19   1
## 258            04-Apr-20   2
## 259            04-Apr-21   2
## 260            04-Aug-17   5
## 261            04-Aug-18   4
## 262            04-Aug-20   4
## 263            04-Aug-21   7
## 264            04-Dec-15   1
## 265            04-Dec-16   1
## 266            04-Dec-18   3
## 267            04-Dec-19   3
## 268            04-Dec-20   9
## 269            04-Feb-08   1
## 270            04-Feb-16   1
## 271            04-Feb-17   1
## 272            04-Feb-18   1
## 273            04-Feb-20   4
## 274            04-Jan-17   1
## 275            04-Jan-19   5
## 276            04-Jan-20   1
## 277            04-Jan-21   3
## 278            04-Jul-16   1
## 279            04-Jul-17   1
## 280            04-Jul-18   1
## 281            04-Jul-19   4
## 282            04-Jul-20   1
## 283            04-Jul-21   1
## 284            04-Jun-18   2
## 285            04-Jun-19   4
## 286            04-Jun-20   3
## 287            04-Jun-21   9
## 288            04-Mar-17   1
## 289            04-Mar-18   1
## 290            04-Mar-19   6
## 291            04-Mar-20   4
## 292            04-Mar-21   4
## 293            04-May-17   1
## 294            04-May-18  10
## 295            04-May-20   2
## 296            04-May-21   4
## 297            04-Nov-16   3
## 298            04-Nov-17   1
## 299            04-Nov-19   9
## 300            04-Nov-20   4
## 301            04-Oct-16   1
## 302            04-Oct-18   4
## 303            04-Oct-19  10
## 304            04-Oct-20   1
## 305            04-Sep-17   2
## 306            04-Sep-18   2
## 307            04-Sep-19   3
## 308            04-Sep-20   6
## 309            04-Sep-21   1
## 310            05-Apr-16   1
## 311            05-Apr-18   2
## 312            05-Apr-19  15
## 313            05-Apr-20   2
## 314            05-Apr-21   2
## 315            05-Aug-15   1
## 316            05-Aug-16   1
## 317            05-Aug-17   4
## 318            05-Aug-18   1
## 319            05-Aug-19   5
## 320            05-Aug-20   3
## 321            05-Aug-21   5
## 322            05-Dec-14   1
## 323            05-Dec-16   2
## 324            05-Dec-17   1
## 325            05-Dec-18   1
## 326            05-Dec-19   3
## 327            05-Dec-20   2
## 328            05-Feb-16   3
## 329            05-Feb-17   2
## 330            05-Feb-18   4
## 331            05-Feb-19   6
## 332            05-Feb-20   4
## 333            05-Feb-21  10
## 334            05-Jan-17   3
## 335            05-Jan-18   3
## 336            05-Jan-19   7
## 337            05-Jan-21   3
## 338            05-Jul-18   1
## 339            05-Jul-19   2
## 340            05-Jul-20  29
## 341            05-Jun-17   2
## 342            05-Jun-18   1
## 343            05-Jun-19   6
## 344            05-Jun-20   9
## 345            05-Jun-21   3
## 346            05-Mar-18   1
## 347            05-Mar-19   5
## 348            05-Mar-20   5
## 349            05-Mar-21   7
## 350            05-May-09   1
## 351            05-May-16   1
## 352            05-May-17   5
## 353            05-May-18   3
## 354            05-May-19   1
## 355            05-May-20   1
## 356            05-May-21   3
## 357            05-Nov-17   1
## 358            05-Nov-18   2
## 359            05-Nov-19   7
## 360            05-Nov-20   7
## 361            05-Oct-18   9
## 362            05-Oct-19   3
## 363            05-Oct-20   1
## 364            05-Sep-17   4
## 365            05-Sep-18   7
## 366            05-Sep-19   1
## 367            05-Sep-20   3
## 368            05-Sep-21   2
## 369            06-Apr-17   1
## 370            06-Apr-18  10
## 371            06-Apr-19   1
## 372            06-Apr-20   2
## 373            06-Apr-21   1
## 374            06-Aug-17   2
## 375            06-Aug-19   6
## 376            06-Aug-20   3
## 377            06-Aug-21   5
## 378            06-Dec-16   4
## 379            06-Dec-17   1
## 380            06-Dec-18   1
## 381            06-Dec-19  16
## 382            06-Feb-16   1
## 383            06-Feb-18   3
## 384            06-Feb-19   2
## 385            06-Feb-20   3
## 386            06-Feb-21   1
## 387            06-Jan-17   4
## 388            06-Jan-18   2
## 389            06-Jan-21   3
## 390            06-Jul-16   1
## 391            06-Jul-17   2
## 392            06-Jul-18   6
## 393            06-Jul-19   2
## 394            06-Jul-20   2
## 395            06-Jul-21  39
## 396            06-Jun-19  16
## 397            06-Jun-20   3
## 398            06-Jun-21   1
## 399            06-Mar-15   2
## 400            06-Mar-18   6
## 401            06-Mar-19   2
## 402            06-Mar-20   8
## 403            06-Mar-21   1
## 404            06-May-16   1
## 405            06-May-19   4
## 406            06-May-20   3
## 407            06-May-21   2
## 408            06-Nov-17   1
## 409            06-Nov-19   3
## 410            06-Nov-20   9
## 411            06-Oct-17   4
## 412            06-Oct-18   2
## 413            06-Oct-19   1
## 414            06-Oct-20   5
## 415            06-Sep-16   1
## 416            06-Sep-17   1
## 417            06-Sep-18   2
## 418            06-Sep-19   5
## 419            06-Sep-21   3
## 420            07-Apr-17   5
## 421            07-Apr-18   1
## 422            07-Apr-19   2
## 423            07-Apr-20   2
## 424            07-Apr-21   4
## 425            07-Aug-17   8
## 426            07-Aug-19   3
## 427            07-Aug-20  10
## 428            07-Aug-21   2
## 429            07-Dec-17   1
## 430            07-Dec-18  10
## 431            07-Dec-19   2
## 432            07-Dec-20   5
## 433            07-Feb-17   1
## 434            07-Feb-19   2
## 435            07-Feb-20   9
## 436            07-Feb-21   1
## 437            07-Jan-17   2
## 438            07-Jan-19   2
## 439            07-Jan-20   2
## 440            07-Jan-21   3
## 441            07-Jul-15   1
## 442            07-Jul-16   1
## 443            07-Jul-17   8
## 444            07-Jul-19   1
## 445            07-Jul-20   2
## 446            07-Jul-21  13
## 447            07-Jun-18   3
## 448            07-Jun-19  12
## 449            07-Jun-20   3
## 450            07-Jun-21   1
## 451            07-Mar-16   1
## 452            07-Mar-17   1
## 453            07-Mar-18   2
## 454            07-Mar-19   6
## 455            07-May-17   1
## 456            07-May-18   1
## 457            07-May-19   6
## 458            07-May-20   5
## 459            07-May-21   9
## 460            07-Nov-14   1
## 461            07-Nov-17   5
## 462            07-Nov-18   3
## 463            07-Nov-19   1
## 464            07-Oct-16   4
## 465            07-Oct-17   1
## 466            07-Oct-19   1
## 467            07-Oct-20   2
## 468            07-Sep-17   1
## 469            07-Sep-18   9
## 470            07-Sep-20   5
## 471            07-Sep-21   6
## 472            08-Apr-16   1
## 473            08-Apr-17   2
## 474            08-Apr-19   2
## 475            08-Apr-20   2
## 476            08-Apr-21   2
## 477            08-Aug-17   1
## 478            08-Aug-18   2
## 479            08-Aug-19  13
## 480            08-Aug-20   3
## 481            08-Aug-21   2
## 482            08-Dec-16   4
## 483            08-Dec-17   4
## 484            08-Dec-18   5
## 485            08-Dec-19   1
## 486            08-Dec-20   8
## 487            08-Feb-16   1
## 488            08-Feb-17   3
## 489            08-Feb-18   1
## 490            08-Feb-19   7
## 491            08-Feb-20   2
## 492            08-Feb-21   2
## 493            08-Jan-16   1
## 494            08-Jan-18   1
## 495            08-Jan-19   1
## 496            08-Jan-20   1
## 497            08-Jan-21  11
## 498            08-Jul-16   1
## 499            08-Jul-18   1
## 500            08-Jul-19   1
## 501            08-Jul-20   4
## 502            08-Jul-21   6
## 503            08-Jun-17   1
## 504            08-Jun-18   4
## 505            08-Jun-19   3
## 506            08-Jun-20   1
## 507            08-Jun-21   1
## 508            08-Mar-17   1
## 509            08-Mar-18   2
## 510            08-Mar-19  12
## 511            08-Mar-20   1
## 512            08-Mar-21   2
## 513            08-May-16   1
## 514            08-May-17   1
## 515            08-May-18   3
## 516            08-May-19   9
## 517            08-May-20   6
## 518            08-May-21   2
## 519            08-Nov-18   6
## 520            08-Nov-19   5
## 521            08-Oct-18   2
## 522            08-Oct-19   2
## 523            08-Oct-20   5
## 524            08-Sep-15   1
## 525            08-Sep-17  21
## 526            08-Sep-18   2
## 527            08-Sep-20   4
## 528            08-Sep-21   4
## 529            09-Apr-16   1
## 530            09-Apr-18   2
## 531            09-Apr-19   2
## 532            09-Apr-20   2
## 533            09-Apr-21   6
## 534            09-Aug-17   1
## 535            09-Aug-18   2
## 536            09-Aug-19   8
## 537            09-Aug-21   1
## 538            09-Dec-15   1
## 539            09-Dec-16   5
## 540            09-Dec-18   1
## 541            09-Dec-19   2
## 542            09-Dec-20   7
## 543            09-Feb-18   5
## 544            09-Feb-19   3
## 545            09-Feb-20   3
## 546            09-Feb-21   1
## 547            09-Jan-18   2
## 548            09-Jan-19   5
## 549            09-Jan-20   2
## 550            09-Jul-19   2
## 551            09-Jul-20   3
## 552            09-Jul-21  12
## 553            09-Jun-17   2
## 554            09-Jun-21   5
## 555            09-Mar-16   1
## 556            09-Mar-17   4
## 557            09-Mar-18   4
## 558            09-Mar-19   2
## 559            09-Mar-21   1
## 560            09-May-17   1
## 561            09-May-19   7
## 562            09-May-20   1
## 563            09-May-21   2
## 564            09-Nov-16   2
## 565            09-Nov-18   9
## 566            09-Nov-19   1
## 567            09-Oct-15   1
## 568            09-Oct-18   3
## 569            09-Oct-19   3
## 570            09-Oct-20   6
## 571            09-Sep-16   1
## 572            09-Sep-18   1
## 573            09-Sep-19   1
## 574            09-Sep-20   6
## 575            09-Sep-21   4
## 576            10-Apr-17   2
## 577            10-Apr-18   1
## 578            10-Apr-19   4
## 579            10-Apr-20   8
## 580            10-Apr-21   1
## 581            10-Aug-17   4
## 582            10-Aug-18   7
## 583            10-Aug-20   4
## 584            10-Aug-21   5
## 585            10-Dec-16   2
## 586            10-Dec-18   4
## 587            10-Dec-19   2
## 588            10-Dec-20   6
## 589            10-Feb-17   4
## 590            10-Feb-20   1
## 591            10-Feb-21   3
## 592            10-Jan-17   2
## 593            10-Jan-18   3
## 594            10-Jan-19   3
## 595            10-Jan-20  11
## 596            10-Jan-21   1
## 597            10-Jul-15   1
## 598            10-Jul-16   1
## 599            10-Jul-17   1
## 600            10-Jul-18   2
## 601            10-Jul-20   8
## 602            10-Jul-21   3
## 603            10-Jun-17   9
## 604            10-Jun-19   1
## 605            10-Jun-20   7
## 606            10-Jun-21   6
## 607            10-Mar-17  22
## 608            10-Mar-18   2
## 609            10-Mar-19   1
## 610            10-Mar-20   2
## 611            10-Mar-21   3
## 612            10-May-15   1
## 613            10-May-17   2
## 614            10-May-19  11
## 615            10-May-21   1
## 616            10-Nov-16   2
## 617            10-Nov-17   7
## 618            10-Nov-18   3
## 619            10-Nov-20   2
## 620            10-Oct-14   1
## 621            10-Oct-15   2
## 622            10-Oct-17   1
## 623            10-Oct-18   4
## 624            10-Oct-19   3
## 625            10-Sep-19   4
## 626            10-Sep-20  15
## 627            10-Sep-21   8
## 628            11-Apr-17   1
## 629            11-Apr-19   2
## 630            11-Apr-20   2
## 631            11-Apr-21   1
## 632            11-Aug-16   4
## 633            11-Aug-17   1
## 634            11-Aug-20   2
## 635            11-Aug-21   6
## 636            11-Dec-15   1
## 637            11-Dec-16   1
## 638            11-Dec-17   3
## 639            11-Dec-18   2
## 640            11-Dec-19   1
## 641            11-Dec-20   6
## 642            11-Feb-17   1
## 643            11-Feb-19   1
## 644            11-Feb-20   3
## 645            11-Feb-21   8
## 646            11-Jan-18   1
## 647            11-Jan-19   8
## 648            11-Jan-20   1
## 649            11-Jan-21   2
## 650            11-Jul-14   1
## 651            11-Jul-18   1
## 652            11-Jul-19   2
## 653            11-Jul-20   1
## 654            11-Jun-19   1
## 655            11-Jun-20   2
## 656            11-Jun-21   7
## 657            11-Mar-16   1
## 658            11-Mar-18   2
## 659            11-Mar-19   2
## 660            11-Mar-20   6
## 661            11-Mar-21   3
## 662            11-May-18   6
## 663            11-May-19   4
## 664            11-May-20   5
## 665            11-May-21   3
## 666            11-Nov-16   2
## 667            11-Nov-17   1
## 668            11-Nov-19   4
## 669            11-Nov-20   6
## 670            11-Oct-18   4
## 671            11-Oct-19   8
## 672            11-Oct-20   1
## 673            11-Sep-17   1
## 674            11-Sep-18   3
## 675            11-Sep-19   1
## 676            11-Sep-20   9
## 677            11-Sep-21   3
## 678            12-Apr-17   2
## 679            12-Apr-18   1
## 680            12-Apr-19   9
## 681            12-Apr-21   2
## 682            12-Aug-17   2
## 683            12-Aug-19   1
## 684            12-Aug-20   3
## 685            12-Aug-21   3
## 686            12-Dec-13   1
## 687            12-Dec-14   1
## 688            12-Dec-16   1
## 689            12-Dec-17   4
## 690            12-Dec-18   2
## 691            12-Dec-19   1
## 692            12-Dec-20   2
## 693            12-Feb-17   1
## 694            12-Feb-19   2
## 695            12-Feb-20   3
## 696            12-Feb-21   7
## 697            12-Jan-17   2
## 698            12-Jan-18   6
## 699            12-Jan-19   2
## 700            12-Jan-20   2
## 701            12-Jan-21   3
## 702            12-Jul-17   1
## 703            12-Jul-19  20
## 704            12-Jul-21   1
## 705            12-Jun-18   2
## 706            12-Jun-19   2
## 707            12-Jun-20  15
## 708            12-Jun-21   4
## 709            12-Mar-18   2
## 710            12-Mar-19   3
## 711            12-Mar-21  12
## 712            12-May-17   4
## 713            12-May-18   1
## 714            12-May-19   2
## 715            12-May-20   3
## 716            12-May-21   4
## 717            12-Nov-17   1
## 718            12-Nov-18   1
## 719            12-Nov-19   2
## 720            12-Nov-20   8
## 721            12-Oct-14   1
## 722            12-Oct-16   1
## 723            12-Oct-17   2
## 724            12-Oct-18  11
## 725            12-Oct-20   6
## 726            12-Sep-17   2
## 727            12-Sep-18   2
## 728            12-Sep-19   3
## 729            13-Apr-18   5
## 730            13-Apr-19   2
## 731            13-Apr-20   4
## 732            13-Apr-21   9
## 733            13-Aug-16   1
## 734            13-Aug-17   2
## 735            13-Aug-19   5
## 736            13-Aug-20   6
## 737            13-Aug-21   7
## 738            13-Dec-16   1
## 739            13-Dec-19   8
## 740            13-Dec-20   1
## 741            13-Feb-15   1
## 742            13-Feb-18   1
## 743            13-Feb-19   1
## 744            13-Feb-20   5
## 745            13-Feb-21   1
## 746            13-Jan-17   3
## 747            13-Jan-19   3
## 748            13-Jan-20   2
## 749            13-Jan-21   2
## 750            13-Jul-17   3
## 751            13-Jul-18   6
## 752            13-Jul-19   1
## 753            13-Jul-21   4
## 754            13-Jun-16   1
## 755            13-Jun-17   2
## 756            13-Jun-19   9
## 757            13-Jun-20   5
## 758            13-Jun-21   3
## 759            13-Mar-18   3
## 760            13-Mar-19   3
## 761            13-Mar-20   9
## 762            13-May-17   1
## 763            13-May-18   1
## 764            13-May-19   1
## 765            13-May-20   2
## 766            13-May-21   4
## 767            13-Nov-15   2
## 768            13-Nov-17   1
## 769            13-Nov-18   3
## 770            13-Nov-19   1
## 771            13-Nov-20   8
## 772            13-Oct-16   1
## 773            13-Oct-17   6
## 774            13-Oct-18   1
## 775            13-Oct-19   2
## 776            13-Oct-20   3
## 777            13-Sep-16   1
## 778            13-Sep-17   2
## 779            13-Sep-18   2
## 780            13-Sep-19  12
## 781            14-Apr-17   5
## 782            14-Apr-18   1
## 783            14-Apr-19   2
## 784            14-Apr-20   2
## 785            14-Apr-21  15
## 786            14-Aug-15   1
## 787            14-Aug-17   4
## 788            14-Aug-19   2
## 789            14-Aug-20  10
## 790            14-Dec-16   1
## 791            14-Dec-17   1
## 792            14-Dec-18   9
## 793            14-Dec-20   3
## 794            14-Feb-16   1
## 795            14-Feb-17   4
## 796            14-Feb-18   3
## 797            14-Feb-19   4
## 798            14-Feb-20  10
## 799            14-Feb-21   1
## 800            14-Jan-17   4
## 801            14-Jan-19   2
## 802            14-Jan-20   3
## 803            14-Jan-21   2
## 804            14-Jul-15   1
## 805            14-Jul-16   2
## 806            14-Jul-17   3
## 807            14-Jul-18   3
## 808            14-Jul-20   3
## 809            14-Jul-21   6
## 810            14-Jun-18   1
## 811            14-Jun-19  10
## 812            14-Jun-21   1
## 813            14-Mar-17   4
## 814            14-Mar-18   1
## 815            14-Mar-19   6
## 816            14-Mar-20   1
## 817            14-Mar-21   1
## 818            14-May-17   1
## 819            14-May-19   4
## 820            14-May-20   8
## 821            14-May-21  14
## 822            14-Nov-12   1
## 823            14-Nov-14   1
## 824            14-Nov-17   1
## 825            14-Nov-19   3
## 826            14-Nov-20   1
## 827            14-Oct-13   2
## 828            14-Oct-15   1
## 829            14-Oct-16   1
## 830            14-Oct-17   1
## 831            14-Oct-19   1
## 832            14-Oct-20   3
## 833            14-Sep-18  11
## 834            14-Sep-19   2
## 835            14-Sep-20   1
## 836            14-Sep-21   6
## 837            15-Apr-14   1
## 838            15-Apr-16   3
## 839            15-Apr-17  12
## 840            15-Apr-18   5
## 841            15-Apr-19  10
## 842            15-Apr-20  12
## 843            15-Apr-21  18
## 844            15-Aug-14   1
## 845            15-Aug-16   6
## 846            15-Aug-17   8
## 847            15-Aug-18   6
## 848            15-Aug-19   5
## 849            15-Aug-20   4
## 850            15-Aug-21   5
## 851            15-Dec-15   2
## 852            15-Dec-16  18
## 853            15-Dec-17  23
## 854            15-Dec-18  16
## 855            15-Dec-19  29
## 856            15-Dec-20   7
## 857            15-Feb-15   1
## 858            15-Feb-17   8
## 859            15-Feb-18  13
## 860            15-Feb-19  24
## 861            15-Feb-20   3
## 862            15-Feb-21   3
## 863            15-Jan-16   2
## 864            15-Jan-17  10
## 865            15-Jan-18  12
## 866            15-Jan-19  15
## 867            15-Jan-20   8
## 868            15-Jan-21  13
## 869            15-Jul-15   2
## 870            15-Jul-16   4
## 871            15-Jul-17   3
## 872            15-Jul-18  14
## 873            15-Jul-19   5
## 874            15-Jul-20   7
## 875            15-Jul-21  11
## 876            15-Jun-14   1
## 877            15-Jun-15   1
## 878            15-Jun-17   6
## 879            15-Jun-18  10
## 880            15-Jun-19  11
## 881            15-Jun-20   4
## 882            15-Jun-21  12
## 883            15-Mar-15   2
## 884            15-Mar-17   8
## 885            15-Mar-18  23
## 886            15-Mar-19  21
## 887            15-Mar-20   7
## 888            15-Mar-21   6
## 889            15-May-16   1
## 890            15-May-17  12
## 891            15-May-18   6
## 892            15-May-19   7
## 893            15-May-20  15
## 894            15-May-21   3
## 895            15-Nov-16   4
## 896            15-Nov-17   5
## 897            15-Nov-18  15
## 898            15-Nov-19  24
## 899            15-Nov-20   9
## 900            15-Oct-16   9
## 901            15-Oct-17  23
## 902            15-Oct-18   4
## 903            15-Oct-19   3
## 904            15-Oct-20  11
## 905            15-Sep-15   1
## 906            15-Sep-16   3
## 907            15-Sep-17   9
## 908            15-Sep-18  15
## 909            15-Sep-19   9
## 910            15-Sep-20  10
## 911            15-Sep-21  22
## 912            16-Apr-15   1
## 913            16-Apr-17   1
## 914            16-Apr-18   2
## 915            16-Apr-19   5
## 916            16-Apr-20   8
## 917            16-Apr-21  15
## 918            16-Aug-17   1
## 919            16-Aug-18  22
## 920            16-Aug-19  14
## 921            16-Aug-20   3
## 922            16-Aug-21   2
## 923            16-Dec-16   6
## 924            16-Dec-17   2
## 925            16-Dec-18   9
## 926            16-Dec-19   3
## 927            16-Dec-20  11
## 928            16-Feb-14   1
## 929            16-Feb-17   2
## 930            16-Feb-18   5
## 931            16-Feb-19   3
## 932            16-Feb-20   6
## 933            16-Feb-21   4
## 934            16-Jan-17   2
## 935            16-Jan-18   3
## 936            16-Jan-19   2
## 937            16-Jan-20   9
## 938            16-Jan-21   3
## 939            16-Jul-19   6
## 940            16-Jul-20   3
## 941            16-Jul-21  14
## 942            16-Jun-17   5
## 943            16-Jun-19   2
## 944            16-Jun-20   2
## 945            16-Jun-21   9
## 946            16-Mar-16   1
## 947            16-Mar-17   6
## 948            16-Mar-18   5
## 949            16-Mar-19   1
## 950            16-Mar-20   1
## 951            16-Mar-21   4
## 952            16-May-17   2
## 953            16-May-18   2
## 954            16-May-19   4
## 955            16-May-20   2
## 956            16-May-21   1
## 957            16-Nov-17   1
## 958            16-Nov-18   7
## 959            16-Nov-19   4
## 960            16-Nov-20   2
## 961            16-Oct-15   3
## 962            16-Oct-16   1
## 963            16-Oct-17   7
## 964            16-Oct-18   2
## 965            16-Oct-19   7
## 966            16-Oct-20   8
## 967            16-Sep-16   5
## 968            16-Sep-18   2
## 969            16-Sep-19   1
## 970            16-Sep-20   9
## 971            16-Sep-21  12
## 972            17-Apr-15   1
## 973            17-Apr-16   1
## 974            17-Apr-18   3
## 975            17-Apr-19   5
## 976            17-Apr-20   8
## 977            17-Apr-21   8
## 978            17-Aug-17   1
## 979            17-Aug-18   5
## 980            17-Aug-20   3
## 981            17-Dec-14   1
## 982            17-Dec-15   1
## 983            17-Dec-18   3
## 984            17-Dec-19   1
## 985            17-Dec-20   9
## 986            17-Feb-17   5
## 987            17-Feb-18   1
## 988            17-Feb-19   2
## 989            17-Feb-20   2
## 990            17-Feb-21   4
## 991            17-Jan-14   1
## 992            17-Jan-17   4
## 993            17-Jan-18   2
## 994            17-Jan-20   5
## 995            17-Jul-15   1
## 996            17-Jul-17   1
## 997            17-Jul-18   1
## 998            17-Jul-19   3
## 999            17-Jul-20   5
## 1000           17-Jul-21   1
## 1001           17-Jun-17   1
## 1002           17-Jun-20   2
## 1003           17-Jun-21  11
## 1004           17-Mar-17   5
## 1005           17-Mar-19   2
## 1006           17-Mar-20   3
## 1007           17-Mar-21   3
## 1008           17-May-11   1
## 1009           17-May-15   1
## 1010           17-May-18   1
## 1011           17-May-19  11
## 1012           17-May-20   3
## 1013           17-Nov-16   1
## 1014           17-Nov-17   8
## 1015           17-Nov-18   3
## 1016           17-Nov-19   1
## 1017           17-Nov-20   4
## 1018           17-Oct-17   1
## 1019           17-Oct-18   2
## 1020           17-Oct-19   2
## 1021           17-Oct-20   1
## 1022           17-Sep-16   1
## 1023           17-Sep-17   1
## 1024           17-Sep-18   1
## 1025           17-Sep-19   6
## 1026           17-Sep-20   7
## 1027           17-Sep-21   7
## 1028           18-Apr-17   2
## 1029           18-Apr-18   1
## 1030           18-Apr-19   6
## 1031           18-Apr-20   3
## 1032           18-Aug-17   4
## 1033           18-Aug-18   3
## 1034           18-Aug-20   2
## 1035           18-Aug-21  11
## 1036           18-Dec-14   1
## 1037           18-Dec-15   1
## 1038           18-Dec-17   2
## 1039           18-Dec-18   2
## 1040           18-Dec-19   2
## 1041           18-Dec-20  10
## 1042           18-Feb-16   2
## 1043           18-Feb-21   5
## 1044           18-Jan-17   1
## 1045           18-Jan-18   2
## 1046           18-Jan-19  13
## 1047           18-Jan-20   1
## 1048           18-Jan-21   1
## 1049           18-Jul-17   3
## 1050           18-Jul-18   3
## 1051           18-Jul-19   3
## 1052           18-Jul-20   3
## 1053           18-Jun-16   1
## 1054           18-Jun-18   4
## 1055           18-Jun-19   8
## 1056           18-Jun-20  15
## 1057           18-Jun-21  10
## 1058           18-Mar-16   4
## 1059           18-Mar-17   2
## 1060           18-Mar-19   1
## 1061           18-Mar-20   5
## 1062           18-Mar-21   8
## 1063           18-May-17   1
## 1064           18-May-18   3
## 1065           18-May-19   2
## 1066           18-May-20   2
## 1067           18-May-21   2
## 1068           18-Nov-09   1
## 1069           18-Nov-15   1
## 1070           18-Nov-16   4
## 1071           18-Nov-17   1
## 1072           18-Nov-18   1
## 1073           18-Nov-20   1
## 1074           18-Oct-17   1
## 1075           18-Oct-18   1
## 1076           18-Oct-19  22
## 1077           18-Oct-20   3
## 1078           18-Sep-15   1
## 1079           18-Sep-17   5
## 1080           18-Sep-18   1
## 1081           18-Sep-19   2
## 1082           18-Sep-20   5
## 1083           19-Apr-17   2
## 1084           19-Apr-18   3
## 1085           19-Apr-19  14
## 1086           19-Apr-21   4
## 1087           19-Aug-16   1
## 1088           19-Aug-17   2
## 1089           19-Aug-18   3
## 1090           19-Aug-20   3
## 1091           19-Aug-21   2
## 1092           19-Dec-14   1
## 1093           19-Dec-16   2
## 1094           19-Dec-17   5
## 1095           19-Dec-18   1
## 1096           19-Dec-19   3
## 1097           19-Dec-20   1
## 1098           19-Feb-16   1
## 1099           19-Feb-17   3
## 1100           19-Feb-18   5
## 1101           19-Feb-19   2
## 1102           19-Feb-21   5
## 1103           19-Jan-17   1
## 1104           19-Jan-18   3
## 1105           19-Jan-19   1
## 1106           19-Jan-21   1
## 1107           19-Jul-17   1
## 1108           19-Jul-18   7
## 1109           19-Jul-19   5
## 1110           19-Jul-20   1
## 1111           19-Jul-21   1
## 1112           19-Jun-17   1
## 1113           19-Jun-18   2
## 1114           19-Jun-19   5
## 1115           19-Jun-20  12
## 1116           19-Jun-21  24
## 1117           19-Mar-16   1
## 1118           19-Mar-18   1
## 1119           19-Mar-19   3
## 1120           19-Mar-20   4
## 1121           19-Mar-21   6
## 1122           19-May-17   6
## 1123           19-May-18   1
## 1124           19-May-19   1
## 1125           19-May-20  13
## 1126           19-May-21   5
## 1127           19-Nov-14   1
## 1128           19-Nov-16   1
## 1129           19-Nov-19   2
## 1130           19-Nov-20  11
## 1131           19-Oct-17   1
## 1132           19-Oct-18  18
## 1133           19-Oct-19   3
## 1134           19-Oct-20  16
## 1135           19-Sep-16   7
## 1136           19-Sep-17   1
## 1137           19-Sep-18   2
## 1138           19-Sep-19   2
## 1139           19-Sep-20   6
## 1140           19-Sep-21   2
## 1141           20-Apr-16   1
## 1142           20-Apr-18   5
## 1143           20-Apr-19   3
## 1144           20-Apr-20   4
## 1145           20-Apr-21   7
## 1146           20-Aug-17   1
## 1147           20-Aug-18   1
## 1148           20-Aug-19   3
## 1149           20-Aug-20   5
## 1150           20-Aug-21   8
## 1151           20-Dec-15   3
## 1152           20-Dec-16   4
## 1153           20-Dec-17   3
## 1154           20-Dec-18   7
## 1155           20-Dec-19   7
## 1156           20-Dec-20   2
## 1157           20-Feb-17   1
## 1158           20-Feb-18   4
## 1159           20-Feb-19   2
## 1160           20-Feb-20   3
## 1161           20-Feb-21   4
## 1162           20-Jan-17   3
## 1163           20-Jan-18   1
## 1164           20-Jan-20   3
## 1165           20-Jan-21   4
## 1166           20-Jul-17   2
## 1167           20-Jul-18  10
## 1168           20-Jul-19   2
## 1169           20-Jul-21   3
## 1170           20-Jun-16   1
## 1171           20-Jun-17   4
## 1172           20-Jun-18   1
## 1173           20-Jun-19   9
## 1174           20-Jun-20   1
## 1175           20-Jun-21   1
## 1176           20-Mar-17   2
## 1177           20-Mar-18   2
## 1178           20-Mar-19   6
## 1179           20-Mar-20  12
## 1180           20-Mar-21   4
## 1181           20-May-19   2
## 1182           20-May-20   8
## 1183           20-May-21   7
## 1184           20-Nov-18   7
## 1185           20-Nov-19  30
## 1186           20-Nov-20   8
## 1187           20-Oct-17   6
## 1188           20-Oct-18   2
## 1189           20-Oct-20   3
## 1190           20-Sep-16   1
## 1191           20-Sep-18   3
## 1192           20-Sep-19  10
## 1193           20-Sep-20   8
## 1194           20-Sep-21   1
## 1195           21-Apr-17   5
## 1196           21-Apr-19   1
## 1197           21-Apr-20   3
## 1198           21-Apr-21   3
## 1199           21-Aug-17   5
## 1200           21-Aug-18   5
## 1201           21-Aug-19   6
## 1202           21-Aug-20   8
## 1203           21-Aug-21   1
## 1204           21-Dec-16   1
## 1205           21-Dec-17   1
## 1206           21-Dec-18  13
## 1207           21-Dec-19   2
## 1208           21-Dec-20   2
## 1209           21-Feb-12   1
## 1210           21-Feb-17   1
## 1211           21-Feb-18   3
## 1212           21-Feb-19   2
## 1213           21-Feb-20   9
## 1214           21-Feb-21   3
## 1215           21-Jan-20   2
## 1216           21-Jan-21   2
## 1217           21-Jul-16   1
## 1218           21-Jul-17   1
## 1219           21-Jul-18   2
## 1220           21-Jul-19   8
## 1221           21-Jul-20   3
## 1222           21-Jul-21   4
## 1223           21-Jun-17   2
## 1224           21-Jun-19  14
## 1225           21-Jun-20   2
## 1226           21-Jun-21   4
## 1227           21-Mar-17   4
## 1228           21-Mar-18   1
## 1229           21-Mar-19   9
## 1230           21-Mar-20   1
## 1231           21-May-19   2
## 1232           21-May-20  12
## 1233           21-May-21   8
## 1234           21-Nov-14   1
## 1235           21-Nov-16   1
## 1236           21-Nov-17   4
## 1237           21-Nov-18   2
## 1238           21-Nov-19   2
## 1239           21-Oct-14   1
## 1240           21-Oct-16   2
## 1241           21-Oct-17   1
## 1242           21-Oct-18   1
## 1243           21-Oct-19   1
## 1244           21-Oct-20   3
## 1245           21-Sep-18   6
## 1246           21-Sep-19   4
## 1247           21-Sep-20   1
## 1248           21-Sep-21   5
## 1249           22-Apr-15   3
## 1250           22-Apr-16   2
## 1251           22-Apr-17   6
## 1252           22-Apr-19   1
## 1253           22-Apr-20   7
## 1254           22-Apr-21   5
## 1255           22-Aug-17   2
## 1256           22-Aug-20   2
## 1257           22-Dec-17   2
## 1258           22-Dec-18   5
## 1259           22-Dec-19   2
## 1260           22-Dec-20   8
## 1261           22-Feb-17  11
## 1262           22-Feb-18   1
## 1263           22-Feb-19  11
## 1264           22-Feb-20   2
## 1265           22-Feb-21   1
## 1266           22-Jan-16   1
## 1267           22-Jan-18   4
## 1268           22-Jan-20   3
## 1269           22-Jan-21   6
## 1270           22-Jul-18   2
## 1271           22-Jul-19   4
## 1272           22-Jul-20   4
## 1273           22-Jul-21  25
## 1274           22-Jun-17   2
## 1275           22-Jun-18   6
## 1276           22-Jun-19   2
## 1277           22-Jun-20   3
## 1278           22-Jun-21   5
## 1279           22-Mar-19   9
## 1280           22-Mar-20   1
## 1281           22-Mar-21   1
## 1282           22-May-15   2
## 1283           22-May-16   1
## 1284           22-May-17   7
## 1285           22-May-18   2
## 1286           22-May-19   2
## 1287           22-May-20   5
## 1288           22-May-21   1
## 1289           22-Nov-16   2
## 1290           22-Nov-17   3
## 1291           22-Nov-18   2
## 1292           22-Nov-19  11
## 1293           22-Nov-20   2
## 1294           22-Oct-15   1
## 1295           22-Oct-17   7
## 1296           22-Oct-18   1
## 1297           22-Oct-19   6
## 1298           22-Oct-20   7
## 1299           22-Sep-15   1
## 1300           22-Sep-17   2
## 1301           22-Sep-18   2
## 1302           22-Sep-19   1
## 1303           22-Sep-20   2
## 1304           22-Sep-21   9
## 1305           23-Apr-17   1
## 1306           23-Apr-19   1
## 1307           23-Apr-20   6
## 1308           23-Apr-21  20
## 1309           23-Aug-17   1
## 1310           23-Aug-18   2
## 1311           23-Aug-19   7
## 1312           23-Aug-20   1
## 1313           23-Aug-21   5
## 1314           23-Dec-16   4
## 1315           23-Dec-17   2
## 1316           23-Dec-18   3
## 1317           23-Dec-20   3
## 1318           23-Feb-17   2
## 1319           23-Feb-18   5
## 1320           23-Feb-19   1
## 1321           23-Feb-20   2
## 1322           23-Feb-21   4
## 1323           23-Jan-15   1
## 1324           23-Jan-16   1
## 1325           23-Jan-17   1
## 1326           23-Jan-18   3
## 1327           23-Jan-19   1
## 1328           23-Jan-20   6
## 1329           23-Jul-18   1
## 1330           23-Jul-19   2
## 1331           23-Jul-20   3
## 1332           23-Jul-21  11
## 1333           23-Jun-15   1
## 1334           23-Jun-17   4
## 1335           23-Jun-18   6
## 1336           23-Jun-19   1
## 1337           23-Jun-20   2
## 1338           23-Jun-21   5
## 1339           23-Mar-17   1
## 1340           23-Mar-18   8
## 1341           23-Mar-19   3
## 1342           23-Mar-20   2
## 1343           23-Mar-21   3
## 1344           23-May-16   1
## 1345           23-May-17   2
## 1346           23-May-19   1
## 1347           23-May-20   3
## 1348           23-May-21   1
## 1349           23-Nov-17   1
## 1350           23-Nov-18   3
## 1351           23-Nov-19   5
## 1352           23-Nov-20   4
## 1353           23-Oct-15   1
## 1354           23-Oct-17   1
## 1355           23-Oct-18   4
## 1356           23-Oct-19   4
## 1357           23-Oct-20   7
## 1358           23-Sep-16   3
## 1359           23-Sep-19   2
## 1360           23-Sep-20   2
## 1361           23-Sep-21   2
## 1362           24-Apr-18   2
## 1363           24-Apr-19   2
## 1364           24-Apr-20   6
## 1365           24-Apr-21   2
## 1366           24-Aug-18  10
## 1367           24-Aug-19   2
## 1368           24-Aug-20   1
## 1369           24-Aug-21   3
## 1370           24-Dec-18   2
## 1371           24-Dec-19   4
## 1372           24-Dec-20   3
## 1373           24-Feb-16   1
## 1374           24-Feb-17   3
## 1375           24-Feb-19   3
## 1376           24-Feb-21   6
## 1377           24-Jan-14   1
## 1378           24-Jan-17   1
## 1379           24-Jan-18   4
## 1380           24-Jan-19   3
## 1381           24-Jan-20   6
## 1382           24-Jul-16   1
## 1383           24-Jul-17   2
## 1384           24-Jul-18   3
## 1385           24-Jul-19   1
## 1386           24-Jul-20   8
## 1387           24-Jul-21   1
## 1388           24-Jun-16   3
## 1389           24-Jun-17   2
## 1390           24-Jun-18   1
## 1391           24-Jun-19   1
## 1392           24-Jun-20   4
## 1393           24-Jun-21   5
## 1394           24-Mar-17   4
## 1395           24-Mar-18   2
## 1396           24-Mar-19   1
## 1397           24-Mar-20   1
## 1398           24-Mar-21   1
## 1399           24-May-18   1
## 1400           24-May-19   7
## 1401           24-May-20   1
## 1402           24-May-21   1
## 1403           24-Nov-17   5
## 1404           24-Nov-19   3
## 1405           24-Nov-20   7
## 1406           24-Oct-14   1
## 1407           24-Oct-17   3
## 1408           24-Oct-18   1
## 1409           24-Oct-19   3
## 1410           24-Oct-20   2
## 1411           24-Sep-17   2
## 1412           24-Sep-18   1
## 1413           24-Sep-19   2
## 1414           24-Sep-20   2
## 1415           24-Sep-21  10
## 1416           25-Apr-16   1
## 1417           25-Apr-17   4
## 1418           25-Apr-18   3
## 1419           25-Apr-19   7
## 1420           25-Apr-20  11
## 1421           25-Aug-16   2
## 1422           25-Aug-17   4
## 1423           25-Aug-18   4
## 1424           25-Aug-19   1
## 1425           25-Aug-20   2
## 1426           25-Aug-21  12
## 1427           25-Dec-15   1
## 1428           25-Dec-16   1
## 1429           25-Dec-17   3
## 1430           25-Dec-18   2
## 1431           25-Dec-19   6
## 1432           25-Dec-20   4
## 1433           25-Feb-17   2
## 1434           25-Feb-18   1
## 1435           25-Feb-19   3
## 1436           25-Feb-20   2
## 1437           25-Feb-21   4
## 1438           25-Jan-17   1
## 1439           25-Jan-18   1
## 1440           25-Jan-19   7
## 1441           25-Jan-20   1
## 1442           25-Jul-16   1
## 1443           25-Jul-17   1
## 1444           25-Jul-18   8
## 1445           25-Jul-19   1
## 1446           25-Jul-20   3
## 1447           25-Jun-17   1
## 1448           25-Jun-18   2
## 1449           25-Jun-19   2
## 1450           25-Jun-20   3
## 1451           25-Jun-21   4
## 1452           25-Mar-16   1
## 1453           25-Mar-19   2
## 1454           25-Mar-20   4
## 1455           25-Mar-21   4
## 1456           25-May-17   1
## 1457           25-May-18   5
## 1458           25-May-19   2
## 1459           25-May-20   5
## 1460           25-May-21   2
## 1461           25-Nov-16   3
## 1462           25-Nov-18   2
## 1463           25-Nov-19   2
## 1464           25-Nov-20   4
## 1465           25-Oct-15   1
## 1466           25-Oct-17   2
## 1467           25-Oct-18   4
## 1468           25-Oct-19  16
## 1469           25-Oct-20   1
## 1470           25-Sep-17   3
## 1471           25-Sep-18   1
## 1472           25-Sep-19   8
## 1473           25-Sep-20   6
## 1474           25-Sep-21   1
## 1475           26-Apr-17   1
## 1476           26-Apr-18   2
## 1477           26-Apr-19  12
## 1478           26-Apr-20   2
## 1479           26-Aug-16   4
## 1480           26-Aug-17   2
## 1481           26-Aug-18   1
## 1482           26-Aug-19   1
## 1483           26-Aug-20   5
## 1484           26-Aug-21   2
## 1485           26-Dec-15   1
## 1486           26-Dec-16   4
## 1487           26-Dec-17   3
## 1488           26-Dec-18   1
## 1489           26-Dec-19   3
## 1490           26-Dec-20   3
## 1491           26-Feb-16   2
## 1492           26-Feb-17   1
## 1493           26-Feb-18   3
## 1494           26-Feb-19   1
## 1495           26-Feb-20   8
## 1496           26-Feb-21  10
## 1497           26-Jan-17   1
## 1498           26-Jan-18   6
## 1499           26-Jan-19   2
## 1500           26-Jan-20   2
## 1501           26-Jan-21   4
## 1502           26-Jul-18  11
## 1503           26-Jul-19  13
## 1504           26-Jul-20   2
## 1505           26-Jul-21   2
## 1506           26-Jun-15   1
## 1507           26-Jun-17   2
## 1508           26-Jun-18   3
## 1509           26-Jun-19   5
## 1510           26-Jun-20  10
## 1511           26-Jun-21   2
## 1512           26-Mar-18   1
## 1513           26-Mar-19   1
## 1514           26-Mar-20   6
## 1515           26-Mar-21  11
## 1516           26-May-16   1
## 1517           26-May-17   5
## 1518           26-May-18   2
## 1519           26-May-19   2
## 1520           26-May-20   1
## 1521           26-May-21   5
## 1522           26-Nov-19   5
## 1523           26-Nov-20   4
## 1524           26-Oct-17   1
## 1525           26-Oct-18   8
## 1526           26-Oct-19   2
## 1527           26-Oct-20   1
## 1528           26-Sep-14   1
## 1529           26-Sep-17   3
## 1530           26-Sep-18   1
## 1531           26-Sep-19   3
## 1532           26-Sep-20   2
## 1533           27-Apr-17   1
## 1534           27-Apr-18   9
## 1535           27-Apr-19   1
## 1536           27-Apr-20   3
## 1537           27-Apr-21   5
## 1538           27-Aug-17   1
## 1539           27-Aug-18   2
## 1540           27-Aug-19   1
## 1541           27-Aug-20   6
## 1542           27-Aug-21  27
## 1543           27-Dec-16   2
## 1544           27-Dec-17   3
## 1545           27-Dec-18   1
## 1546           27-Dec-19   5
## 1547           27-Dec-20   2
## 1548           27-Feb-15   1
## 1549           27-Feb-17   1
## 1550           27-Feb-18   2
## 1551           27-Feb-19  15
## 1552           27-Feb-20   6
## 1553           27-Jan-17   3
## 1554           27-Jan-19   2
## 1555           27-Jan-20   2
## 1556           27-Jan-21   6
## 1557           27-Jul-18   6
## 1558           27-Jul-21   8
## 1559           27-Jun-17   1
## 1560           27-Jun-18   1
## 1561           27-Jun-19   3
## 1562           27-Jun-20   2
## 1563           27-Mar-18   2
## 1564           27-Mar-19   2
## 1565           27-Mar-20  12
## 1566           27-May-16   1
## 1567           27-May-18   1
## 1568           27-May-19   2
## 1569           27-May-20   1
## 1570           27-May-21   7
## 1571           27-Nov-17   2
## 1572           27-Nov-18   3
## 1573           27-Nov-19   5
## 1574           27-Nov-20   9
## 1575           27-Oct-15   1
## 1576           27-Oct-16   1
## 1577           27-Oct-17   2
## 1578           27-Oct-18   2
## 1579           27-Oct-19   1
## 1580           27-Oct-20   4
## 1581           27-Sep-11   1
## 1582           27-Sep-17   1
## 1583           27-Sep-18   1
## 1584           27-Sep-19   5
## 1585           27-Sep-20   1
## 1586           28-Apr-16   1
## 1587           28-Apr-17   8
## 1588           28-Apr-19   1
## 1589           28-Apr-20  12
## 1590           28-Apr-21   3
## 1591           28-Aug-17   1
## 1592           28-Aug-18   4
## 1593           28-Aug-19   1
## 1594           28-Aug-20   5
## 1595           28-Aug-21   4
## 1596           28-Dec-15   1
## 1597           28-Dec-16   1
## 1598           28-Dec-18  10
## 1599           28-Dec-19   1
## 1600           28-Dec-20   3
## 1601           28-Feb-17   3
## 1602           28-Feb-18   2
## 1603           28-Feb-19   3
## 1604           28-Feb-20   6
## 1605           28-Feb-21   1
## 1606           28-Jan-16   4
## 1607           28-Jan-19   6
## 1608           28-Jan-21   1
## 1609           28-Jul-17   3
## 1610           28-Jul-18   6
## 1611           28-Jul-20   1
## 1612           28-Jul-21   5
## 1613           28-Jun-17   1
## 1614           28-Jun-18   1
## 1615           28-Jun-19  11
## 1616           28-Jun-20   3
## 1617           28-Jun-21   4
## 1618           28-Mar-17   1
## 1619           28-Mar-18   1
## 1620           28-Mar-19   1
## 1621           28-Mar-20   1
## 1622           28-Mar-21   2
## 1623           28-May-19   2
## 1624           28-May-20   9
## 1625           28-May-21   5
## 1626           28-Nov-18   1
## 1627           28-Nov-19   6
## 1628           28-Oct-16   6
## 1629           28-Oct-17   1
## 1630           28-Oct-18   1
## 1631           28-Oct-19   2
## 1632           28-Oct-20   5
## 1633           28-Sep-17   1
## 1634           28-Sep-18  11
## 1635           28-Sep-19   3
## 1636           28-Sep-20  11
## 1637           29-Apr-16   2
## 1638           29-Apr-19   4
## 1639           29-Apr-20   8
## 1640           29-Apr-21   2
## 1641           29-Aug-17   2
## 1642           29-Aug-18   2
## 1643           29-Aug-19   4
## 1644           29-Aug-20   1
## 1645           29-Aug-21   2
## 1646           29-Dec-13   1
## 1647           29-Dec-17   5
## 1648           29-Dec-18   2
## 1649           29-Jan-17   1
## 1650           29-Jan-18   4
## 1651           29-Jan-19   6
## 1652           29-Jan-20   4
## 1653           29-Jan-21   4
## 1654           29-Jul-16   2
## 1655           29-Jul-18   1
## 1656           29-Jul-19   3
## 1657           29-Jul-20   6
## 1658           29-Jul-21   3
## 1659           29-Jun-15   1
## 1660           29-Jun-18   8
## 1661           29-Jun-19   2
## 1662           29-Jun-20   1
## 1663           29-Jun-21   1
## 1664           29-Mar-18   1
## 1665           29-Mar-19  14
## 1666           29-Mar-20   2
## 1667           29-Mar-21   1
## 1668           29-May-15   1
## 1669           29-May-17   2
## 1670           29-May-18   1
## 1671           29-May-20   4
## 1672           29-May-21   1
## 1673           29-Nov-19  11
## 1674           29-Nov-20   1
## 1675           29-Oct-16   1
## 1676           29-Oct-18   1
## 1677           29-Oct-19   3
## 1678           29-Oct-20   1
## 1679           29-Sep-15   1
## 1680           29-Sep-17   8
## 1681           29-Sep-18   2
## 1682           29-Sep-20   3
## 1683           30-Apr-18   4
## 1684           30-Apr-19  10
## 1685           30-Apr-20   7
## 1686           30-Apr-21   7
## 1687           30-Aug-18   1
## 1688           30-Aug-19   8
## 1689           30-Aug-20   2
## 1690           30-Dec-16   1
## 1691           30-Dec-17   1
## 1692           30-Dec-18   4
## 1693           30-Dec-19   1
## 1694           30-Dec-20   7
## 1695           30-Jan-18   4
## 1696           30-Jan-19   6
## 1697           30-Jan-20   4
## 1698           30-Jul-17   1
## 1699           30-Jul-18   5
## 1700           30-Jul-19   4
## 1701           30-Jul-20   4
## 1702           30-Jul-21  10
## 1703           30-Jun-16   2
## 1704           30-Jun-17   5
## 1705           30-Jun-18   5
## 1706           30-Jun-19   4
## 1707           30-Jun-20   4
## 1708           30-Jun-21  10
## 1709           30-Mar-17   3
## 1710           30-Mar-18  10
## 1711           30-Mar-19   2
## 1712           30-Mar-21   3
## 1713           30-May-17   2
## 1714           30-May-18   1
## 1715           30-May-19   3
## 1716           30-May-21   1
## 1717           30-Nov-16   1
## 1718           30-Nov-17   1
## 1719           30-Nov-18  13
## 1720           30-Nov-19   3
## 1721           30-Nov-20   4
## 1722           30-Oct-17   1
## 1723           30-Oct-18   5
## 1724           30-Oct-19   4
## 1725           30-Oct-20  10
## 1726           30-Sep-16   1
## 1727           30-Sep-17   2
## 1728           30-Sep-18   7
## 1729           30-Sep-19   2
## 1730           30-Sep-20   9
## 1731           31-Aug-17   1
## 1732           31-Aug-18  10
## 1733           31-Aug-19   1
## 1734           31-Aug-20   4
## 1735           31-Aug-21   3
## 1736           31-Dec-15   1
## 1737           31-Dec-16   2
## 1738           31-Dec-17  17
## 1739           31-Dec-18  27
## 1740           31-Dec-19  74
## 1741           31-Dec-20   6
## 1742           31-Jan-17   2
## 1743           31-Jan-18   1
## 1744           31-Jan-19   8
## 1745           31-Jan-20   8
## 1746           31-Jan-21   2
## 1747           31-Jul-15   1
## 1748           31-Jul-18   3
## 1749           31-Jul-19   3
## 1750           31-Jul-20   7
## 1751           31-Jul-21   3
## 1752           31-Mar-13   1
## 1753           31-Mar-16   1
## 1754           31-Mar-17  30
## 1755           31-Mar-18   8
## 1756           31-Mar-19   3
## 1757           31-Mar-20  13
## 1758           31-Mar-21   5
## 1759           31-May-17   1
## 1760           31-May-18   1
## 1761           31-May-19   7
## 1762           31-May-20   1
## 1763           31-May-21   1
## 1764           31-Oct-15   1
## 1765           31-Oct-17   2
## 1766           31-Oct-18   2
## 1767           31-Oct-19   4
## 1768           31-Oct-20   3
df1<-df %>% filter(country=="United Kingdom") %>% 
  mutate(ymd=dmy(date_added)) %>% 
  filter(ymd>='2018-01-01'&ymd<='2018-01-31')
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `ymd = dmy(date_added)`.
## Caused by warning:
## !  15 failed to parse.
df$y2<-parse_date_time(df$date_added, orders = c("mdy","dmy"),train=F)
df %>% filter(country=="United Kingdom") %>%
  filter(y2>='2018-01-01'&y2<='2018-01-31')
##   show_id    type                                        title        director
## 1   s5058 TV Show                                  Retribution                
## 2   s5075   Movie                          Bad Day for the Cut     Chris Baugh
## 3   s5098 TV Show                                     Lovesick                
## 4   s7399   Movie   Manolo: The Boy Who Made Shoes for Lizards Michael Roberts
## 5   s8358 TV Show                             The Inbetweeners                
## 6   s8620   Movie Treasures from the Wreck of the Unbelievable   Sam Hobkinson
##                                                                                                                                                                            cast
## 1                         Georgina Campbell, Joe Dempsie, Adrian Edmondson, Steve Evets, Laura Fraser, Julie Graham, John Lynch, Gary Lewis, Juliet Stevenson, Joanna Vanderham
## 2                        Nigel O'Neill, Susan Lynch, J?zef Pawlowski, Stuart Graham, David Pearse, Brian Milligan, Anna Prochniak, Stella McCusker, Ian McElhinney, Lalor Roddy
## 3                                                                  Johnny Flynn, Antonia Thomas, Daniel Ings, Hannah Britland, Joshua McGuire, Richard Thomson, Jessica Ellerby
## 4 Manolo Blahnik, Anna Wintour, Andr? Leon Talley, Paloma Picasso, Candace Bushnell, Iman, Rihanna, Naomi Campbell, Isaac Mizrahi, Rupert Everett, Sofia Coppola, John Galliano
## 5                     Simon Bird, James Buckley, Blake Harrison, Joe Thomas, Greg Davies, Emily Head, Martin Trenaman, Belinda Stewart-Wilson, Robin Weaver, Henry Lloyd-Hughes
## 6                                                                                                                                                                              
##          country       date_added release_year rating  duration
## 1 United Kingdom        30-Jan-18         2016  TV-MA  1 Season
## 2 United Kingdom        18-Jan-18         2017  TV-MA    99 min
## 3 United Kingdom        01-Jan-18         2018  TV-MA 3 Seasons
## 4 United Kingdom        15-Jan-18         2017  TV-MA    89 min
## 5 United Kingdom  January 1, 2018         2010  TV-MA 3 Seasons
## 6 United Kingdom        01-Jan-18         2017   TV-G    82 min
##                                                     listed_in         y2
## 1    British TV Shows, Crime TV Shows, International TV Shows 2018-01-30
## 2         Independent Movies, International Movies, Thrillers 2018-01-18
## 3 British TV Shows, International TV Shows, Romantic TV Shows 2018-01-01
## 4                         Documentaries, International Movies 2018-01-15
## 5                               British TV Shows, TV Comedies 2018-01-01
## 6                 Documentaries, Dramas, International Movies 2018-01-01
#실습
library(plyr)
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
## 
## 다음의 패키지를 부착합니다: 'plyr'
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
df<-read.csv("Data1.csv")
glimpse(df)
## Rows: 1,925
## Columns: 27
## $ X         <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1…
## $ Q1        <int> 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, …
## $ Q2        <int> 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 2, 2, …
## $ Q3        <int> 2, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, 3, 2, 3, …
## $ Q4        <int> 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 2, 2, 4, …
## $ Q5        <int> 4, 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 4, 3, 1, 2, …
## $ Q6        <int> 2, 3, 4, 4, 4, 4, 4, 4, 1, 2, 2, 2, 4, 4, 3, 5, 2, 2, 1, 4, …
## $ Q7        <int> 2, 2, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 5, 4, 4, 5, 4, 3, 4, 4, …
## $ Q8        <int> 4, 4, 4, 4, 4, 4, 5, 5, 2, 2, 4, 4, 4, 4, 3, 5, 4, 2, 4, 4, …
## $ Q9        <int> 4, 4, 4, 4, 2, 4, 5, 5, 3, 4, 4, 4, 2, 2, 4, 5, 2, 4, 2, 4, …
## $ Q10       <int> 4, 4, 2, 4, 4, 4, 5, 5, 2, 4, 2, 4, 4, 4, 3, 4, 4, 3, 2, 3, …
## $ Q11       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 3, 4, 4, 4, 4, 5, 4, 3, 3, …
## $ Q12       <int> 4, 4, 4, 4, 4, 4, 5, 5, 3, 4, 4, 3, 4, 3, 3, 4, 5, 4, 4, 2, …
## $ Q13       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 2, 4, 4, 4, 5, 4, 4, 4, …
## $ Q14       <int> 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 3, 4, 5, 4, 5, 4, 4, 4, …
## $ Q15       <int> 4, 4, 3, 4, 4, 4, 4, 2, 3, 4, 4, 3, 1, 4, 4, 4, 5, 4, 4, 4, …
## $ Q16       <int> 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 4, 4, …
## $ Q17       <int> 4, 3, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 3, 2, 4, 5, 4, 4, 3, 4, …
## $ Q18       <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, …
## $ Q19       <int> 4, 2, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 1, 4, 4, 4, 5, 4, 2, 3, …
## $ Q20       <int> 4, 1, 3, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 2, 4, 5, 5, 4, 2, 4, …
## $ Gender    <int> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, …
## $ EDU       <int> 1, 1, 2, 1, 2, 1, 1, 1, 4, 3, 2, 1, 1, 3, 3, 2, 1, 1, 1, 4, …
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
df$Gender<-as.factor(df$Gender)
df$Gender<-revalue(df$Gender,replace=c("0"="female","1"="male"))
glimpse(df)
## Rows: 1,925
## Columns: 27
## $ X         <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1…
## $ Q1        <int> 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, …
## $ Q2        <int> 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 2, 2, …
## $ Q3        <int> 2, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, 3, 2, 3, …
## $ Q4        <int> 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 2, 2, 4, …
## $ Q5        <int> 4, 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 4, 3, 1, 2, …
## $ Q6        <int> 2, 3, 4, 4, 4, 4, 4, 4, 1, 2, 2, 2, 4, 4, 3, 5, 2, 2, 1, 4, …
## $ Q7        <int> 2, 2, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 5, 4, 4, 5, 4, 3, 4, 4, …
## $ Q8        <int> 4, 4, 4, 4, 4, 4, 5, 5, 2, 2, 4, 4, 4, 4, 3, 5, 4, 2, 4, 4, …
## $ Q9        <int> 4, 4, 4, 4, 2, 4, 5, 5, 3, 4, 4, 4, 2, 2, 4, 5, 2, 4, 2, 4, …
## $ Q10       <int> 4, 4, 2, 4, 4, 4, 5, 5, 2, 4, 2, 4, 4, 4, 3, 4, 4, 3, 2, 3, …
## $ Q11       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 3, 4, 4, 4, 4, 5, 4, 3, 3, …
## $ Q12       <int> 4, 4, 4, 4, 4, 4, 5, 5, 3, 4, 4, 3, 4, 3, 3, 4, 5, 4, 4, 2, …
## $ Q13       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 2, 4, 4, 4, 5, 4, 4, 4, …
## $ Q14       <int> 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 3, 4, 5, 4, 5, 4, 4, 4, …
## $ Q15       <int> 4, 4, 3, 4, 4, 4, 4, 2, 3, 4, 4, 3, 1, 4, 4, 4, 5, 4, 4, 4, …
## $ Q16       <int> 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 4, 4, …
## $ Q17       <int> 4, 3, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 3, 2, 4, 5, 4, 4, 3, 4, …
## $ Q18       <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, …
## $ Q19       <int> 4, 2, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 1, 4, 4, 4, 5, 4, 2, 3, …
## $ Q20       <int> 4, 1, 3, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 2, 4, 5, 5, 4, 2, 4, …
## $ Gender    <fct> female, female, female, female, female, female, female, fema…
## $ EDU       <int> 1, 1, 2, 1, 2, 1, 1, 1, 4, 3, 2, 1, 1, 3, 3, 2, 1, 1, 1, 4, …
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
table(df$Gender)
## 
## female   male 
##   1136    789
library(dplyr)
colSums(is.na(df))
##         X        Q1        Q2        Q3        Q4        Q5        Q6        Q7 
##         0         0         0         0         0         0         0         0 
##        Q8        Q9       Q10       Q11       Q12       Q13       Q14       Q15 
##         0         0         0         0         0         0         0         0 
##       Q16       Q17       Q18       Q19       Q20    Gender       EDU        BF 
##         0         0         0         0         0         0         0         0 
##        BM Happiness     Peace 
##         0         0         0
library(caret)
zs_df<-preProcess(df,method = c("center","scale"))
zs_df
## Created from 1925 samples and 27 variables
## 
## Pre-processing:
##   - centered (26)
##   - ignored (1)
##   - scaled (26)
glimpse(df)
## Rows: 1,925
## Columns: 27
## $ X         <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1…
## $ Q1        <int> 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, …
## $ Q2        <int> 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 2, 2, …
## $ Q3        <int> 2, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, 3, 2, 3, …
## $ Q4        <int> 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 2, 2, 4, …
## $ Q5        <int> 4, 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 4, 3, 1, 2, …
## $ Q6        <int> 2, 3, 4, 4, 4, 4, 4, 4, 1, 2, 2, 2, 4, 4, 3, 5, 2, 2, 1, 4, …
## $ Q7        <int> 2, 2, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 5, 4, 4, 5, 4, 3, 4, 4, …
## $ Q8        <int> 4, 4, 4, 4, 4, 4, 5, 5, 2, 2, 4, 4, 4, 4, 3, 5, 4, 2, 4, 4, …
## $ Q9        <int> 4, 4, 4, 4, 2, 4, 5, 5, 3, 4, 4, 4, 2, 2, 4, 5, 2, 4, 2, 4, …
## $ Q10       <int> 4, 4, 2, 4, 4, 4, 5, 5, 2, 4, 2, 4, 4, 4, 3, 4, 4, 3, 2, 3, …
## $ Q11       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 3, 4, 4, 4, 4, 5, 4, 3, 3, …
## $ Q12       <int> 4, 4, 4, 4, 4, 4, 5, 5, 3, 4, 4, 3, 4, 3, 3, 4, 5, 4, 4, 2, …
## $ Q13       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 2, 4, 4, 4, 5, 4, 4, 4, …
## $ Q14       <int> 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 3, 4, 5, 4, 5, 4, 4, 4, …
## $ Q15       <int> 4, 4, 3, 4, 4, 4, 4, 2, 3, 4, 4, 3, 1, 4, 4, 4, 5, 4, 4, 4, …
## $ Q16       <int> 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 4, 4, …
## $ Q17       <int> 4, 3, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 3, 2, 4, 5, 4, 4, 3, 4, …
## $ Q18       <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, …
## $ Q19       <int> 4, 2, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 1, 4, 4, 4, 5, 4, 2, 3, …
## $ Q20       <int> 4, 1, 3, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 2, 4, 5, 5, 4, 2, 4, …
## $ Gender    <fct> female, female, female, female, female, female, female, fema…
## $ EDU       <int> 1, 1, 2, 1, 2, 1, 1, 1, 4, 3, 2, 1, 1, 3, 3, 2, 1, 1, 1, 4, …
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
summary(df)
##        X              Q1              Q2              Q3              Q4       
##  Min.   :   1   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.: 482   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median : 963   Median :4.000   Median :3.000   Median :3.000   Median :3.000  
##  Mean   : 963   Mean   :3.536   Mean   :3.291   Mean   :2.928   Mean   :3.061  
##  3rd Qu.:1444   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
##  Max.   :1925   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
##        Q5              Q6              Q7              Q8       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :3.000   Median :3.000   Median :3.000   Median :3.000  
##  Mean   :3.041   Mean   :2.796   Mean   :3.086   Mean   :3.049  
##  3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
##  Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
##        Q9             Q10             Q11            Q12             Q13       
##  Min.   :1.000   Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:3.00   1st Qu.:3.000   1st Qu.:3.000  
##  Median :3.000   Median :3.000   Median :4.00   Median :4.000   Median :4.000  
##  Mean   :3.066   Mean   :2.883   Mean   :3.47   Mean   :3.421   Mean   :3.588  
##  3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.00   3rd Qu.:4.000   3rd Qu.:4.000  
##  Max.   :5.000   Max.   :5.000   Max.   :5.00   Max.   :5.000   Max.   :5.000  
##       Q14             Q15             Q16             Q17       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000  
##  Median :4.000   Median :4.000   Median :4.000   Median :4.000  
##  Mean   :3.716   Mean   :3.542   Mean   :3.791   Mean   :3.516  
##  3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
##  Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
##       Q18             Q19             Q20           Gender          EDU       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   female:1136   Min.   :1.000  
##  1st Qu.:4.000   1st Qu.:3.000   1st Qu.:3.000   male  : 789   1st Qu.:2.000  
##  Median :4.000   Median :3.000   Median :3.000                 Median :3.000  
##  Mean   :3.804   Mean   :3.364   Mean   :3.349                 Mean   :2.616  
##  3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000                 3rd Qu.:3.000  
##  Max.   :5.000   Max.   :5.000   Max.   :5.000                 Max.   :4.000  
##        BF              BM          Happiness         Peace      
##  Min.   :1.000   Min.   :1.000   Min.   :1.400   Min.   :1.200  
##  1st Qu.:2.600   1st Qu.:2.400   1st Qu.:3.000   1st Qu.:3.200  
##  Median :3.200   Median :3.000   Median :3.600   Median :3.600  
##  Mean   :3.172   Mean   :2.976   Mean   :3.547   Mean   :3.564  
##  3rd Qu.:3.800   3rd Qu.:3.600   3rd Qu.:4.000   3rd Qu.:4.000  
##  Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000
set.seed(998) 
inTraining<-createDataPartition(y=df$Gender,p=.50,list = FALSE)
training<-df[inTraining,]
testing<-df[-inTraining,]
inTraining
##        Resample1
##   [1,]         2
##   [2,]         3
##   [3,]         7
##   [4,]        10
##   [5,]        12
##   [6,]        14
##   [7,]        15
##   [8,]        17
##   [9,]        19
##  [10,]        22
##  [11,]        23
##  [12,]        25
##  [13,]        26
##  [14,]        28
##  [15,]        35
##  [16,]        36
##  [17,]        37
##  [18,]        38
##  [19,]        41
##  [20,]        44
##  [21,]        45
##  [22,]        46
##  [23,]        47
##  [24,]        50
##  [25,]        51
##  [26,]        52
##  [27,]        53
##  [28,]        55
##  [29,]        58
##  [30,]        59
##  [31,]        61
##  [32,]        65
##  [33,]        68
##  [34,]        69
##  [35,]        70
##  [36,]        72
##  [37,]        75
##  [38,]        78
##  [39,]        86
##  [40,]        89
##  [41,]        91
##  [42,]        92
##  [43,]        94
##  [44,]        95
##  [45,]        97
##  [46,]        99
##  [47,]       100
##  [48,]       102
##  [49,]       104
##  [50,]       106
##  [51,]       107
##  [52,]       110
##  [53,]       111
##  [54,]       112
##  [55,]       113
##  [56,]       115
##  [57,]       117
##  [58,]       121
##  [59,]       123
##  [60,]       124
##  [61,]       125
##  [62,]       129
##  [63,]       131
##  [64,]       132
##  [65,]       134
##  [66,]       135
##  [67,]       136
##  [68,]       138
##  [69,]       139
##  [70,]       144
##  [71,]       146
##  [72,]       147
##  [73,]       148
##  [74,]       149
##  [75,]       150
##  [76,]       153
##  [77,]       157
##  [78,]       158
##  [79,]       161
##  [80,]       162
##  [81,]       163
##  [82,]       165
##  [83,]       168
##  [84,]       169
##  [85,]       171
##  [86,]       175
##  [87,]       176
##  [88,]       180
##  [89,]       183
##  [90,]       184
##  [91,]       185
##  [92,]       186
##  [93,]       187
##  [94,]       188
##  [95,]       189
##  [96,]       190
##  [97,]       193
##  [98,]       194
##  [99,]       196
## [100,]       198
## [101,]       199
## [102,]       201
## [103,]       202
## [104,]       203
## [105,]       207
## [106,]       209
## [107,]       210
## [108,]       213
## [109,]       216
## [110,]       221
## [111,]       222
## [112,]       223
## [113,]       225
## [114,]       227
## [115,]       228
## [116,]       230
## [117,]       231
## [118,]       232
## [119,]       235
## [120,]       236
## [121,]       237
## [122,]       239
## [123,]       241
## [124,]       243
## [125,]       245
## [126,]       246
## [127,]       248
## [128,]       249
## [129,]       253
## [130,]       254
## [131,]       255
## [132,]       258
## [133,]       260
## [134,]       261
## [135,]       262
## [136,]       263
## [137,]       264
## [138,]       265
## [139,]       266
## [140,]       267
## [141,]       270
## [142,]       271
## [143,]       272
## [144,]       274
## [145,]       279
## [146,]       280
## [147,]       282
## [148,]       283
## [149,]       284
## [150,]       285
## [151,]       286
## [152,]       288
## [153,]       289
## [154,]       290
## [155,]       291
## [156,]       292
## [157,]       293
## [158,]       296
## [159,]       299
## [160,]       300
## [161,]       301
## [162,]       302
## [163,]       303
## [164,]       308
## [165,]       314
## [166,]       315
## [167,]       317
## [168,]       320
## [169,]       321
## [170,]       322
## [171,]       324
## [172,]       327
## [173,]       329
## [174,]       330
## [175,]       332
## [176,]       333
## [177,]       334
## [178,]       341
## [179,]       342
## [180,]       343
## [181,]       344
## [182,]       345
## [183,]       346
## [184,]       348
## [185,]       351
## [186,]       352
## [187,]       354
## [188,]       355
## [189,]       357
## [190,]       361
## [191,]       363
## [192,]       364
## [193,]       367
## [194,]       368
## [195,]       369
## [196,]       371
## [197,]       376
## [198,]       380
## [199,]       382
## [200,]       384
## [201,]       385
## [202,]       387
## [203,]       391
## [204,]       392
## [205,]       394
## [206,]       396
## [207,]       397
## [208,]       398
## [209,]       399
## [210,]       400
## [211,]       401
## [212,]       402
## [213,]       404
## [214,]       405
## [215,]       406
## [216,]       408
## [217,]       409
## [218,]       412
## [219,]       414
## [220,]       416
## [221,]       418
## [222,]       421
## [223,]       423
## [224,]       424
## [225,]       425
## [226,]       426
## [227,]       427
## [228,]       428
## [229,]       431
## [230,]       438
## [231,]       439
## [232,]       442
## [233,]       446
## [234,]       449
## [235,]       451
## [236,]       453
## [237,]       454
## [238,]       456
## [239,]       459
## [240,]       464
## [241,]       465
## [242,]       466
## [243,]       469
## [244,]       471
## [245,]       475
## [246,]       476
## [247,]       477
## [248,]       479
## [249,]       484
## [250,]       485
## [251,]       487
## [252,]       489
## [253,]       490
## [254,]       494
## [255,]       497
## [256,]       501
## [257,]       502
## [258,]       504
## [259,]       510
## [260,]       511
## [261,]       513
## [262,]       515
## [263,]       517
## [264,]       518
## [265,]       520
## [266,]       524
## [267,]       525
## [268,]       527
## [269,]       530
## [270,]       532
## [271,]       538
## [272,]       541
## [273,]       542
## [274,]       545
## [275,]       546
## [276,]       547
## [277,]       550
## [278,]       551
## [279,]       555
## [280,]       557
## [281,]       558
## [282,]       560
## [283,]       562
## [284,]       564
## [285,]       565
## [286,]       566
## [287,]       568
## [288,]       569
## [289,]       570
## [290,]       571
## [291,]       573
## [292,]       574
## [293,]       577
## [294,]       578
## [295,]       584
## [296,]       585
## [297,]       587
## [298,]       590
## [299,]       591
## [300,]       592
## [301,]       593
## [302,]       594
## [303,]       595
## [304,]       597
## [305,]       598
## [306,]       599
## [307,]       602
## [308,]       603
## [309,]       606
## [310,]       607
## [311,]       609
## [312,]       612
## [313,]       613
## [314,]       615
## [315,]       616
## [316,]       618
## [317,]       620
## [318,]       621
## [319,]       623
## [320,]       626
## [321,]       628
## [322,]       633
## [323,]       637
## [324,]       639
## [325,]       642
## [326,]       645
## [327,]       646
## [328,]       647
## [329,]       648
## [330,]       649
## [331,]       650
## [332,]       652
## [333,]       658
## [334,]       659
## [335,]       660
## [336,]       661
## [337,]       666
## [338,]       667
## [339,]       669
## [340,]       671
## [341,]       672
## [342,]       677
## [343,]       678
## [344,]       680
## [345,]       683
## [346,]       684
## [347,]       687
## [348,]       688
## [349,]       692
## [350,]       695
## [351,]       697
## [352,]       701
## [353,]       702
## [354,]       703
## [355,]       704
## [356,]       705
## [357,]       706
## [358,]       708
## [359,]       709
## [360,]       710
## [361,]       711
## [362,]       713
## [363,]       715
## [364,]       717
## [365,]       719
## [366,]       724
## [367,]       725
## [368,]       726
## [369,]       728
## [370,]       731
## [371,]       733
## [372,]       735
## [373,]       736
## [374,]       737
## [375,]       740
## [376,]       741
## [377,]       744
## [378,]       750
## [379,]       751
## [380,]       753
## [381,]       754
## [382,]       755
## [383,]       756
## [384,]       757
## [385,]       758
## [386,]       759
## [387,]       762
## [388,]       772
## [389,]       777
## [390,]       778
## [391,]       780
## [392,]       781
## [393,]       782
## [394,]       785
## [395,]       787
## [396,]       788
## [397,]       790
## [398,]       795
## [399,]       797
## [400,]       798
## [401,]       800
## [402,]       803
## [403,]       804
## [404,]       807
## [405,]       810
## [406,]       811
## [407,]       812
## [408,]       813
## [409,]       815
## [410,]       819
## [411,]       820
## [412,]       822
## [413,]       823
## [414,]       824
## [415,]       826
## [416,]       828
## [417,]       829
## [418,]       830
## [419,]       831
## [420,]       833
## [421,]       834
## [422,]       835
## [423,]       836
## [424,]       837
## [425,]       838
## [426,]       839
## [427,]       840
## [428,]       843
## [429,]       845
## [430,]       846
## [431,]       849
## [432,]       850
## [433,]       855
## [434,]       856
## [435,]       857
## [436,]       859
## [437,]       864
## [438,]       867
## [439,]       868
## [440,]       870
## [441,]       871
## [442,]       872
## [443,]       873
## [444,]       874
## [445,]       876
## [446,]       877
## [447,]       879
## [448,]       881
## [449,]       883
## [450,]       885
## [451,]       887
## [452,]       888
## [453,]       889
## [454,]       890
## [455,]       891
## [456,]       894
## [457,]       897
## [458,]       901
## [459,]       902
## [460,]       903
## [461,]       905
## [462,]       908
## [463,]       911
## [464,]       912
## [465,]       913
## [466,]       914
## [467,]       915
## [468,]       917
## [469,]       918
## [470,]       920
## [471,]       923
## [472,]       928
## [473,]       932
## [474,]       934
## [475,]       935
## [476,]       938
## [477,]       940
## [478,]       941
## [479,]       943
## [480,]       944
## [481,]       947
## [482,]       949
## [483,]       952
## [484,]       955
## [485,]       958
## [486,]       959
## [487,]       961
## [488,]       964
## [489,]       968
## [490,]       970
## [491,]       975
## [492,]       976
## [493,]       977
## [494,]       980
## [495,]       982
## [496,]       985
## [497,]       986
## [498,]       987
## [499,]       988
## [500,]       990
## [501,]       993
## [502,]       994
## [503,]       999
## [504,]      1001
## [505,]      1003
## [506,]      1004
## [507,]      1006
## [508,]      1007
## [509,]      1010
## [510,]      1011
## [511,]      1012
## [512,]      1013
## [513,]      1014
## [514,]      1015
## [515,]      1016
## [516,]      1018
## [517,]      1019
## [518,]      1020
## [519,]      1025
## [520,]      1028
## [521,]      1029
## [522,]      1030
## [523,]      1033
## [524,]      1035
## [525,]      1036
## [526,]      1038
## [527,]      1045
## [528,]      1047
## [529,]      1050
## [530,]      1052
## [531,]      1056
## [532,]      1057
## [533,]      1060
## [534,]      1061
## [535,]      1065
## [536,]      1068
## [537,]      1070
## [538,]      1071
## [539,]      1075
## [540,]      1076
## [541,]      1077
## [542,]      1078
## [543,]      1079
## [544,]      1081
## [545,]      1083
## [546,]      1084
## [547,]      1091
## [548,]      1094
## [549,]      1095
## [550,]      1100
## [551,]      1102
## [552,]      1103
## [553,]      1105
## [554,]      1106
## [555,]      1107
## [556,]      1111
## [557,]      1112
## [558,]      1114
## [559,]      1116
## [560,]      1117
## [561,]      1118
## [562,]      1121
## [563,]      1122
## [564,]      1123
## [565,]      1124
## [566,]      1127
## [567,]      1130
## [568,]      1132
## [569,]      1135
## [570,]      1140
## [571,]      1143
## [572,]      1145
## [573,]      1146
## [574,]      1147
## [575,]      1149
## [576,]      1150
## [577,]      1152
## [578,]      1155
## [579,]      1156
## [580,]      1158
## [581,]      1159
## [582,]      1160
## [583,]      1161
## [584,]      1162
## [585,]      1169
## [586,]      1172
## [587,]      1173
## [588,]      1174
## [589,]      1177
## [590,]      1179
## [591,]      1180
## [592,]      1184
## [593,]      1189
## [594,]      1196
## [595,]      1197
## [596,]      1198
## [597,]      1199
## [598,]      1201
## [599,]      1202
## [600,]      1203
## [601,]      1205
## [602,]      1206
## [603,]      1208
## [604,]      1211
## [605,]      1215
## [606,]      1217
## [607,]      1219
## [608,]      1221
## [609,]      1222
## [610,]      1224
## [611,]      1226
## [612,]      1228
## [613,]      1229
## [614,]      1230
## [615,]      1234
## [616,]      1236
## [617,]      1238
## [618,]      1239
## [619,]      1240
## [620,]      1244
## [621,]      1245
## [622,]      1246
## [623,]      1247
## [624,]      1249
## [625,]      1250
## [626,]      1252
## [627,]      1253
## [628,]      1254
## [629,]      1256
## [630,]      1259
## [631,]      1266
## [632,]      1267
## [633,]      1269
## [634,]      1270
## [635,]      1272
## [636,]      1275
## [637,]      1277
## [638,]      1278
## [639,]      1281
## [640,]      1282
## [641,]      1284
## [642,]      1286
## [643,]      1289
## [644,]      1291
## [645,]      1294
## [646,]      1295
## [647,]      1296
## [648,]      1297
## [649,]      1298
## [650,]      1299
## [651,]      1301
## [652,]      1302
## [653,]      1303
## [654,]      1308
## [655,]      1309
## [656,]      1315
## [657,]      1318
## [658,]      1319
## [659,]      1320
## [660,]      1321
## [661,]      1322
## [662,]      1325
## [663,]      1328
## [664,]      1330
## [665,]      1331
## [666,]      1333
## [667,]      1335
## [668,]      1341
## [669,]      1345
## [670,]      1352
## [671,]      1353
## [672,]      1356
## [673,]      1357
## [674,]      1358
## [675,]      1362
## [676,]      1363
## [677,]      1364
## [678,]      1365
## [679,]      1368
## [680,]      1369
## [681,]      1372
## [682,]      1375
## [683,]      1376
## [684,]      1378
## [685,]      1379
## [686,]      1380
## [687,]      1381
## [688,]      1383
## [689,]      1386
## [690,]      1388
## [691,]      1391
## [692,]      1392
## [693,]      1395
## [694,]      1397
## [695,]      1400
## [696,]      1402
## [697,]      1403
## [698,]      1406
## [699,]      1407
## [700,]      1408
## [701,]      1411
## [702,]      1412
## [703,]      1413
## [704,]      1416
## [705,]      1417
## [706,]      1418
## [707,]      1419
## [708,]      1421
## [709,]      1426
## [710,]      1428
## [711,]      1430
## [712,]      1431
## [713,]      1432
## [714,]      1433
## [715,]      1434
## [716,]      1436
## [717,]      1438
## [718,]      1444
## [719,]      1446
## [720,]      1451
## [721,]      1452
## [722,]      1453
## [723,]      1455
## [724,]      1457
## [725,]      1459
## [726,]      1465
## [727,]      1467
## [728,]      1468
## [729,]      1469
## [730,]      1471
## [731,]      1472
## [732,]      1475
## [733,]      1476
## [734,]      1478
## [735,]      1480
## [736,]      1487
## [737,]      1488
## [738,]      1492
## [739,]      1493
## [740,]      1494
## [741,]      1496
## [742,]      1497
## [743,]      1498
## [744,]      1499
## [745,]      1500
## [746,]      1506
## [747,]      1510
## [748,]      1511
## [749,]      1514
## [750,]      1515
## [751,]      1516
## [752,]      1522
## [753,]      1526
## [754,]      1529
## [755,]      1530
## [756,]      1531
## [757,]      1532
## [758,]      1534
## [759,]      1535
## [760,]      1537
## [761,]      1539
## [762,]      1540
## [763,]      1543
## [764,]      1545
## [765,]      1547
## [766,]      1548
## [767,]      1549
## [768,]      1550
## [769,]      1554
## [770,]      1555
## [771,]      1557
## [772,]      1562
## [773,]      1563
## [774,]      1564
## [775,]      1565
## [776,]      1566
## [777,]      1569
## [778,]      1573
## [779,]      1574
## [780,]      1575
## [781,]      1576
## [782,]      1578
## [783,]      1580
## [784,]      1581
## [785,]      1583
## [786,]      1584
## [787,]      1585
## [788,]      1586
## [789,]      1587
## [790,]      1588
## [791,]      1590
## [792,]      1593
## [793,]      1594
## [794,]      1595
## [795,]      1597
## [796,]      1598
## [797,]      1599
## [798,]      1604
## [799,]      1606
## [800,]      1607
## [801,]      1608
## [802,]      1610
## [803,]      1611
## [804,]      1613
## [805,]      1614
## [806,]      1618
## [807,]      1619
## [808,]      1620
## [809,]      1622
## [810,]      1626
## [811,]      1629
## [812,]      1634
## [813,]      1639
## [814,]      1640
## [815,]      1641
## [816,]      1642
## [817,]      1643
## [818,]      1648
## [819,]      1649
## [820,]      1651
## [821,]      1653
## [822,]      1655
## [823,]      1656
## [824,]      1660
## [825,]      1661
## [826,]      1663
## [827,]      1671
## [828,]      1672
## [829,]      1675
## [830,]      1676
## [831,]      1680
## [832,]      1683
## [833,]      1684
## [834,]      1686
## [835,]      1687
## [836,]      1688
## [837,]      1690
## [838,]      1691
## [839,]      1692
## [840,]      1693
## [841,]      1694
## [842,]      1697
## [843,]      1699
## [844,]      1700
## [845,]      1702
## [846,]      1704
## [847,]      1705
## [848,]      1706
## [849,]      1707
## [850,]      1709
## [851,]      1710
## [852,]      1712
## [853,]      1714
## [854,]      1716
## [855,]      1717
## [856,]      1718
## [857,]      1719
## [858,]      1721
## [859,]      1722
## [860,]      1726
## [861,]      1728
## [862,]      1730
## [863,]      1732
## [864,]      1733
## [865,]      1737
## [866,]      1739
## [867,]      1741
## [868,]      1743
## [869,]      1744
## [870,]      1748
## [871,]      1749
## [872,]      1754
## [873,]      1755
## [874,]      1756
## [875,]      1757
## [876,]      1758
## [877,]      1759
## [878,]      1761
## [879,]      1762
## [880,]      1763
## [881,]      1764
## [882,]      1766
## [883,]      1769
## [884,]      1772
## [885,]      1775
## [886,]      1779
## [887,]      1780
## [888,]      1787
## [889,]      1789
## [890,]      1792
## [891,]      1794
## [892,]      1795
## [893,]      1797
## [894,]      1800
## [895,]      1801
## [896,]      1803
## [897,]      1804
## [898,]      1805
## [899,]      1806
## [900,]      1807
## [901,]      1808
## [902,]      1809
## [903,]      1810
## [904,]      1817
## [905,]      1819
## [906,]      1822
## [907,]      1824
## [908,]      1826
## [909,]      1827
## [910,]      1834
## [911,]      1835
## [912,]      1836
## [913,]      1838
## [914,]      1845
## [915,]      1847
## [916,]      1848
## [917,]      1849
## [918,]      1850
## [919,]      1853
## [920,]      1855
## [921,]      1856
## [922,]      1857
## [923,]      1858
## [924,]      1859
## [925,]      1860
## [926,]      1861
## [927,]      1862
## [928,]      1864
## [929,]      1865
## [930,]      1866
## [931,]      1868
## [932,]      1869
## [933,]      1872
## [934,]      1873
## [935,]      1875
## [936,]      1877
## [937,]      1878
## [938,]      1881
## [939,]      1882
## [940,]      1883
## [941,]      1884
## [942,]      1885
## [943,]      1886
## [944,]      1890
## [945,]      1892
## [946,]      1893
## [947,]      1894
## [948,]      1896
## [949,]      1897
## [950,]      1899
## [951,]      1900
## [952,]      1901
## [953,]      1903
## [954,]      1907
## [955,]      1908
## [956,]      1910
## [957,]      1913
## [958,]      1915
## [959,]      1916
## [960,]      1917
## [961,]      1918
## [962,]      1920
## [963,]      1922
NROW(training)
## [1] 963
NROW(testing)
## [1] 962
963/1925
## [1] 0.5002597
set.seed(825)
rffit<-train(Gender~.,data=training,
             method="rf",
             preProc=c("center","scale"))
rffit
## Random Forest 
## 
## 963 samples
##  26 predictor
##   2 classes: 'female', 'male' 
## 
## Pre-processing: centered (26), scaled (26) 
## Resampling: Bootstrapped (25 reps) 
## Summary of sample sizes: 963, 963, 963, 963, 963, 963, ... 
## Resampling results across tuning parameters:
## 
##   mtry  Accuracy   Kappa    
##    2    0.5911403  0.1083694
##   14    0.5910687  0.1244021
##   26    0.5931687  0.1359087
## 
## Accuracy was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 26.
predict(rffit,newdata=head(testing))
## [1] female female male   female female female
## Levels: female male
predict(rffit,newdata=head(testing),type='prob')
##   female  male
## 1  0.876 0.124
## 4  0.874 0.126
## 5  0.494 0.506
## 6  0.846 0.154
## 8  0.774 0.226
## 9  0.532 0.468
predict(rffit,newdata=testing) %>% confusionMatrix(testing$Gender)
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction female male
##     female    420  219
##     male      148  175
##                                          
##                Accuracy : 0.6185         
##                  95% CI : (0.587, 0.6493)
##     No Information Rate : 0.5904         
##     P-Value [Acc > NIR] : 0.0407725      
##                                          
##                   Kappa : 0.1888         
##                                          
##  Mcnemar's Test P-Value : 0.0002582      
##                                          
##             Sensitivity : 0.7394         
##             Specificity : 0.4442         
##          Pos Pred Value : 0.6573         
##          Neg Pred Value : 0.5418         
##              Prevalence : 0.5904         
##          Detection Rate : 0.4366         
##    Detection Prevalence : 0.6642         
##       Balanced Accuracy : 0.5918         
##                                          
##        'Positive' Class : female         
## 
prop.table(table(df$Gender))
## 
##    female      male 
## 0.5901299 0.4098701
library(mlbench)
library(dplyr)
library(caret)
data(PimaIndiansDiabetes)
glimpse(PimaIndiansDiabetes)
## Rows: 768
## Columns: 9
## $ pregnant <dbl> 6, 1, 8, 1, 0, 5, 3, 10, 2, 8, 4, 10, 10, 1, 5, 7, 0, 7, 1, 1…
## $ glucose  <dbl> 148, 85, 183, 89, 137, 116, 78, 115, 197, 125, 110, 168, 139,…
## $ pressure <dbl> 72, 66, 64, 66, 40, 74, 50, 0, 70, 96, 92, 74, 80, 60, 72, 0,…
## $ triceps  <dbl> 35, 29, 0, 23, 35, 0, 32, 0, 45, 0, 0, 0, 0, 23, 19, 0, 47, 0…
## $ insulin  <dbl> 0, 0, 0, 94, 168, 0, 88, 0, 543, 0, 0, 0, 0, 846, 175, 0, 230…
## $ mass     <dbl> 33.6, 26.6, 23.3, 28.1, 43.1, 25.6, 31.0, 35.3, 30.5, 0.0, 37…
## $ pedigree <dbl> 0.627, 0.351, 0.672, 0.167, 2.288, 0.201, 0.248, 0.134, 0.158…
## $ age      <dbl> 50, 31, 32, 21, 33, 30, 26, 29, 53, 54, 30, 34, 57, 59, 51, 3…
## $ diabetes <fct> pos, neg, pos, neg, pos, neg, pos, neg, pos, pos, neg, pos, n…
count<-dplyr::count
PimaIndiansDiabetes %>% count(diabetes)
##   diabetes   n
## 1      neg 500
## 2      pos 268
glimpse(PimaIndiansDiabetes)
## Rows: 768
## Columns: 9
## $ pregnant <dbl> 6, 1, 8, 1, 0, 5, 3, 10, 2, 8, 4, 10, 10, 1, 5, 7, 0, 7, 1, 1…
## $ glucose  <dbl> 148, 85, 183, 89, 137, 116, 78, 115, 197, 125, 110, 168, 139,…
## $ pressure <dbl> 72, 66, 64, 66, 40, 74, 50, 0, 70, 96, 92, 74, 80, 60, 72, 0,…
## $ triceps  <dbl> 35, 29, 0, 23, 35, 0, 32, 0, 45, 0, 0, 0, 0, 23, 19, 0, 47, 0…
## $ insulin  <dbl> 0, 0, 0, 94, 168, 0, 88, 0, 543, 0, 0, 0, 0, 846, 175, 0, 230…
## $ mass     <dbl> 33.6, 26.6, 23.3, 28.1, 43.1, 25.6, 31.0, 35.3, 30.5, 0.0, 37…
## $ pedigree <dbl> 0.627, 0.351, 0.672, 0.167, 2.288, 0.201, 0.248, 0.134, 0.158…
## $ age      <dbl> 50, 31, 32, 21, 33, 30, 26, 29, 53, 54, 30, 34, 57, 59, 51, 3…
## $ diabetes <fct> pos, neg, pos, neg, pos, neg, pos, neg, pos, pos, neg, pos, n…
PimaIndiansDiabetes$diabetes 
##   [1] pos neg pos neg pos neg pos neg pos pos neg pos neg pos pos pos pos pos
##  [19] neg pos neg neg pos pos pos pos pos neg neg neg neg pos neg neg neg neg
##  [37] neg pos pos pos neg neg neg pos neg pos neg neg pos neg neg neg neg pos
##  [55] neg neg pos neg neg neg neg pos neg neg pos neg pos neg neg neg pos neg
##  [73] pos neg neg neg neg neg pos neg neg neg neg neg pos neg neg neg pos neg
##  [91] neg neg neg pos neg neg neg neg neg pos pos neg neg neg neg neg neg neg
## [109] neg pos pos pos neg neg pos pos pos neg neg neg pos neg neg neg pos pos
## [127] neg neg pos pos pos pos pos neg neg neg neg neg neg neg neg neg neg pos
## [145] neg neg neg neg neg neg neg neg pos neg pos pos neg neg neg pos neg neg
## [163] neg neg pos pos neg neg neg neg pos pos neg neg neg pos neg pos neg pos
## [181] neg neg neg neg neg pos pos pos pos pos neg neg pos pos neg pos neg pos
## [199] pos pos neg neg neg neg neg neg pos pos neg pos neg neg neg pos pos pos
## [217] pos neg pos pos pos pos neg neg neg neg neg pos neg neg pos pos neg neg
## [235] neg pos pos pos pos neg neg neg pos pos neg pos neg neg neg neg neg neg
## [253] neg neg pos pos neg neg neg pos neg pos neg neg pos neg pos neg neg pos
## [271] pos neg neg neg neg neg pos neg neg neg pos neg neg pos pos neg neg pos
## [289] neg neg neg pos pos pos neg neg pos neg pos neg pos pos neg pos neg neg
## [307] pos neg pos pos neg neg pos neg pos neg neg pos neg pos neg pos pos pos
## [325] neg neg pos neg pos neg neg neg pos neg neg neg neg pos pos pos neg neg
## [343] neg neg neg neg neg neg neg pos neg neg neg neg neg pos pos pos neg pos
## [361] pos neg neg pos neg neg pos neg neg pos pos neg neg neg neg pos neg neg
## [379] pos neg neg neg neg neg neg neg pos pos pos neg neg pos neg neg pos neg
## [397] neg pos neg pos pos neg pos neg pos neg pos neg pos pos neg neg neg neg
## [415] pos pos neg pos neg pos neg neg neg neg pos pos neg pos neg pos neg neg
## [433] neg neg neg pos neg neg neg neg pos neg neg pos pos pos neg neg pos neg
## [451] neg pos neg neg neg pos neg neg pos neg neg neg neg neg neg neg neg neg
## [469] pos neg neg neg neg neg neg neg pos neg neg neg pos neg neg neg pos pos
## [487] neg neg neg neg neg neg neg pos neg neg neg neg pos neg neg neg pos neg
## [505] neg neg pos neg neg neg pos neg neg neg neg pos pos neg neg neg neg neg
## [523] neg pos neg neg neg neg neg neg neg neg neg neg neg pos neg neg neg pos
## [541] pos pos pos neg neg pos pos neg neg neg neg neg neg neg neg neg neg neg
## [559] neg neg pos pos neg neg neg neg neg neg neg pos neg neg neg neg neg neg
## [577] neg pos neg pos pos neg neg neg pos neg pos neg pos neg pos neg pos neg
## [595] neg pos neg neg pos neg neg neg neg pos pos neg pos neg neg neg neg pos
## [613] pos neg pos neg neg neg pos pos neg neg neg neg neg neg neg neg neg neg
## [631] pos neg neg neg neg pos neg neg pos neg neg neg pos neg neg neg pos pos
## [649] pos neg neg neg neg neg neg pos neg neg neg pos neg pos pos pos pos neg
## [667] pos pos neg neg neg neg neg neg neg pos pos neg pos neg neg pos neg pos
## [685] neg neg neg neg neg pos neg pos neg pos neg pos pos neg neg neg neg pos
## [703] pos neg neg neg pos neg pos pos neg neg pos neg neg pos pos neg neg pos
## [721] neg neg pos neg neg neg neg neg neg neg pos pos pos neg neg neg neg neg
## [739] neg pos pos neg neg pos neg neg pos neg pos pos pos neg neg pos pos pos
## [757] neg pos neg pos neg pos neg neg neg neg pos neg
## Levels: neg pos