rm(list=ls())
getwd()
## [1] "C:/Users/김지수/Desktop/2023/여름방학/AI빅데이터인력양성/adsp"
setwd("c:/data")
getwd()
## [1] "c:/data"
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
library(caret)
## 필요한 패키지를 로딩중입니다: ggplot2
## 필요한 패키지를 로딩중입니다: lattice
#단순선형회귀분석
#BM(건강한자기관리)
#HAPPLINESS(행복도)
#bm이 happiness에 끼치는 영향관계
#건강한 자기관리를 잘할수록 행복도 증가하는가
df<-read.csv("DATA1.csv")
glimpse(df)
## Rows: 1,925
## Columns: 26
## $ 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, …
## $ Gender1 <int> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, …
## $ EDU1 <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, …
#회귀분석은 등간척도 이상이어야함
#독립변수 범주형이라도 회귀분석이 가능하다.=더미변수
#종속변수가 이진데이터(0,1/성공실패)경우 로지스틱회귀분석
bs.out2<-lm(Happiness~BM,data=df) #lm=선형회귀분석을 만드는 함수
summary(bs.out2)
##
## Call:
## lm(formula = Happiness ~ BM, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.1591 -0.4577 0.0418 0.4409 1.9386
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.06599 0.05777 35.77 <2e-16 ***
## BM 0.49771 0.01878 26.50 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6404 on 1923 degrees of freedom
## Multiple R-squared: 0.2675, Adjusted R-squared: 0.2671
## F-statistic: 702.2 on 1 and 1923 DF, p-value: < 2.2e-16
#~종속변수 관계 설정
#건강한 자기관리가 1 증가할 경우 행복은 0.498 증가함
#더빈왓슨(Durbin watson) 검정
#더빈왓슨 통계량을 0~4값을 가질 수 있음
#0에 가까울수록 양의 상관관계
#4에 가까울수록 음의 상관관계
#2에 가까울수록 오차항의 자기상관이 없음
#BM Estimate = 비율
#Intercept : 절편
#residuals : 잔차
#단순회귀분석 : happiness=2.06+0.497*BM, 모델링 完
#오차항 : 모집단을 알수 없음. 실제관측값-모회귀선의 차이(오차)
#잔차항 : 표본을 통해 표본회귀선을 만들고 그때 관측값의 차이(잔차), 잔차를 통해 오차항의 가정조건 성립을 확인=>잔차분석
library(car)#더빈왓슨 검정을 위해 필요
## 필요한 패키지를 로딩중입니다: carData
##
## 다음의 패키지를 부착합니다: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
sreg.res1<-residuals(bs.out2)
durbinWatsonTest(sreg.res1)
## [1] 1.787942
#오차는 독립성이라 판단한다.
library(caret)
#잔차의 등분산성
par(mfrow=c(2,2))
plot(bs.out2)

