library(ISLR)
## Warning: package 'ISLR' was built under R version 4.2.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(PerformanceAnalytics)
## Warning: package 'PerformanceAnalytics' was built under R version 4.2.3
## Zorunlu paket yükleniyor: xts
## Warning: package 'xts' was built under R version 4.2.3
## Zorunlu paket yükleniyor: zoo
## Warning: package 'zoo' was built under R version 4.2.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
library(caret)
## Warning: package 'caret' was built under R version 4.2.3
## Zorunlu paket yükleniyor: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.3
## Zorunlu paket yükleniyor: lattice
library(glmnet)
## Warning: package 'glmnet' was built under R version 4.2.3
## Zorunlu paket yükleniyor: Matrix
## Warning: package 'Matrix' was built under R version 4.2.3
## Loaded glmnet 4.1-8
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.1 ✔ tidyr 1.3.0
## ✔ readr 2.1.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::expand() masks Matrix::expand()
## ✖ dplyr::filter() masks stats::filter()
## ✖ xts::first() masks dplyr::first()
## ✖ dplyr::lag() masks stats::lag()
## ✖ xts::last() masks dplyr::last()
## ✖ purrr::lift() masks caret::lift()
## ✖ tidyr::pack() masks Matrix::pack()
## ✖ tidyr::unpack() masks Matrix::unpack()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
###Principal Component Regression
Temel Bilesenler Analizi olan PCA tanima, siniflandirma, goruntu sikistirma alanlarinda kullanilan yararlı bir istatistiksel tekniktir. Temel amaci cok sayida birbiri ile iliskili degiskenler iceren veri setinin boyutlarini veri icerisinde var olan degisimlerin mumkun oldugunca korunarak daha az boyuta indirgenmesini saglayan bir donusum teknigidir. Eldeki veriyi daha az sayida degiskenle ifade edebilecek en iyi donusumu belirlemeyi amaclar. Donusum sonrasinda elde edilen degiskenler ilk degiskenlerin temel bilesenleri olarak adlandirilir.
Ilk temel bilesen varyans degeri en buyuk olandır ve diger temel bilesenler varyans degerleri azalacak sekilde siralanir.
Daha aciklayici bir degisle temel bilesen analizi, istatistikte cok boyutlu uzaydaki bir verinin daha dusuk boyutlu bir uzaya izdusumunu, varyansı maksimize edecek sekilde bulma yontemidir.
Temel Bilesenler Analizi;
Modelde kullanilacak veri train ve test olarak ikiye ayrilir. Train seti ile model kurulur ve test seti uzerinden modelin performansi degerlendirilir.
Bu analizde kullanacagimiz veriyi gorelim;
Factor.Hair.Revised <- read.csv("C:/Users/90555/Downloads/Factor-Hair-Revised.csv")
View(Factor.Hair.Revised)
df<- Factor.Hair.Revised
View(df)
df<-na.omit(df)
glimpse(df)
## Rows: 100
## Columns: 13
## $ ID <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17…
## $ ProdQual <dbl> 8.5, 8.2, 9.2, 6.4, 9.0, 6.5, 6.9, 6.2, 5.8, 6.4, 8.7, 6.…
## $ Ecom <dbl> 3.9, 2.7, 3.4, 3.3, 3.4, 2.8, 3.7, 3.3, 3.6, 4.5, 3.2, 4.…
## $ TechSup <dbl> 2.5, 5.1, 5.6, 7.0, 5.2, 3.1, 5.0, 3.9, 5.1, 5.1, 4.6, 6.…
## $ CompRes <dbl> 5.9, 7.2, 5.6, 3.7, 4.6, 4.1, 2.6, 4.8, 6.7, 6.1, 4.8, 3.…
## $ Advertising <dbl> 4.8, 3.4, 5.4, 4.7, 2.2, 4.0, 2.1, 4.6, 3.7, 4.7, 2.7, 4.…
## $ ProdLine <dbl> 4.9, 7.9, 7.4, 4.7, 6.0, 4.3, 2.3, 3.6, 5.9, 5.7, 6.8, 3.…
## $ SalesFImage <dbl> 6.0, 3.1, 5.8, 4.5, 4.5, 3.7, 5.4, 5.1, 5.8, 5.7, 4.6, 6.…
## $ ComPricing <dbl> 6.8, 5.3, 4.5, 8.8, 6.8, 8.5, 8.9, 6.9, 9.3, 8.4, 6.8, 8.…
## $ WartyClaim <dbl> 4.7, 5.5, 6.2, 7.0, 6.1, 5.1, 4.8, 5.4, 5.9, 5.4, 5.8, 5.…
## $ OrdBilling <dbl> 5.0, 3.9, 5.4, 4.3, 4.5, 3.6, 2.1, 4.3, 4.4, 4.1, 3.8, 3.…
## $ DelSpeed <dbl> 3.7, 4.9, 4.5, 3.0, 3.5, 3.3, 2.0, 3.7, 4.6, 4.4, 4.0, 3.…
## $ Satisfaction <dbl> 8.2, 5.7, 8.9, 4.8, 7.1, 4.7, 5.7, 6.3, 7.0, 5.5, 7.4, 6.…
ID kismi bizim isimize yaramadigi icin onu verimzdemn cikaracagiz
df <- df[, -1]
view(df)
Veriden kisaca bahsedecek olursak: 100 musteri icin urun musteri anketi verisini ele alacagiz. Burada bagimli degiskenimiz satisfaction degeridir. Yani biz burada memnuniyeti tahmin etmeye calisacagiz.
Ilk olarak verimizde eksik veri olup olmadigini kontrol etmekle baslayalim; Verimde eksik veri yok ama bu hatayi aldigim icin ve cozemedigim icin maalesef burayi silmek zorunda kaldim. #library(mice) #md.pattern(df) bu sekilde eksik veri kontrolu yaptik.
Error in (function (filename = “Rplot%03d.png”, width = 480, height = 480, : unable to start png() device
Eksik verimizin olmadigini gozlemliyoruz.
##VERİMİZİ TEST VE TRAİN OLARAK İKİYE AYIRMAKLA DEVAM EDECEGİZ
Veriyi ikiye ayirirkan belirli bir oran kullaniyoruz.
set.seed(145)
sampleIndex<-sample(1:nrow(df),size=0.8*nrow(df))
trainset<-df[sampleIndex,]
testset<-df[-sampleIndex,]
train_x<-trainset %>% dplyr::select(-Satisfaction)
train_y<-trainset$Satisfaction
test_x<-testset %>% dplyr::select(-Satisfaction)
test_y<-testset$Satisfaction
names(df)
## [1] "ProdQual" "Ecom" "TechSup" "CompRes" "Advertising"
## [6] "ProdLine" "SalesFImage" "ComPricing" "WartyClaim" "OrdBilling"
## [11] "DelSpeed" "Satisfaction"
Ayirdigimiz testset ve trainset icin ayri ayrı satisfactionlu ve satisfactionsuz veri olusturuyoruz.
Bagimsiz degiskenlerimizin birbiriyle olan iliskini gormek icin hisgorgam grafigi olusturalim;
#chart.Correlation(df%>%dplyr::select(-c(“Advertising”,“ComPricing”,“WartyClaim”)),histogram=TRUE,pch=19) Daha oncesinde hatasiz calistidigim ama markdown olarak kaydedecegim zaman bu sekilde bir hata aldim ve cozumunu bulamadigim icin bu sekilde yazmak durumunda kaldim. Grafigi inceledigimiz zaman alt tarafta yogun koyulasmis olan grafikleri goruyor olacaktik. Bu koyuluk baska degisle cizgi etrafindaki yogunluk bize bagimsiz degiskenlerin birbirleriyle olan iliskisinin fazla oldugunu gostermektedir. Error in (function (filename = “Rplot%03d.png”, width = 480, height = 480, : unable to start png() device
Veri icerisindeki bagimsiz degiskenlerin bazilarinin birbiriyle onemli derecede iliskisi gorulmektedir. Bu da bize multicolinearty problemiini isaret etmektedir.
##MODEL OLUSTURMA
Ilk olarak ham verimizden modelimizi trainset uzerinden inceleyelim;
model1<-lm(Satisfaction~.,data=trainset)
summary(model1)
##
## Call:
## lm(formula = Satisfaction ~ ., data = trainset)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.22353 -0.27473 0.05019 0.40582 0.87436
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.859480 0.914554 -0.940 0.35066
## ProdQual 0.363873 0.060193 6.045 7.09e-08 ***
## Ecom -0.534750 0.169156 -3.161 0.00235 **
## TechSup 0.078205 0.078778 0.993 0.32436
## CompRes 0.136438 0.118606 1.150 0.25403
## Advertising -0.006205 0.069877 -0.089 0.92950
## ProdLine 0.207972 0.096500 2.155 0.03469 *
## SalesFImage 0.907490 0.122567 7.404 2.64e-10 ***
## ComPricing -0.010125 0.054905 -0.184 0.85423
## WartyClaim -0.190195 0.144723 -1.314 0.19320
## OrdBilling 0.221016 0.125085 1.767 0.08173 .
## DelSpeed 0.052662 0.234841 0.224 0.82324
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5763 on 68 degrees of freedom
## Multiple R-squared: 0.8145, Adjusted R-squared: 0.7845
## F-statistic: 27.14 on 11 and 68 DF, p-value: < 2.2e-16
Yanlarinda * olan degiskenlerin anlamli oldugunu gozlemliyoruz. Cunku onlar icin p 0.05 den kucuktur. Estimate sutunundaki degerler regresyon modelinde degiskenlerin katsayilarini ifade eder. Katsayinin (-) olmasi bagimsiz degisken ile bagimli degisken arasindaki iliskinin negatif oldugunu gosterir. R-Squared değerinin 0.7148 oldugunu goruyoruz. Bu sayinin 1 e yakin olması bizim istedigimiz seydir. Bu bize modelimizde bagimsiz degiskenlerin bagimli degiskeni aciklama yuzdesini verir. Degiskenlerimiz memnuniyet puanini %71 oraninda etkiler. Degiskenler memnuniyet puanini arttirmaktadir diye de yorumlayabiliriz. RSe yi de inceleyecek olursak bu bagimli degiskenin gercek dogrusal modelden ortalama ne kadar saptigi hakkinda bilgi verir. Bu da 0.7094 dir.
Coklu baglantililik kontrolu;
library(car)
## Warning: package 'car' was built under R version 4.2.3
## Zorunlu paket yükleniyor: carData
## Warning: package 'carData' was built under R version 4.2.3
##
## Attaching package: 'car'
## The following object is masked from 'package:purrr':
##
## some
## The following object is masked from 'package:dplyr':
##
## recode
vif(model1)
## ProdQual Ecom TechSup CompRes Advertising ProdLine
## 1.514165 3.600209 3.218277 4.997532 1.514776 4.106217
## SalesFImage ComPricing WartyClaim OrdBilling DelSpeed
## 4.073167 1.790959 3.281176 3.093060 7.329510
Bu degerler 10 dan buyuk oldugunda coklu baglantililik sorunu ortaya cikar.
Normallestirme islemini scale() kullanarak yapacagiz.
Bu bagimsiz degiskenler arasindaki iliskiler ele almak ve bagimli degiskeni tahmin etmek icin kullanılır.
PCR modeli olusturalim;
library(pls) #kısmı en kucuk kareler ve PCR icin
## Warning: package 'pls' was built under R version 4.2.3
##
## Attaching package: 'pls'
## The following object is masked from 'package:caret':
##
## R2
## The following object is masked from 'package:stats':
##
## loadings
modelpcr<-pcr(Satisfaction~.,data=trainset,scale=TRUE)
summary(modelpcr)
## Data: X dimension: 80 11
## Y dimension: 80 1
## Fit method: svdpc
## Number of components considered: 11
## TRAINING: % variance explained
## 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps 7 comps
## X 33.40 56.08 71.92 80.47 85.90 91.25 94.50
## Satisfaction 58.98 59.08 59.11 68.54 71.07 71.75 72.01
## 8 comps 9 comps 10 comps 11 comps
## X 96.54 98.05 99.24 100.00
## Satisfaction 73.44 77.64 80.27 81.45
Burada bize her bir bilesenin varyans degerini gostermektedir.
Ilgili temel bilesenlerin x ler cinsinden katsayilarinii bulmak icin;
modelpcr$coefficients
## , , 1 comps
##
## Satisfaction
## ProdQual 0.08721716
## Ecom 0.10611214
## TechSup 0.05606388
## CompRes 0.23033452
## Advertising 0.11194258
## ProdLine 0.18951508
## SalesFImage 0.11181017
## ComPricing -0.08216872
## WartyClaim 0.08253388
## OrdBilling 0.21282954
## DelSpeed 0.22908623
##
## , , 2 comps
##
## Satisfaction
## ProdQual 0.07937495
## Ecom 0.11738107
## TechSup 0.04952973
## CompRes 0.22989388
## Advertising 0.12026351
## ProdLine 0.18197960
## SalesFImage 0.12313738
## ComPricing -0.07197740
## WartyClaim 0.07774564
## OrdBilling 0.21390583
## DelSpeed 0.22991425
##
## , , 3 comps
##
## Satisfaction
## ProdQual 0.08092105
## Ecom 0.11422149
## TechSup 0.04048912
## CompRes 0.23235898
## Advertising 0.11916760
## ProdLine 0.18372460
## SalesFImage 0.11951646
## ComPricing -0.07149507
## WartyClaim 0.06866071
## OrdBilling 0.21566965
## DelSpeed 0.23318971
##
## , , 4 comps
##
## Satisfaction
## ProdQual 0.319541360
## Ecom 0.194632101
## TechSup -0.007803581
## CompRes 0.145669332
## Advertising 0.260144039
## ProdLine 0.225044113
## SalesFImage 0.216242937
## ComPricing -0.218827070
## WartyClaim -0.006870847
## OrdBilling 0.097404952
## DelSpeed 0.138037241
##
## , , 5 comps
##
## Satisfaction
## ProdQual 0.414805735
## Ecom 0.295072930
## TechSup -0.006936973
## CompRes 0.146010657
## Advertising 0.070167678
## ProdLine 0.254986813
## SalesFImage 0.267289462
## ComPricing -0.138969288
## WartyClaim -0.016027798
## OrdBilling 0.092099013
## DelSpeed 0.134707824
##
## , , 6 comps
##
## Satisfaction
## ProdQual 0.488182443
## Ecom 0.261685986
## TechSup 0.009235641
## CompRes 0.152758146
## Advertising 0.112601995
## ProdLine 0.228306804
## SalesFImage 0.241229550
## ComPricing -0.053976604
## WartyClaim 0.001302351
## OrdBilling 0.110561011
## DelSpeed 0.132639390
##
## , , 7 comps
##
## Satisfaction
## ProdQual 0.50427277
## Ecom 0.26267308
## TechSup 0.01188492
## CompRes 0.14859333
## Advertising 0.09673984
## ProdLine 0.16712339
## SalesFImage 0.24743923
## ComPricing -0.09062607
## WartyClaim -0.00870250
## OrdBilling 0.18007035
## DelSpeed 0.11081294
##
## , , 8 comps
##
## Satisfaction
## ProdQual 0.51443727
## Ecom 0.21255233
## TechSup 0.15674406
## CompRes 0.31357432
## Advertising 0.07789320
## ProdLine 0.06481775
## SalesFImage 0.30935286
## ComPricing -0.10990678
## WartyClaim -0.14325560
## OrdBilling 0.06332029
## DelSpeed 0.14247843
##
## , , 9 comps
##
## Satisfaction
## ProdQual 0.56451167
## Ecom -0.10990549
## TechSup -0.09583756
## CompRes 0.35480795
## Advertising -0.01363354
## ProdLine -0.03036170
## SalesFImage 0.65988335
## ComPricing -0.14151047
## WartyClaim 0.10433603
## OrdBilling -0.02271774
## DelSpeed 0.22490690
##
## , , 10 comps
##
## Satisfaction
## ProdQual 0.54278702
## Ecom -0.28722486
## TechSup 0.10347668
## CompRes 0.03099156
## Advertising -0.01931026
## ProdLine 0.09381129
## SalesFImage 0.85308150
## ComPricing -0.08537194
## WartyClaim -0.09483309
## OrdBilling 0.09757962
## DelSpeed 0.37800104
##
## , , 11 comps
##
## Satisfaction
## ProdQual 0.482308037
## Ecom -0.388922778
## TechSup 0.115471958
## CompRes 0.166740612
## Advertising -0.007086578
## ProdLine 0.283161658
## SalesFImage 0.968879645
## ComPricing -0.016002319
## WartyClaim -0.154351936
## OrdBilling 0.201488868
## DelSpeed 0.039363748
modelpcr$scores
## Comp 1 Comp 2 Comp 3 Comp 4 Comp 5 Comp 6
## 2 -1.09621234 -2.53874852 -2.02935858 -0.559374272 0.51758885 -0.38375888
## 54 1.10837574 -1.21192785 0.67691516 0.278491529 0.28683502 -1.29850584
## 92 4.59098621 1.14578785 0.26523609 0.176747747 -1.68584081 0.04554362
## 75 -0.32466398 0.82319487 0.07567640 0.964791069 0.24584264 0.36559216
## 47 -1.16774776 -1.98777227 0.99669197 0.845049071 -0.87945458 -0.30536038
## 64 2.76850465 -2.37417915 0.15229428 -0.422589184 0.28719880 0.10273602
## 20 -1.52552297 2.24371270 -0.56950213 1.103113558 -0.58694753 0.79015360
## 45 -0.89820944 -2.40319927 -2.51581567 -0.580383512 0.85691651 -0.37102836
## 32 2.15495797 -2.47308754 1.16067752 -0.453032015 -0.20765329 0.31464422
## 43 -2.19656304 1.80770124 -0.80843730 1.683123834 -0.43948912 0.36294167
## 80 2.24237833 0.61202872 0.78950073 0.725655273 0.03282150 -0.19326140
## 1 -0.30022279 1.52512669 -2.00841758 1.101477803 0.09110249 0.02822082
## 86 2.13242800 0.47380381 -1.11016815 0.223239439 -0.10147078 -0.02783907
## 21 1.35664437 0.62670324 2.15498363 -1.509903499 0.46036575 -0.15785030
## 53 -1.11476193 -2.06896792 -1.19601692 -0.199586101 -0.21881083 0.52790141
## 51 1.85650837 0.08256858 0.50885458 -0.224665196 0.01048100 -0.35874178
## 57 -3.63123254 2.32208112 -0.25227720 -1.169747208 -1.24862556 0.30535305
## 97 1.31423377 0.97616749 -2.23906584 0.292995442 0.37726904 -0.17899123
## 22 -3.38013017 0.79810980 1.65745600 2.798495323 -0.91568504 -1.21463752
## 69 2.33000604 0.34650756 -1.06352632 -0.005037041 -0.46789444 -0.13766174
## 72 1.92792268 -0.20891115 -1.15320843 1.393731868 1.45724546 -1.40814718
## 38 -2.64688112 -0.72712130 -0.50086855 -0.393655721 -1.81194796 0.52000622
## 81 0.29112219 -2.06388880 0.56210882 1.557653606 0.18083009 0.27584884
## 26 -0.39805399 0.57473322 0.55619754 -1.476013218 0.55027896 0.08892553
## 40 0.84652567 3.35542884 -0.46684558 0.450156331 0.15299190 -0.59492217
## 84 4.35455006 -0.31275221 2.77945476 -0.517222755 -0.58713072 0.04918600
## 76 -0.25412294 -1.88615324 1.45949803 1.712596827 1.15320547 0.83263069
## 18 -1.94079497 0.92683773 -0.30610706 -2.245390779 -0.39102614 -0.34104977
## 15 -2.07087086 1.73115042 -0.55149638 -1.272307569 -0.27724238 -0.26006370
## 83 2.25802219 -1.85907271 0.28884469 0.721757944 -0.22887499 0.02382639
## 16 -1.25924869 -2.12587187 -1.63379290 0.014858084 -0.03530272 -0.62001695
## 58 -1.42545471 -0.43558695 0.42532416 0.773128489 1.54647500 -0.65454132
## 39 -0.60403132 1.49560605 -1.55861454 -0.007110675 0.76652474 1.49771352
## 9 -0.63462029 1.25039591 -0.43507935 -1.863733622 -0.19836925 -0.06870800
## 87 3.94352995 2.04159415 -2.01149803 0.136965112 0.29923270 -1.47641984
## 95 0.48865805 0.37757063 -0.82747589 1.793225304 -0.31191384 0.43807041
## 33 0.93108175 1.05730411 0.59542608 -0.297948669 0.74140309 0.86927984
## 7 5.02392173 1.22216240 0.39739795 0.499163374 -1.28150854 -0.30030599
## 65 1.69075309 0.35243745 1.26522242 0.202377806 1.03967354 0.05654479
## 71 -2.41228571 1.83200135 1.48649137 0.694712376 0.13696387 1.59638318
## 62 0.94792037 0.42810711 0.46800132 1.428109397 -0.01148675 -0.03040104
## 70 0.82906978 1.42466233 -1.54136236 -0.528825357 0.43473828 -0.57163566
## 10 -0.59847766 1.83596986 -0.33727501 -0.456957671 -0.02033296 -0.31182012
## 25 0.21784263 0.87619116 0.60642935 -1.250308384 -0.22819897 -0.46945728
## 3 -2.37286033 -0.87176371 -0.19719710 1.212151667 0.91485156 -0.07340526
## 85 -0.80419268 -2.60048099 -0.19962010 -1.538246085 -0.49855441 -0.44886261
## 34 -0.25141765 0.56258605 -0.07367013 -0.459678533 0.95211593 1.69024479
## 100 1.40605890 1.17544873 -0.49127275 0.243272545 1.17472707 1.92726174
## 12 1.63458019 2.33547939 1.72584901 0.447457546 -0.31269103 -0.67169867
## 82 0.01247446 -1.77180496 0.11589420 -0.321914391 -0.99903597 0.08303498
## 55 0.36839027 0.44802273 -1.68604031 -0.932385568 -0.56237603 0.80099345
## 11 0.46561004 -1.26557907 -0.92016389 0.223284757 -0.83291234 -0.14083198
## 31 0.19546904 -1.64328145 2.86929425 -0.032278395 1.13074319 -0.45617683
## 56 -0.48358345 -0.80722441 1.26443356 0.533810492 -0.90307016 0.75937903
## 88 -1.52623237 -2.43986900 0.68855110 -1.388777293 0.56702414 0.23107107
## 89 -0.42868117 -0.44825114 0.03985027 0.007533453 -0.38528884 1.32953218
## 35 1.66403603 1.19718266 1.09821915 0.254775465 -1.13613372 -0.82396519
## 6 2.73287744 0.41076767 -1.63394175 -0.582248075 0.85276282 0.38212829
## 14 -1.19042482 -1.60768234 0.02788528 -0.073179216 -1.72598264 -0.04318438
## 50 -1.02820309 0.01721419 -1.07581083 1.160002337 0.28809051 -1.35857748
## 44 -2.38585803 2.08327645 2.24848820 -0.915616538 0.04813854 -1.92235205
## 17 -0.58958513 -0.09002468 1.03716953 -1.477657851 0.15780860 -1.21769318
## 28 1.03552837 -0.28816363 0.07249815 -1.752580789 -0.62745098 0.63261283
## 37 0.49072194 -1.11318768 0.40785997 0.623582122 -0.13913603 0.60346890
## 78 -1.31550924 -0.60963597 1.25627687 -0.021269333 -0.34609072 1.73996231
## 4 1.53403052 0.16129556 1.85014803 -0.959361619 0.90903265 0.99842183
## 8 1.27871969 1.13740595 -0.74770831 -0.367060775 1.20585967 -0.30364582
## 23 -1.26212924 -2.30274967 0.98950582 0.507722559 0.10712594 -0.89891549
## 41 0.97853521 1.07921037 -2.53561922 -0.202168743 -1.00225281 0.64841219
## 13 -2.95875477 1.64438144 0.27181555 1.162288621 -1.33368049 0.33485169
## 90 -3.60990475 2.59989091 2.87248177 -0.707146163 0.34780796 -1.30773212
## 36 2.00291036 -2.34632142 0.29237608 0.924129572 0.27208428 0.08699447
## 52 -1.16790606 -2.42128283 -2.92091971 -0.849344004 0.06959445 -0.62585391
## 77 -0.19668199 -0.39781403 2.66991812 -0.716208911 0.66765966 1.02620705
## 29 -1.29097683 -2.65013910 -1.30290171 -0.785765997 -0.38739251 -0.60448759
## 46 -1.72290916 1.51472534 0.32668980 -1.187928376 1.10509990 0.21719751
## 73 -1.32858521 2.90930637 -2.01043554 0.187333276 1.05356945 0.06037649
## 79 -3.33462530 -1.01158261 0.16310416 0.844435610 0.86172931 0.14028264
## 5 0.65891453 -1.38794859 -0.30532285 0.021228020 -1.24412047 0.11651556
## 94 -2.93567004 -1.08981220 -0.40015778 0.779984454 0.25956606 -0.26794287
## Comp 7 Comp 8 Comp 9 Comp 10 Comp 11
## 2 1.011419393 0.63314933 -0.329390535 0.354968235 -0.338096183
## 54 0.455768403 -0.31063422 0.068039284 0.027597918 0.079140429
## 92 0.470274447 -0.32654947 -0.319286098 0.396074714 -0.472619351
## 75 -0.668945726 0.34838215 0.108191484 -0.089695367 0.087178800
## 47 -1.867115897 0.23410335 -0.652535884 1.024341388 -0.305768852
## 64 -0.494305505 0.45392910 0.065611866 0.114427559 0.427811121
## 20 -0.051936151 0.11747368 0.835082198 0.271613254 -0.106126636
## 45 0.572862862 0.54803299 -0.439331098 0.186775653 -0.020887818
## 32 0.086192659 0.40082613 0.302998643 0.094018785 -0.027398732
## 43 0.175975097 0.34418526 -0.806643355 0.308009169 0.158758538
## 80 0.670950228 0.05633955 0.736779117 -0.004964070 0.581896448
## 1 -1.186641227 -0.06069597 0.343611752 0.194737544 0.434332125
## 86 -0.293093925 0.35884269 -0.218992366 0.069600003 -0.329462895
## 21 0.529353189 0.33314050 -0.119156260 0.526532323 0.013060394
## 53 0.130558970 -0.25727491 0.976325164 -0.329463751 -0.041008759
## 51 -0.611781487 -0.06470170 -0.537745633 -0.229344643 0.494359568
## 57 0.645540881 -0.27591873 0.099078097 0.057543991 -0.043910600
## 97 -0.679266824 0.01764825 0.080926357 0.032446190 -0.093469133
## 22 0.387857631 -0.03991376 -0.442229307 -0.322518129 0.069036899
## 69 -0.810967505 -0.48365864 -0.106637443 -0.392960104 -0.472004312
## 72 0.648373770 -0.77128143 0.043399802 -0.021130767 0.194305755
## 38 0.189382287 0.32385731 -0.166167718 -0.158341952 0.086090199
## 81 -0.013869866 0.99808694 -0.038377878 -0.610573067 -0.516964832
## 26 -1.647091332 0.50435871 -0.218016078 -0.130938521 0.128678500
## 40 -0.797376159 -0.48723828 -0.287308957 0.343166994 0.349779383
## 84 0.024966930 0.30087155 0.772774669 0.870422850 0.535272973
## 76 0.424182574 0.12452552 0.657248053 0.283368171 -0.692935061
## 18 -0.075151209 -0.04609442 -0.201967850 -0.009135321 0.308546948
## 15 0.986196072 -0.06635864 -0.125388470 -0.005132520 -0.242219716
## 83 0.378758847 0.01922131 0.085150976 -0.022077195 -0.146094895
## 16 0.426509534 -0.33475794 0.206132838 0.794382248 -0.167989467
## 58 -0.184826930 -0.53510216 0.316049090 0.277501487 0.090390077
## 39 0.007932281 0.20779753 -0.123203637 0.048673459 -0.284962882
## 9 0.779551847 0.51249701 0.404244138 -0.193791615 0.275767598
## 87 0.717218905 -0.53314008 0.230333855 -0.096978225 -0.199694253
## 95 0.443652905 -0.36511727 -0.004094971 -0.223574036 0.342290335
## 33 0.798187698 0.60384628 -0.832687496 -0.118406440 0.405808924
## 7 -0.478348360 0.77880601 -0.033089227 -0.296969712 0.054667737
## 65 0.052342236 -0.43873223 -0.247468857 0.228884596 0.264108471
## 71 -0.478655696 -0.42246503 0.493478259 -0.203797008 -0.143337356
## 62 0.269804493 1.64665203 -0.254612909 -0.471406641 -0.297015488
## 70 -1.072919679 -0.21062825 0.517366129 0.249579645 -0.211846645
## 10 0.636339463 0.44284881 -0.596328985 -0.011683353 -0.142370803
## 25 -0.173373823 -0.79767289 -0.088815262 -0.213220154 -0.228879150
## 3 -0.564518582 -0.51889293 0.300765288 -0.818258884 0.077947716
## 85 -0.036531764 0.39422535 0.385983120 -0.232107110 0.341907384
## 34 -0.237355811 0.37489664 -0.339329978 -0.277896203 -0.269157495
## 100 0.608858634 0.24485483 0.290977439 0.164645053 0.060334726
## 12 0.193863411 0.43590319 -0.581843753 -0.227406064 -0.302376404
## 82 0.050531479 -0.21954319 0.029561929 -0.644162643 -0.075791211
## 55 -0.713777775 0.05536791 0.268859753 -0.005088617 -0.194667092
## 11 0.421358995 -0.37277820 0.310451510 -0.354566513 -0.168008131
## 31 0.353174952 -0.43221026 -0.299387435 -0.233602838 0.049286267
## 56 0.080966023 0.30112313 -0.160990802 -0.054564707 0.557421401
## 88 -0.087247770 0.38495712 -0.035737016 -0.403897085 0.460408842
## 89 0.121015152 -0.61457565 -0.134088472 0.071408558 0.011471373
## 35 1.125316262 0.11829438 0.936674322 -0.553656773 -0.058957688
## 6 0.080187311 -0.45393961 -0.016031264 0.037562244 -0.049008870
## 14 0.711081051 -0.94515502 -0.096249795 -0.158554751 0.140527674
## 50 0.075614854 0.21515913 0.084228273 -0.226129370 -0.039649458
## 44 -0.397037528 0.40132585 0.565488578 0.320298839 -0.005815337
## 17 0.078651671 0.37478680 -0.131961613 0.181422277 -0.637348472
## 28 -0.098755628 -0.17483242 0.124416143 0.395109119 -0.031596278
## 37 0.036833390 -0.40430734 -0.108251223 -0.069563254 -0.100534520
## 78 0.672457255 -0.16201288 -0.100494521 0.380083935 -0.065352428
## 4 -0.076954084 -0.84520806 -0.421774825 -0.438798096 0.298223679
## 8 -0.893575763 0.04670079 0.330087658 -0.026876265 -0.274418967
## 23 -0.599187611 -0.36503490 -0.449775166 -0.468209493 -0.156061189
## 41 -0.710012296 0.55314100 0.005375396 -0.510414891 0.225920792
## 13 0.029158087 -0.62950984 -0.296888505 0.875697574 -0.023022102
## 90 -0.411632606 0.33711053 0.096634904 -0.107004159 -0.148160280
## 36 0.141827276 -0.33623088 -1.021670492 0.644606181 0.280965640
## 52 0.491103061 0.17936620 -0.033181912 0.552963548 -0.152099359
## 77 -0.345556013 -0.67763105 0.308208122 0.060318536 -0.732003289
## 29 -0.900986978 -0.45404391 -0.461174070 -0.455595565 0.125267396
## 46 0.568755061 -0.56510933 -0.449269410 -0.449096801 -0.100054458
## 73 0.839080315 -0.04750873 -0.295661374 0.024025827 0.343213795
## 79 -0.232507890 0.40948864 0.420954386 0.143110974 0.383780078
## 5 -0.645633502 -0.61999115 0.064695191 -0.189463766 0.042628904
## 94 -0.063048937 0.53032791 0.757054113 0.455097598 0.328559960
## attr(,"class")
## [1] "scores"
Modelleme fonksiyonlari tarafindan dondurulen nesnelerden uygun degerleri cikarmak icin fitted.values takma adini kullanacagiz.
modelpcr$fitted.values
## , , 1 comps
##
## Satisfaction
## 2 7.421447
## 54 6.325004
## 92 4.592942
## 75 7.037720
## 47 7.457024
## 64 5.499346
## 20 7.634962
## 45 7.322971
## 32 5.804491
## 43 7.968701
## 80 5.761013
## 1 7.025565
## 86 5.815696
## 21 6.201529
## 53 7.430672
## 51 5.952923
## 57 8.682228
## 97 6.222621
## 22 8.557344
## 69 5.717431
## 72 5.917406
## 38 8.192665
## 81 6.731462
## 26 7.074220
## 40 6.455234
## 84 4.710533
## 76 7.002637
## 18 7.841496
## 15 7.906189
## 83 5.753232
## 16 7.502532
## 58 7.585194
## 39 7.176662
## 9 7.191876
## 87 4.914952
## 95 6.633218
## 33 6.413180
## 7 4.377624
## 65 6.035361
## 71 8.075990
## 62 6.404806
## 70 6.463916
## 10 7.173900
## 25 6.767907
## 3 8.056382
## 85 7.276212
## 34 7.001292
## 100 6.176953
## 12 6.063298
## 82 6.870046
## 55 6.693033
## 11 6.644681
## 31 6.779034
## 56 7.116758
## 88 7.635315
## 89 7.089453
## 35 6.048649
## 6 5.517065
## 14 7.468303
## 50 7.387622
## 44 8.062846
## 17 7.169478
## 28 6.361234
## 37 6.632192
## 78 7.530513
## 4 6.113306
## 8 6.240284
## 23 7.503965
## 41 6.389580
## 13 8.347774
## 90 8.671621
## 36 5.880111
## 52 7.457103
## 77 6.974069
## 29 7.518312
## 46 7.733132
## 73 7.537016
## 79 8.534712
## 5 6.548542
## 94 8.336293
##
## , , 2 comps
##
## Satisfaction
## 2 7.358522
## 54 6.294965
## 92 4.621342
## 75 7.058124
## 47 7.407756
## 64 5.440500
## 20 7.690575
## 45 7.263405
## 32 5.743193
## 43 8.013507
## 80 5.776182
## 1 7.063366
## 86 5.827440
## 21 6.217062
## 53 7.379391
## 51 5.954970
## 57 8.739783
## 97 6.246817
## 22 8.577125
## 69 5.726020
## 72 5.912228
## 38 8.174643
## 81 6.680306
## 26 7.088466
## 40 6.538401
## 84 4.702781
## 76 6.955887
## 18 7.864469
## 15 7.949097
## 83 5.707153
## 16 7.449840
## 58 7.574398
## 39 7.213732
## 9 7.222868
## 87 4.965555
## 95 6.642576
## 33 6.439387
## 7 4.407916
## 65 6.044097
## 71 8.121398
## 62 6.415417
## 70 6.499227
## 10 7.219406
## 25 6.789624
## 3 8.034775
## 85 7.211757
## 34 7.015236
## 100 6.206087
## 12 6.121185
## 82 6.826130
## 55 6.704137
## 11 6.613312
## 31 6.738304
## 56 7.096750
## 88 7.574841
## 89 7.078342
## 35 6.078322
## 6 5.527246
## 14 7.428455
## 50 7.388049
## 44 8.114482
## 17 7.167246
## 28 6.354092
## 37 6.604600
## 78 7.515403
## 4 6.117304
## 8 6.268476
## 23 7.446889
## 41 6.416329
## 13 8.388532
## 90 8.736062
## 36 5.821955
## 52 7.397090
## 77 6.964209
## 29 7.452626
## 46 7.770675
## 73 7.609126
## 79 8.509639
## 5 6.514140
## 94 8.309281
##
## , , 3 comps
##
## Satisfaction
## 2 7.388219
## 54 6.285059
## 92 4.617460
## 75 7.057016
## 47 7.393170
## 64 5.438271
## 20 7.698909
## 45 7.300221
## 32 5.726208
## 43 8.025337
## 80 5.764629
## 1 7.092757
## 86 5.843686
## 21 6.185526
## 53 7.396893
## 51 5.947523
## 57 8.743475
## 97 6.279583
## 22 8.552871
## 69 5.741583
## 72 5.929104
## 38 8.181972
## 81 6.672081
## 26 7.080326
## 40 6.545233
## 84 4.662107
## 76 6.934529
## 18 7.868948
## 15 7.957167
## 83 5.702927
## 16 7.473749
## 58 7.568173
## 39 7.236541
## 9 7.229235
## 87 4.994990
## 95 6.654686
## 33 6.430673
## 7 4.402101
## 65 6.025582
## 71 8.099645
## 62 6.408568
## 70 6.521783
## 10 7.224342
## 25 6.780750
## 3 8.037660
## 85 7.214678
## 34 7.016314
## 100 6.213276
## 12 6.095930
## 82 6.824434
## 55 6.728810
## 11 6.626778
## 31 6.696315
## 56 7.078247
## 88 7.564765
## 89 7.077759
## 35 6.062251
## 6 5.551157
## 14 7.428047
## 50 7.403792
## 44 8.081578
## 17 7.152069
## 28 6.353031
## 37 6.598632
## 78 7.497019
## 4 6.090230
## 8 6.279418
## 23 7.432409
## 41 6.453435
## 13 8.384554
## 90 8.694026
## 36 5.817677
## 52 7.439834
## 77 6.925138
## 29 7.471692
## 46 7.765895
## 73 7.638546
## 79 8.507252
## 5 6.518608
## 94 8.315137
##
## , , 4 comps
##
## Satisfaction
## 2 7.168247
## 54 6.394575
## 92 4.686966
## 75 7.436417
## 47 7.725483
## 64 5.272089
## 20 8.132704
## 45 7.071988
## 32 5.548055
## 43 8.687220
## 80 6.049990
## 1 7.525909
## 86 5.931474
## 21 5.591762
## 53 7.318407
## 51 5.859175
## 57 8.283476
## 97 6.394802
## 22 9.653369
## 69 5.739602
## 72 6.477184
## 38 8.027169
## 81 7.284622
## 26 6.499890
## 40 6.722255
## 84 4.458711
## 76 7.608002
## 18 6.985956
## 15 7.456837
## 83 5.986755
## 16 7.479592
## 58 7.872203
## 39 7.233745
## 9 6.496328
## 87 5.048852
## 95 7.359865
## 33 6.313506
## 7 4.598395
## 65 6.105166
## 71 8.372838
## 62 6.970167
## 70 6.313824
## 10 7.044645
## 25 6.289070
## 3 8.514335
## 85 6.609768
## 34 6.835547
## 100 6.308942
## 12 6.271891
## 82 6.697842
## 55 6.362153
## 11 6.714584
## 31 6.683622
## 56 7.288166
## 88 7.018633
## 89 7.080722
## 35 6.162440
## 6 5.322190
## 14 7.399269
## 50 7.859959
## 44 7.721515
## 17 6.570985
## 28 5.663835
## 37 6.843853
## 78 7.488654
## 4 5.712964
## 8 6.135072
## 23 7.632069
## 41 6.373932
## 13 8.841620
## 90 8.415944
## 36 6.181087
## 52 7.105832
## 77 6.643491
## 29 7.162693
## 46 7.298746
## 73 7.712214
## 79 8.839323
## 5 6.526956
## 94 8.621863
##
## , , 5 comps
##
## Satisfaction
## 2 7.036025
## 54 6.321301
## 92 5.117625
## 75 7.373615
## 47 7.950146
## 64 5.198723
## 20 8.282644
## 45 6.853082
## 32 5.601101
## 43 8.799490
## 80 6.041606
## 1 7.502636
## 86 5.957395
## 21 5.474159
## 53 7.374303
## 51 5.856497
## 57 8.602446
## 97 6.298426
## 22 9.887287
## 69 5.859129
## 72 6.104920
## 38 8.490043
## 81 7.238428
## 26 6.359317
## 40 6.683172
## 84 4.608698
## 76 7.313407
## 18 7.085847
## 15 7.527661
## 83 6.045223
## 16 7.488610
## 58 7.477146
## 39 7.037931
## 9 6.547003
## 87 4.972410
## 95 7.439545
## 33 6.124110
## 7 4.925765
## 65 5.839574
## 71 8.337850
## 62 6.973101
## 70 6.202768
## 10 7.049839
## 25 6.347365
## 3 8.280630
## 85 6.737127
## 34 6.592322
## 100 6.008850
## 12 6.351770
## 82 6.953053
## 55 6.505816
## 11 6.927357
## 31 6.394766
## 56 7.518861
## 88 6.873783
## 89 7.179147
## 35 6.452673
## 6 5.104346
## 14 7.840184
## 50 7.786364
## 44 7.709218
## 17 6.530672
## 28 5.824122
## 37 6.879396
## 78 7.577066
## 4 5.480745
## 8 5.827027
## 23 7.604703
## 41 6.629965
## 13 9.182318
## 90 8.327094
## 36 6.111582
## 52 7.088054
## 77 6.472933
## 29 7.261655
## 46 7.016441
## 73 7.443073
## 79 8.619189
## 5 6.844775
## 94 8.555555
##
## , , 6 comps
##
## Satisfaction
## 2 6.984729
## 54 6.147735
## 92 5.123713
## 75 7.422482
## 47 7.909329
## 64 5.212455
## 20 8.388261
## 45 6.803488
## 32 5.643159
## 43 8.848003
## 80 6.015773
## 1 7.506409
## 86 5.953674
## 21 5.453059
## 53 7.444866
## 51 5.808545
## 57 8.643261
## 97 6.274501
## 22 9.724930
## 69 5.840728
## 72 5.916698
## 38 8.559551
## 81 7.275300
## 26 6.371203
## 40 6.603651
## 84 4.615272
## 76 7.424702
## 18 7.040260
## 15 7.492899
## 83 6.048408
## 16 7.405735
## 58 7.389655
## 39 7.238125
## 9 6.537819
## 87 4.775063
## 95 7.498101
## 33 6.240303
## 7 4.885624
## 65 5.847132
## 71 8.551233
## 62 6.969038
## 70 6.126359
## 10 7.008159
## 25 6.284615
## 3 8.270818
## 85 6.677129
## 34 6.818251
## 100 6.266461
## 12 6.261986
## 82 6.964152
## 55 6.612882
## 11 6.908532
## 31 6.333790
## 56 7.620365
## 88 6.904669
## 89 7.356860
## 35 6.342537
## 6 5.155424
## 14 7.834411
## 50 7.604768
## 44 7.452264
## 17 6.367907
## 28 5.908681
## 37 6.960060
## 78 7.809640
## 4 5.614201
## 8 5.786440
## 23 7.484548
## 41 6.716636
## 13 9.227076
## 90 8.152294
## 36 6.123210
## 52 7.004398
## 77 6.610102
## 29 7.180855
## 46 7.045473
## 73 7.451143
## 79 8.637940
## 5 6.860349
## 94 8.519740
##
## , , 7 comps
##
## Satisfaction
## 2 6.878319
## 54 6.099783
## 92 5.074236
## 75 7.492862
## 47 8.105767
## 64 5.264461
## 20 8.393725
## 45 6.743218
## 32 5.634090
## 43 8.829489
## 80 5.945183
## 1 7.631254
## 86 5.984510
## 21 5.397366
## 53 7.431130
## 51 5.872911
## 57 8.575344
## 97 6.345966
## 22 9.684124
## 69 5.926050
## 72 5.848483
## 38 8.539626
## 81 7.276759
## 26 6.544493
## 40 6.687543
## 84 4.612645
## 76 7.380074
## 18 7.048166
## 15 7.389142
## 83 6.008559
## 16 7.360862
## 58 7.409101
## 39 7.237290
## 9 6.455803
## 87 4.699604
## 95 7.451424
## 33 6.156326
## 7 4.935951
## 65 5.841625
## 71 8.601592
## 62 6.940652
## 70 6.239240
## 10 6.941210
## 25 6.302855
## 3 8.330210
## 85 6.680973
## 34 6.843224
## 100 6.202403
## 12 6.241590
## 82 6.958836
## 55 6.687978
## 11 6.864201
## 31 6.296633
## 56 7.611847
## 88 6.913849
## 89 7.344129
## 35 6.224143
## 6 5.146987
## 14 7.759599
## 50 7.596813
## 44 7.494036
## 17 6.359632
## 28 5.919071
## 37 6.956185
## 78 7.738892
## 4 5.622297
## 8 5.880452
## 23 7.547588
## 41 6.791336
## 13 9.224008
## 90 8.195601
## 36 6.108288
## 52 6.952729
## 77 6.646458
## 29 7.275647
## 46 6.985634
## 73 7.362864
## 79 8.662402
## 5 6.928276
## 94 8.526374
##
## , , 8 comps
##
## Satisfaction
## 2 7.077114
## 54 6.002251
## 92 4.971706
## 75 7.602246
## 47 8.179271
## 64 5.406985
## 20 8.430610
## 45 6.915288
## 32 5.759941
## 43 8.937556
## 80 5.962872
## 1 7.612197
## 86 6.097179
## 21 5.501966
## 53 7.350351
## 51 5.852596
## 57 8.488712
## 97 6.351507
## 22 9.671592
## 69 5.774191
## 72 5.606317
## 38 8.641310
## 81 7.590137
## 26 6.702851
## 40 6.534560
## 84 4.707113
## 76 7.419173
## 18 7.033694
## 15 7.368306
## 83 6.014594
## 16 7.255755
## 58 7.241090
## 39 7.302534
## 9 6.616716
## 87 4.532210
## 95 7.336785
## 33 6.345921
## 7 5.180480
## 65 5.703873
## 71 8.468947
## 62 7.457666
## 70 6.173108
## 10 7.080256
## 25 6.052403
## 3 8.167289
## 85 6.804751
## 34 6.960933
## 100 6.279282
## 12 6.378454
## 82 6.889904
## 55 6.705363
## 11 6.747157
## 31 6.160928
## 56 7.706393
## 88 7.034717
## 89 7.151165
## 35 6.261285
## 6 5.004460
## 14 7.462840
## 50 7.664368
## 44 7.620044
## 17 6.477307
## 28 5.864177
## 37 6.829241
## 78 7.688023
## 4 5.356920
## 8 5.895116
## 23 7.432975
## 41 6.965010
## 13 9.026356
## 90 8.301447
## 36 6.002719
## 52 7.009047
## 77 6.433696
## 29 7.133087
## 46 6.808202
## 73 7.347947
## 79 8.790973
## 5 6.733612
## 94 8.692885
##
## , , 9 comps
##
## Satisfaction
## 2 6.871729
## 54 6.044675
## 92 4.772621
## 75 7.669707
## 47 7.772395
## 64 5.447896
## 20 8.951308
## 45 6.641352
## 32 5.948870
## 43 8.434590
## 80 6.422276
## 1 7.826449
## 86 5.960631
## 21 5.427668
## 53 7.959119
## 51 5.517295
## 57 8.550490
## 97 6.401967
## 22 9.395849
## 69 5.707700
## 72 5.633378
## 38 8.537700
## 81 7.566207
## 26 6.566912
## 40 6.355415
## 84 5.188961
## 76 7.828986
## 18 6.907761
## 15 7.290123
## 83 6.067688
## 16 7.384285
## 58 7.438156
## 39 7.225713
## 9 6.868774
## 87 4.675830
## 95 7.334232
## 33 5.826716
## 7 5.159847
## 65 5.549568
## 71 8.776645
## 62 7.298907
## 70 6.495701
## 10 6.708427
## 25 5.997024
## 3 8.354825
## 85 7.045423
## 34 6.749351
## 100 6.460715
## 12 6.015657
## 82 6.908337
## 55 6.873005
## 11 6.940733
## 31 5.974251
## 56 7.606010
## 88 7.012434
## 89 7.067557
## 35 6.845329
## 6 4.994464
## 14 7.402825
## 50 7.716887
## 44 7.972643
## 17 6.395025
## 28 5.941754
## 37 6.761743
## 78 7.625362
## 4 5.093930
## 8 6.100935
## 23 7.152527
## 41 6.968362
## 13 8.841237
## 90 8.361702
## 36 5.365677
## 52 6.988357
## 77 6.625873
## 29 6.845531
## 46 6.528069
## 73 7.163594
## 79 9.053450
## 5 6.773951
## 94 9.164931
##
## , , 10 comps
##
## Satisfaction
## 2 6.674090
## 54 6.029309
## 92 4.552095
## 75 7.719648
## 47 7.202063
## 64 5.384185
## 20 8.800080
## 45 6.537360
## 32 5.896522
## 43 8.263097
## 80 6.425040
## 1 7.718024
## 86 5.921879
## 21 5.134506
## 53 8.142558
## 51 5.644990
## 57 8.518451
## 97 6.383902
## 22 9.575420
## 69 5.926492
## 72 5.645143
## 38 8.625861
## 81 7.906162
## 26 6.639815
## 40 6.164346
## 84 4.704327
## 76 7.671213
## 18 6.912847
## 15 7.292981
## 83 6.079980
## 16 6.941989
## 58 7.283649
## 39 7.198613
## 9 6.976674
## 87 4.729825
## 95 7.458713
## 33 5.892642
## 7 5.325194
## 65 5.422130
## 71 8.890115
## 62 7.561377
## 70 6.356740
## 10 6.714932
## 25 6.115740
## 3 8.810415
## 85 7.174656
## 34 6.904078
## 100 6.369044
## 12 6.142272
## 82 7.266993
## 55 6.875838
## 11 7.138148
## 31 6.104316
## 56 7.636391
## 88 7.237316
## 89 7.027798
## 35 7.153594
## 6 4.973550
## 14 7.491105
## 50 7.842791
## 44 7.794307
## 17 6.294013
## 28 5.721766
## 37 6.800474
## 78 7.413739
## 4 5.338244
## 8 6.115899
## 23 7.413216
## 41 7.252551
## 13 8.353666
## 90 8.421279
## 36 5.006773
## 52 6.680478
## 77 6.592289
## 29 7.099197
## 46 6.778117
## 73 7.150216
## 79 8.973769
## 5 6.879441
## 94 8.911542
##
## , , 11 comps
##
## Satisfaction
## 2 6.517026
## 54 6.066074
## 92 4.332538
## 75 7.760147
## 47 7.060017
## 64 5.582926
## 20 8.750778
## 45 6.527656
## 32 5.883794
## 43 8.336849
## 80 6.695363
## 1 7.919795
## 86 5.768826
## 21 5.140573
## 53 8.123507
## 51 5.874647
## 57 8.498052
## 97 6.340480
## 22 9.607492
## 69 5.707220
## 72 5.735409
## 38 8.665855
## 81 7.666003
## 26 6.699594
## 40 6.326838
## 84 4.952991
## 76 7.349307
## 18 7.056184
## 15 7.180456
## 83 6.012111
## 16 6.863949
## 58 7.325640
## 39 7.066232
## 9 7.104783
## 87 4.637056
## 95 7.617726
## 33 6.081162
## 7 5.350590
## 65 5.544823
## 71 8.823527
## 62 7.423397
## 70 6.258326
## 10 6.648793
## 25 6.009413
## 3 8.846626
## 85 7.333490
## 34 6.779039
## 100 6.397073
## 12 6.001802
## 82 7.231784
## 55 6.785404
## 11 7.060099
## 31 6.127212
## 56 7.895344
## 88 7.451201
## 89 7.033127
## 35 7.126205
## 6 4.950782
## 14 7.556388
## 50 7.824372
## 44 7.791606
## 17 5.997930
## 28 5.707087
## 37 6.753770
## 78 7.383379
## 4 5.476785
## 8 5.988417
## 23 7.340717
## 41 7.357503
## 13 8.342971
## 90 8.352451
## 36 5.137297
## 52 6.609820
## 77 6.252234
## 29 7.157391
## 46 6.731636
## 73 7.309658
## 79 9.152056
## 5 6.899244
## 94 9.064176
Cross-Validation
Modelde gorulmeyen veriler uzerindeki peerformansini mumkun oldugunca objektif ve dogru bir sekilde degerlendirmek icin kullanılan istatistiksel bir yeniden ornekleme yontemidir.
Olusturdumuz PCR modeline Cross-Validation yontemi kullanarak yeni bir model olusturalim;
modelpcr_cv<-pcr(Satisfaction~.,data=trainset,scale=TRUE,validation="CV")
summary(modelpcr_cv)
## Data: X dimension: 80 11
## Y dimension: 80 1
## Fit method: svdpc
## Number of components considered: 11
##
## VALIDATION: RMSEP
## Cross-validated using 10 random segments.
## (Intercept) 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps
## CV 1.249 0.8251 0.8316 0.8538 0.7561 0.7305 0.7212
## adjCV 1.249 0.8199 0.8294 0.8511 0.7519 0.7161 0.7176
## 7 comps 8 comps 9 comps 10 comps 11 comps
## CV 0.7326 0.7216 0.6887 0.6453 0.6263
## adjCV 0.7288 0.7188 0.6791 0.6404 0.6212
##
## TRAINING: % variance explained
## 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps 7 comps
## X 33.40 56.08 71.92 80.47 85.90 91.25 94.50
## Satisfaction 58.98 59.08 59.11 68.54 71.07 71.75 72.01
## 8 comps 9 comps 10 comps 11 comps
## X 96.54 98.05 99.24 100.00
## Satisfaction 73.44 77.64 80.27 81.45
Yukaridaki kod ciktisinda random_state ler icin accuracy skorlaini goruyoruz. Farkli train-test bolumleri sonucunda farkli accuarty degerleri elde edildigini ama bunlarin birbirine oldukca yakin oldugunu gozlemliyoruz. Accuracy degeri bizwe dogru tahmin etme oranini verir. Buyuk olmasini isteriz.
Her bir bilesen icin, MSEP hata metrigine ait degerler grafikteki gibidir.
Burada biz modelpcr ile modelpcr_cv modelini karsilastirarak nihai modele ulasacagiz.
Kolay yorumlayabilmek adina metrikleri kisaca tanimlayacak olursak ; RMSE= Gercek degerler ile tahmin edilen degerler arasindaki farkin ortalama buyuklugunu olcer. Rsquared = Gercek deger ile modelin tahminleri arasindaki uyumun bir olcusudur. MAE= Gercek gegerler ile tahmin edilen degerler arasindaki hatalarin mutlak degerlerinin ortalamasidir.
library(caret)
ozet_<-defaultSummary(data.frame(obs=trainset$Satisfaction,pred=as.vector(modelpcr_cv$fitted.values)))
ozet_
## RMSE Rsquared MAE
## 0.6721901 0.7030421 0.5373387
ozet_1<-defaultSummary(data.frame(obs=trainset$Satisfaction,pred=as.vector(modelpcr$fitted.values)))
ozet_1
## RMSE Rsquared MAE
## 0.6721901 0.7030421 0.5373387
Degerleri inceledigimizde modelpcr_cv modelinin daha iyi sonuc verdigini goruyoruz. Cunku bizim istedigimiz RMSE ve MAE degerlerinin kucuk Rsqared degeriinin ise buyuk olmasidir.
Burun bilesenler icin gozlem degerlerini hesaplayalim (tahmin edilen degerler);
predict(modelpcr_cv,test_x)
## , , 1 comps
##
## Satisfaction
## 19 7.113184
## 24 7.862512
## 27 7.732496
## 30 6.211028
## 42 6.913414
## 48 8.421477
## 49 7.545170
## 59 6.722577
## 60 7.429298
## 61 7.867130
## 63 6.438612
## 66 7.573730
## 67 7.499744
## 68 6.880030
## 74 7.601646
## 91 6.956398
## 93 7.491082
## 96 7.107793
## 98 5.415395
## 99 7.320597
##
## , , 2 comps
##
## Satisfaction
## 19 7.143612
## 24 7.812834
## 27 7.666396
## 30 6.243233
## 42 6.916137
## 48 8.458070
## 49 7.550191
## 59 6.690149
## 60 7.356242
## 61 7.787114
## 63 6.444094
## 66 7.627984
## 67 7.483911
## 68 6.895005
## 74 7.592413
## 91 6.936809
## 93 7.472121
## 96 7.110596
## 98 5.373603
## 99 7.374836
##
## , , 3 comps
##
## Satisfaction
## 19 7.156690
## 24 7.849796
## 27 7.661060
## 30 6.266125
## 42 6.937565
## 48 8.450323
## 49 7.562508
## 59 6.677577
## 60 7.362284
## 61 7.772868
## 63 6.460224
## 66 7.649067
## 67 7.455360
## 68 6.903352
## 74 7.561970
## 91 6.906692
## 93 7.481722
## 96 7.107852
## 98 5.396947
## 99 7.359354
##
## , , 4 comps
##
## Satisfaction
## 19 6.362832
## 24 7.353931
## 27 7.488897
## 30 6.473324
## 42 7.199392
## 48 7.556705
## 49 8.152949
## 59 7.582314
## 60 7.105322
## 61 7.390001
## 63 7.030081
## 66 7.228290
## 67 6.554350
## 68 6.567889
## 74 8.231153
## 91 7.166545
## 93 7.784815
## 96 7.229923
## 98 5.982967
## 99 7.714662
##
## , , 5 comps
##
## Satisfaction
## 19 6.349957
## 24 7.529839
## 27 7.279172
## 30 6.257321
## 42 7.464188
## 48 7.223124
## 49 8.371376
## 59 7.596507
## 60 7.207531
## 61 7.449132
## 63 7.003452
## 66 6.966470
## 67 6.600980
## 68 6.291570
## 74 8.206190
## 91 7.228499
## 93 7.931823
## 96 7.749064
## 98 5.990461
## 99 7.819898
##
## , , 6 comps
##
## Satisfaction
## 19 6.337021
## 24 7.586213
## 27 7.295969
## 30 6.326214
## 42 7.578412
## 48 7.292270
## 49 8.410495
## 59 7.543597
## 60 7.326004
## 61 7.441489
## 63 6.990975
## 66 6.921829
## 67 6.464558
## 68 6.124627
## 74 8.350881
## 91 7.362005
## 93 7.967078
## 96 7.656938
## 98 5.926995
## 99 7.824209
##
## , , 7 comps
##
## Satisfaction
## 19 6.320622
## 24 7.737731
## 27 7.325074
## 30 6.425876
## 42 7.533101
## 48 7.351482
## 49 8.412816
## 59 7.628490
## 60 7.497911
## 61 7.482761
## 63 7.130578
## 66 6.859565
## 67 6.516540
## 68 6.152821
## 74 8.298821
## 91 7.367045
## 93 7.864512
## 96 7.759428
## 98 5.929915
## 99 7.832001
##
## , , 8 comps
##
## Satisfaction
## 19 6.460978
## 24 7.338230
## 27 7.141818
## 30 6.165415
## 42 7.586968
## 48 7.420091
## 49 8.329255
## 59 7.319435
## 60 7.689454
## 61 7.398180
## 63 7.092462
## 66 6.930845
## 67 6.580755
## 68 6.137275
## 74 8.211655
## 91 7.021028
## 93 7.498836
## 96 7.670867
## 98 5.590125
## 99 7.877711
##
## , , 9 comps
##
## Satisfaction
## 19 6.516152
## 24 8.288041
## 27 6.820006
## 30 5.943559
## 42 7.249559
## 48 7.338771
## 49 9.052996
## 59 7.151253
## 60 7.428718
## 61 7.014249
## 63 6.808670
## 66 7.214862
## 67 6.523346
## 68 5.988541
## 74 8.560279
## 91 7.110056
## 93 7.332879
## 96 7.300299
## 98 5.091411
## 99 7.801265
##
## , , 10 comps
##
## Satisfaction
## 19 6.875447
## 24 8.102153
## 27 6.997456
## 30 6.077623
## 42 7.506527
## 48 7.614192
## 49 9.081032
## 59 6.848855
## 60 7.298391
## 61 7.228557
## 63 6.497711
## 66 7.315270
## 67 6.390544
## 68 6.055032
## 74 9.093438
## 91 7.315528
## 93 7.426233
## 96 7.299522
## 98 4.917956
## 99 7.967114
##
## , , 11 comps
##
## Satisfaction
## 19 7.099400
## 24 8.432045
## 27 6.938620
## 30 5.990686
## 42 7.512206
## 48 7.704770
## 49 9.404799
## 59 6.269121
## 60 7.330837
## 61 7.148929
## 63 6.672320
## 66 7.169810
## 67 6.174731
## 68 5.885022
## 74 9.166616
## 91 7.409267
## 93 7.504902
## 96 7.371944
## 98 4.979938
## 99 7.982921
Testsetden sadece ilk 5 gozlemin ilk 2 bilesene gore olusturulmus modelden elde edilen tahminleri;
predict(modelpcr_cv,test_x[1:5,],ncomp = 1:2) #testsetden sadeceilk 5 gozlemin ilk 2 bilesene gore olusturulmus modelden elde edilen tahminleri
## , , 1 comps
##
## Satisfaction
## 19 7.113184
## 24 7.862512
## 27 7.732496
## 30 6.211028
## 42 6.913414
##
## , , 2 comps
##
## Satisfaction
## 19 7.143612
## 24 7.812834
## 27 7.666396
## 30 6.243233
## 42 6.916137
Bu predictionlar topluca bir hata metriği ile degerlendirilirse;
library(caret)
testperf<-defaultSummary(data.frame(obs = test_y, pred=as.vector(predict(modelpcr_cv,test_x, ncomp = 1:2))))
testperf
## RMSE Rsquared MAE
## 0.7665706 0.3745319 0.6452308
ozet_
## RMSE Rsquared MAE
## 0.6721901 0.7030421 0.5373387
##Model Tunning
PCR da tune edebilecegimiz parametre sayisi birdir. Optimal Temel bilesen sayisi belirlenmeye calisilir.
ctrl<-trainControl(method = "cv",number = 10) #validasyonda kullanılancak onemli adımlar belirlenir
set.seed(1234)
pcr_opt<-train(train_x,train_y,method = "pcr",trControl = ctrl,
preProc=c("center","scale"))
pcr_opt
## Principal Component Analysis
##
## 80 samples
## 11 predictors
##
## Pre-processing: centered (11), scaled (11)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 72, 72, 71, 72, 72, 72, ...
## Resampling results across tuning parameters:
##
## ncomp RMSE Rsquared MAE
## 1 0.8047135 0.6133528 0.6472494
## 2 0.8090508 0.6151730 0.6544344
## 3 0.8151724 0.6073951 0.6579271
##
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was ncomp = 1.
Nihai olarak 3 tane bilesen denenmis ve bunlar arasinda 1 tane bilesen olmasi durumunun en iyi durum oldugu belirtilmistir. Bunuda RMSE degerinde en dusuk olan bilesen durumuna bakarak karar vermektedir.
Bu sonuclar incelendiginde daha iyi RMSE sonuclari elde edilemeyecegi gorulmektedir. Bunu detaylandirirsak;
ctrl<-trainControl(method = "cv",number = 10) #validasyonda kullanılancak onemli adımlar belirlenir
set.seed(1234)
pcr_opt<-train(train_x,train_y,method = "pcr",trControl = ctrl,
tuneLength = 20,
preProc=c("center","scale"))
pcr_opt
## Principal Component Analysis
##
## 80 samples
## 11 predictors
##
## Pre-processing: centered (11), scaled (11)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 72, 72, 71, 72, 72, 72, ...
## Resampling results across tuning parameters:
##
## ncomp RMSE Rsquared MAE
## 1 0.8047135 0.6133528 0.6472494
## 2 0.8090508 0.6151730 0.6544344
## 3 0.8151724 0.6073951 0.6579271
## 4 0.7022679 0.6916837 0.5880000
## 5 0.7006117 0.6966629 0.5900553
## 6 0.6774046 0.7265402 0.5523550
## 7 0.6873380 0.7185125 0.5638133
## 8 0.6775728 0.7320354 0.5487216
## 9 0.6345869 0.7690780 0.5177718
## 10 0.6028245 0.8001219 0.4874342
##
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was ncomp = 10.
Bu sonucla da nihai olarak 9 temel bilesen ile daha dusuk hata metrikleri elde edilmistir. Thefinalvalueusedforthemodelwasncomp=9.
plot(pcr_opt)
Modelin son hali şu şekildedir;
pcr_opt$finalModel # tune edilmismodelin nihai hali
## Principal component regression, fitted with the singular value decomposition algorithm.
## Call:
## pcr(formula = .outcome ~ ., ncomp = ncomp, data = dat)
Tahminleri elde etme Tune edilmis modelden yararlanarak tahminleri elde edersek;
testperf_tune<-defaultSummary(data.frame(obs=test_y, pred=as.vector(predict(pcr_opt,test_x))))
testperf_tune
## RMSE Rsquared MAE
## 0.5130632 0.7424527 0.3628280