6.1
#the theory of IR spectroscopy holds that unique molecular structures absorb IR frequencies differently.
library(caret)
data(tecator)
absorp
#absorbance values 215*100
endpoints
#percent of moisture, fat, and protein 215*3
#first way
corthresh=0.99
toohigh=findCorrelation(absorp, corthresh)
corrpred=names(absorp)[toohigh]
absorpeffective=absorp[, -toohigh]
absorpeffective
#second way
correlations=cor(absorp)
dim(correlations)
library(corrplot)
corrplot(correlations, order="hclust")
highcorr=findCorrelation(correlations, cutoff=0.8)
length(highcorr)
absorpeffective=absorp[, -highcorr]
absorpeffective
6.2
library(AppliedPredictiveModeling)
data(permeability)
library(caret)
lowfrequencies=nearZeroVar(fingerprints, freqCut = 20, uniqueCut = 10)
fingerfiltered=fingerprints[, -lowfrequencies]
fingerfiltered
ncol(fingerfiltered)
colnames(fingerfiltered)
#binary predictors decreases from 1107 to 413
trainfinger=fingerfiltered[sample(1:165, 132, replace=FALSE), ]
dim(trainfinger)
trainfinger
#X1=fingerfiltered[ ,1]
#X1
#trainX1=sample(X1, 132, replace = FALSE)
#trainX1
#trainfinger=fingerfiltered[trainX1, ]
#trainfinger
a=c(121, 149, 114, 40, 104, 45, 153, 26, 66, 162, 15, 128, 81, 102, 62, 127, 110, 52, 140, 95, 6, 86, 60, 11, 75,
135, 99, 77, 34, 106, 89, 112, 87, 64, 65, 50, 59, 105, 118, 19, 94, 165, 120, 43, 48, 115, 13, 111, 41, 151,
116, 82, 46, 18, 38, 69, 7, 92, 23, 58, 155, 137, 132, 27, 131, 49, 93, 85, 36, 31, 79, 122, 30, 9, 145, 63,
143, 80, 152, 159, 134, 67, 126, 3, 70, 55, 141, 53, 101, 28, 139, 125, 109, 14, 42, 78, 147, 158, 54, 4, 117,
107, 150, 57, 119, 103, 156, 160, 146, 47, 29, 76, 164, 83, 73, 154, 72, 37, 124, 51, 24, 133, 22, 17, 98, 1,
97, 157, 148, 123, 21, 130)
testfinger=fingerfiltered[-a, ]
testfinger
(I do not know how to delete a random submatrix from a matrix and obtain the remaining one as the other matrix, I spent hours searching online but I cannot find it. I will try to solve it because it is important to my research.)
Tomorrow, I will try to figure out the problem and go on doing exercises of Chapter 6.
No comments:
Post a Comment