#q-q : 정규분포 확인
#잔차의 등분산성을 입증하기 위해서는 산점도에서 예측값(Fitted value)의
#변화에 관계없이 잔차(residuals)가 분포하는 모습이 일정하여야 한다.
#정규성검정
#shapiro-Wilk test(샤피로 윌크 검정)
shapiro.test(sreg.res1)#p-value 판단
##
## Shapiro-Wilk normality test
##
## data: sreg.res1
## W = 0.99439, p-value = 1.148e-06
options(scipen=999)#아라비아숫자로 바꾸기
shapiro.test(sreg.res1)
##
## Shapiro-Wilk normality test
##
## data: sreg.res1
## W = 0.99439, p-value = 0.000001148
options(scipen=-999)#원래대로 돌아가기
shapiro.test(sreg.res1)
##
## Shapiro-Wilk normality test
##
## data: sreg.res1
## W = 9.9439e-01, p-value = 1.148e-06
#귀무가설 : 정규분포 맞음
#대립가설 : 정규분포 아님
#유의확률 p-value<유의수준 0.05 = 귀무가설 기각
#정규분포가 아님
#정규성을 만족하지 못하면 박스콕스 변수 변환을 적용할 수 있다.
#Happiness 정규성 검정 한다.
options(scipen=999)
shapiro.test(sreg.res1)
##
## Shapiro-Wilk normality test
##
## data: sreg.res1
## W = 0.99439, p-value = 0.000001148
#위 잔차분석 결과 등분산성, 정규성만족 x
#정규성을 만족하지 못하는 경우 박스콕스 변수 변환을 적용 가능
#다항회귀분석 :독립변수의 차수 제곱을 넘어가는 것
#회귀분석(all)은 시험당 1문제
#다중회귀분석
#다중선형 회귀모형에서는 두개 이상의 독립변수가 주어졌다는 가정에서
#종속변수에 대한 분포를 가정하고 있다
#ㅣ는 독립변수들은 서로 독립적이야 한다는 것을
#다중공선성 vif함수를 통해 확인해야 한다
bs.out3<-lm(Happiness~BM+BF,data=df)
summary(bs.out3)
##
## Call:
## lm(formula = Happiness ~ BM + BF, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.23134 -0.40553 0.02014 0.41352 1.86210
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.60995 0.06412 25.11 <0.0000000000000002 ***
## BM 0.29054 0.02331 12.47 <0.0000000000000002 ***
## BF 0.33817 0.02435 13.89 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6106 on 1922 degrees of freedom
## Multiple R-squared: 0.3343, Adjusted R-squared: 0.3336
## F-statistic: 482.6 on 2 and 1922 DF, p-value: < 0.00000000000000022
library(car)
vif(bs.out3)
## BM BF
## 1.693504 1.693504
#vif값이 모두 10보다 작으므로 두 변수는 서로 내용추가
library(caret)
dim(df)
## [1] 1925 26
idx<-createDataPartition(df$Happiness,p=0.8,list=FALSE)
train<-df[idx,]
test<-df[-idx,]
library(dplyr)
glimpse(train)
## Rows: 1,541
## Columns: 26
## $ Q1 <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 5, 4, …
## $ Q2 <int> 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 2, 4, 2, 4, 2, 2, 2, 5, 4, …
## $ Q3 <int> 2, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 3, 2, 3, 2, 5, 4, …
## $ Q4 <int> 3, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 2, 2, 4, 1, 5, 4, …
## $ Q5 <int> 4, 4, 2, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 3, 1, 2, 1, 5, 3, …
## $ Q6 <int> 2, 3, 4, 4, 4, 4, 1, 2, 2, 2, 4, 4, 5, 2, 2, 1, 4, 1, 5, 4, …
## $ Q7 <int> 2, 2, 4, 4, 4, 4, 3, 4, 4, 4, 5, 4, 5, 4, 3, 4, 4, 2, 5, 5, …
## $ Q8 <int> 4, 4, 4, 4, 4, 5, 2, 2, 4, 4, 4, 4, 5, 4, 2, 4, 4, 4, 5, 3, …
## $ Q9 <int> 4, 4, 4, 2, 4, 5, 3, 4, 4, 4, 2, 2, 5, 2, 4, 2, 4, 4, 5, 3, …
## $ Q10 <int> 4, 4, 2, 4, 4, 5, 2, 4, 2, 4, 4, 4, 4, 4, 3, 2, 3, 3, 5, 2, …
## $ Q11 <int> 4, 4, 4, 4, 4, 5, 4, 4, 4, 3, 4, 4, 4, 5, 4, 3, 3, 3, 5, 3, …
## $ Q12 <int> 4, 4, 4, 4, 4, 5, 3, 4, 4, 3, 4, 3, 4, 5, 4, 4, 2, 4, 5, 4, …
## $ Q13 <int> 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 2, 4, 4, 5, 4, 4, 4, 2, 5, 4, …
## $ Q14 <int> 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 3, 4, 4, 5, 4, 4, 4, 4, 5, 3, …
## $ Q15 <int> 4, 4, 3, 4, 4, 4, 3, 4, 4, 3, 1, 4, 4, 5, 4, 4, 4, 3, 4, 2, …
## $ Q16 <int> 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, …
## $ Q17 <int> 4, 3, 4, 4, 4, 2, 4, 4, 4, 4, 3, 2, 5, 4, 4, 3, 4, 4, 4, 5, …
## $ Q18 <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, 4, 4, 2, …
## $ Q19 <int> 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 1, 4, 4, 5, 4, 2, 3, 3, 4, 1, …
## $ Q20 <int> 4, 1, 3, 4, 4, 4, 4, 2, 4, 4, 4, 2, 5, 5, 4, 2, 4, 3, 5, 4, …
## $ Gender1 <int> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, …
## $ EDU1 <int> 1, 1, 2, 2, 1, 1, 4, 3, 2, 1, 1, 3, 2, 1, 1, 1, 4, 2, 1, 2, …
## $ BF <dbl> 3.4, 4.0, 3.6, 4.0, 4.0, 3.6, 3.6, 3.2, 4.0, 3.2, 4.0, 3.2, …
## $ BM <dbl> 3.2, 3.4, 3.6, 3.6, 4.0, 4.6, 2.2, 3.2, 3.2, 3.6, 3.8, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.8, 3.8, 4.0, 4.0, 3.4, 2.8, 3.8, …
## $ Peace <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 3.8, 4.0, 3.2, 4.0, 3.9, 3.2, 3.2, …
#linear regrssion model
fit<-lm(Happiness~BM+BF+Peace,data=train)
summary(fit)
##
## Call:
## lm(formula = Happiness ~ BM + BF + Peace, data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.88604 -0.32617 -0.01011 0.33664 2.19432
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.52177 0.08509 6.132 0.0000000011 ***
## BM 0.21000 0.02360 8.900 < 0.0000000000000002 ***
## BF 0.23543 0.02471 9.527 < 0.0000000000000002 ***
## Peace 0.46335 0.02333 19.858 < 0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5453 on 1537 degrees of freedom
## Multiple R-squared: 0.4641, Adjusted R-squared: 0.4631
## F-statistic: 443.8 on 3 and 1537 DF, p-value: < 0.00000000000000022
#happiness=0.51388+0.20878*BM+0.24636*BF+0.45747*Peace
predict(fit,newdata=test)
## 4 8 15 21 31 33 35 41
## 4.203960 3.447336 4.077213 3.471854 4.202461 4.165548 3.576196 3.941793
## 48 57 59 66 82 83 84 92
## 1.988073 3.793365 3.793365 3.756452 2.989520 3.791866 4.855655 3.308943
## 106 107 108 112 122 124 129 134
## 4.160462 3.260947 3.743281 3.923537 4.939653 4.578230 3.676628 4.385715
## 135 140 154 156 162 164 166 174
## 3.625368 2.565166 3.027932 4.020706 3.424769 3.356616 2.634682 4.368370
## 177 178 185 190 191 198 206 209
## 3.492036 3.389355 3.363202 3.702194 4.221305 3.371098 3.576196 3.568861
## 214 220 227 228 238 243 250 265
## 4.424128 2.650663 4.109790 3.983793 3.781694 3.789778 3.396528 4.062705
## 268 277 283 287 291 299 302 309
## 3.567524 2.295826 4.198874 3.936708 2.753506 3.833865 4.114876 3.434029
## 310 325 330 337 344 349 352 354
## 3.016261 3.433441 3.897707 2.423323 3.704281 3.499371 3.794864 3.350943
## 356 366 369 374 375 382 391 401
## 3.300859 2.800591 3.440615 3.699195 3.270531 3.012674 3.449287 3.263358
## 403 409 416 417 419 427 432 439
## 3.716540 3.670954 3.424769 3.978707 3.442114 3.977207 3.751366 3.257360
## 441 443 445 448 451 460 464 467
## 3.277116 3.338683 3.276205 2.996693 3.305945 3.800538 4.156875 3.559439
## 468 472 474 476 483 486 487 502
## 3.975120 4.305891 3.622370 3.924448 3.462134 4.128635 3.885286 2.853350
## 505 506 510 519 531 537 560 563
## 4.526059 3.674541 3.736108 4.981652 2.077158 3.844624 4.109790 3.305945
## 565 575 579 586 587 588 590 606
## 3.618783 2.080744 3.881538 3.980206 3.835364 3.529111 4.114876 3.202514
## 618 619 624 631 632 634 647 650
## 3.960638 4.077051 4.350889 3.936708 3.929534 3.581870 3.484113 3.440027
## 652 665 669 684 685 686 688 693
## 3.810710 2.891175 2.524666 3.502958 4.342217 3.445701 3.455872 3.722214
## 694 709 712 723 728 734 739 740
## 3.442702 3.204601 4.161961 2.627509 2.711507 3.027932 3.528787 3.788279
## 742 745 746 747 756 760 768 769
## 2.948432 3.988879 3.760038 3.529111 3.484113 3.748367 2.213327 2.208241
## 770 774 780 794 795 801 804 811
## 3.033018 2.926589 3.810710 3.410874 3.440027 3.582458 3.090863 4.390801
## 817 822 823 824 825 841 847 855
## 3.931622 3.092950 3.494285 3.746280 4.032377 3.389943 3.155429 2.791919
## 860 866 868 881 883 887 889 892
## 4.015620 3.531198 4.428302 3.410287 3.218360 2.386409 2.753506 2.660835
## 893 894 899 900 902 906 908 927
## 2.517493 2.979510 2.517493 2.208241 1.982987 3.815208 4.156875 3.721626
## 931 938 945 949 957 958 972 976
## 3.751366 2.670096 3.353030 3.046777 3.899794 3.610111 3.496960 3.258859
## 980 982 983 992 998 1007 1008 1010
## 3.929534 2.711507 2.665921 3.347944 3.265445 4.536231 3.132862 3.758539
## 1013 1016 1021 1027 1032 1033 1034 1036
## 3.288012 3.935208 3.243014 3.502958 3.516852 3.045865 3.681126 4.345216
## 1042 1046 1047 1048 1064 1070 1089 1091
## 3.585456 3.672454 3.884536 4.153876 3.076517 2.959779 3.040191 3.318204
## 1098 1106 1108 1109 1115 1117 1123 1131
## 3.494285 4.059118 3.700694 4.359562 2.617337 4.156875 4.088723 3.487700
## 1132 1133 1136 1141 1153 1154 1156 1161
## 3.212686 3.412374 3.544045 3.156928 3.406700 4.784639 3.247512 3.526112
## 1163 1166 1171 1172 1179 1181 1182 1185
## 3.155429 4.121461 3.653609 2.480580 3.302358 3.352442 2.874418 4.355975
## 1189 1192 1194 1197 1205 1219 1220 1225
## 4.030878 2.844678 3.793365 3.096085 3.434941 3.130775 3.450199 3.201015
## 1233 1239 1241 1242 1247 1253 1254 1256
## 3.328512 3.793365 3.486200 3.468267 3.295773 3.501458 4.207547 3.884536
## 1278 1280 1283 1289 1293 1295 1298 1300
## 3.138084 3.248100 3.143034 3.704281 3.744193 3.586956 3.841038 3.703169
## 1307 1308 1309 1310 1318 1320 1329 1334
## 3.358116 3.798451 3.166189 3.031519 4.030878 3.731798 2.886677 2.844678
## 1339 1344 1346 1357 1359 1367 1373 1376
## 3.600850 3.894708 3.073518 3.486200 4.298718 2.893262 2.752007 3.930122
## 1377 1380 1389 1391 1400 1407 1413 1430
## 3.515353 3.643463 3.127188 3.008952 3.387856 3.562438 3.219859 3.713541
## 1442 1460 1466 1468 1472 1475 1479 1480
## 3.747779 3.248100 3.578283 4.144480 3.092362 3.721626 3.012674 3.389943
## 1482 1483 1485 1486 1491 1495 1503 1513
## 3.852709 2.975761 3.351530 3.838951 3.810710 2.979348 2.907608 2.980847
## 1514 1515 1520 1526 1528 1538 1542 1544
## 3.400115 3.497872 3.973621 3.177860 3.756452 3.650474 2.854850 4.379130
## 1549 1552 1556 1562 1567 1576 1581 1584
## 3.674541 3.706368 3.889622 3.709954 4.090810 3.928035 4.160462 3.492786
## 1585 1589 1599 1606 1608 1611 1617 1624
## 3.454373 3.062758 4.177807 3.027344 4.072877 3.870054 3.076517 3.712953
## 1627 1632 1635 1641 1644 1650 1651 1664
## 3.856296 2.810175 3.856296 3.311031 3.798451 3.374097 2.765178 3.888123
## 1671 1673 1674 1677 1682 1687 1694 1705
## 3.306856 2.924502 3.127776 3.357528 3.076517 3.433441 3.440615 3.306856
## 1706 1710 1711 1714 1718 1720 1727 1734
## 3.306856 3.159016 3.484113 3.970034 3.261858 3.473353 2.706421 4.114876
## 1736 1739 1740 1741 1743 1745 1746 1753
## 3.061259 4.531145 4.039550 3.370511 3.883037 3.164101 3.125689 4.665227
## 1754 1755 1759 1770 1771 1772 1773 1774
## 4.880309 4.324872 3.061259 3.522526 4.028791 4.248047 3.571698 3.479027
## 1781 1789 1798 1800 1813 1824 1828 1832
## 4.429802 4.291545 4.266891 3.671542 3.986791 4.198287 3.762126 3.447788
## 1842 1844 1853 1865 1866 1872 1876 1882
## 3.377684 4.140894 2.907021 4.291545 3.939382 3.464681 4.255220 3.611610
## 1883 1884 1897 1909 1911 1914 1919 1925
## 4.691969 3.508044 2.437081 3.621782 3.747779 3.522526 3.286512 2.685354
lm_p<-predict(fit,newdata=test)
round(predict(fit,newdata=test),1)
## 4 8 15 21 31 33 35 41 48 57 59 66 82 83 84 92
## 4.2 3.4 4.1 3.5 4.2 4.2 3.6 3.9 2.0 3.8 3.8 3.8 3.0 3.8 4.9 3.3
## 106 107 108 112 122 124 129 134 135 140 154 156 162 164 166 174
## 4.2 3.3 3.7 3.9 4.9 4.6 3.7 4.4 3.6 2.6 3.0 4.0 3.4 3.4 2.6 4.4
## 177 178 185 190 191 198 206 209 214 220 227 228 238 243 250 265
## 3.5 3.4 3.4 3.7 4.2 3.4 3.6 3.6 4.4 2.7 4.1 4.0 3.8 3.8 3.4 4.1
## 268 277 283 287 291 299 302 309 310 325 330 337 344 349 352 354
## 3.6 2.3 4.2 3.9 2.8 3.8 4.1 3.4 3.0 3.4 3.9 2.4 3.7 3.5 3.8 3.4
## 356 366 369 374 375 382 391 401 403 409 416 417 419 427 432 439
## 3.3 2.8 3.4 3.7 3.3 3.0 3.4 3.3 3.7 3.7 3.4 4.0 3.4 4.0 3.8 3.3
## 441 443 445 448 451 460 464 467 468 472 474 476 483 486 487 502
## 3.3 3.3 3.3 3.0 3.3 3.8 4.2 3.6 4.0 4.3 3.6 3.9 3.5 4.1 3.9 2.9
## 505 506 510 519 531 537 560 563 565 575 579 586 587 588 590 606
## 4.5 3.7 3.7 5.0 2.1 3.8 4.1 3.3 3.6 2.1 3.9 4.0 3.8 3.5 4.1 3.2
## 618 619 624 631 632 634 647 650 652 665 669 684 685 686 688 693
## 4.0 4.1 4.4 3.9 3.9 3.6 3.5 3.4 3.8 2.9 2.5 3.5 4.3 3.4 3.5 3.7
## 694 709 712 723 728 734 739 740 742 745 746 747 756 760 768 769
## 3.4 3.2 4.2 2.6 2.7 3.0 3.5 3.8 2.9 4.0 3.8 3.5 3.5 3.7 2.2 2.2
## 770 774 780 794 795 801 804 811 817 822 823 824 825 841 847 855
## 3.0 2.9 3.8 3.4 3.4 3.6 3.1 4.4 3.9 3.1 3.5 3.7 4.0 3.4 3.2 2.8
## 860 866 868 881 883 887 889 892 893 894 899 900 902 906 908 927
## 4.0 3.5 4.4 3.4 3.2 2.4 2.8 2.7 2.5 3.0 2.5 2.2 2.0 3.8 4.2 3.7
## 931 938 945 949 957 958 972 976 980 982 983 992 998 1007 1008 1010
## 3.8 2.7 3.4 3.0 3.9 3.6 3.5 3.3 3.9 2.7 2.7 3.3 3.3 4.5 3.1 3.8
## 1013 1016 1021 1027 1032 1033 1034 1036 1042 1046 1047 1048 1064 1070 1089 1091
## 3.3 3.9 3.2 3.5 3.5 3.0 3.7 4.3 3.6 3.7 3.9 4.2 3.1 3.0 3.0 3.3
## 1098 1106 1108 1109 1115 1117 1123 1131 1132 1133 1136 1141 1153 1154 1156 1161
## 3.5 4.1 3.7 4.4 2.6 4.2 4.1 3.5 3.2 3.4 3.5 3.2 3.4 4.8 3.2 3.5
## 1163 1166 1171 1172 1179 1181 1182 1185 1189 1192 1194 1197 1205 1219 1220 1225
## 3.2 4.1 3.7 2.5 3.3 3.4 2.9 4.4 4.0 2.8 3.8 3.1 3.4 3.1 3.5 3.2
## 1233 1239 1241 1242 1247 1253 1254 1256 1278 1280 1283 1289 1293 1295 1298 1300
## 3.3 3.8 3.5 3.5 3.3 3.5 4.2 3.9 3.1 3.2 3.1 3.7 3.7 3.6 3.8 3.7
## 1307 1308 1309 1310 1318 1320 1329 1334 1339 1344 1346 1357 1359 1367 1373 1376
## 3.4 3.8 3.2 3.0 4.0 3.7 2.9 2.8 3.6 3.9 3.1 3.5 4.3 2.9 2.8 3.9
## 1377 1380 1389 1391 1400 1407 1413 1430 1442 1460 1466 1468 1472 1475 1479 1480
## 3.5 3.6 3.1 3.0 3.4 3.6 3.2 3.7 3.7 3.2 3.6 4.1 3.1 3.7 3.0 3.4
## 1482 1483 1485 1486 1491 1495 1503 1513 1514 1515 1520 1526 1528 1538 1542 1544
## 3.9 3.0 3.4 3.8 3.8 3.0 2.9 3.0 3.4 3.5 4.0 3.2 3.8 3.7 2.9 4.4
## 1549 1552 1556 1562 1567 1576 1581 1584 1585 1589 1599 1606 1608 1611 1617 1624
## 3.7 3.7 3.9 3.7 4.1 3.9 4.2 3.5 3.5 3.1 4.2 3.0 4.1 3.9 3.1 3.7
## 1627 1632 1635 1641 1644 1650 1651 1664 1671 1673 1674 1677 1682 1687 1694 1705
## 3.9 2.8 3.9 3.3 3.8 3.4 2.8 3.9 3.3 2.9 3.1 3.4 3.1 3.4 3.4 3.3
## 1706 1710 1711 1714 1718 1720 1727 1734 1736 1739 1740 1741 1743 1745 1746 1753
## 3.3 3.2 3.5 4.0 3.3 3.5 2.7 4.1 3.1 4.5 4.0 3.4 3.9 3.2 3.1 4.7
## 1754 1755 1759 1770 1771 1772 1773 1774 1781 1789 1798 1800 1813 1824 1828 1832
## 4.9 4.3 3.1 3.5 4.0 4.2 3.6 3.5 4.4 4.3 4.3 3.7 4.0 4.2 3.8 3.4
## 1842 1844 1853 1865 1866 1872 1876 1882 1883 1884 1897 1909 1911 1914 1919 1925
## 3.4 4.1 2.9 4.3 3.9 3.5 4.3 3.6 4.7 3.5 2.4 3.6 3.7 3.5 3.3 2.7
test$Happiness1<-round(predict(fit,newdata=test),1)
View(test)
#오차가 생기는지 확인
#Happiness-Happiness1=오차