if (FALSE) {
### WARNING ###
#The 'tuning' part of the example can take quite some time to run,
#depending on the computational power.
#using the GROAN.KI dataset, we regress on the dataset and predict the first ten phenotypes
phenos = GROAN.KI$yield
phenos[1:10] = NA
#--------- TUNE ---------
#tuning the SVR on a grid of hyperparameters
results.tune = phenoRegressor.SVR(
phenotypes = phenos,
genotypes = GROAN.KI$SNPs,
covariances = NULL,
extraCovariates = NULL,
mode = 'tune',
kernel = 'linear', cost = 10^(-3:+3) #SVR-specific parameters
)
#examining the predictions
plot(GROAN.KI$yield, results.tune$predictions,
main = 'Mode = TUNING\nTrain set (black) and test set (red) regressions',
xlab = 'Original phenotypes', ylab = 'Predicted phenotypes')
points(GROAN.KI$yield[1:10], results.tune$predictions[1:10], pch=16, col='red')
#printing correlations
test.set.correlation = cor(GROAN.KI$yield[1:10], results.tune$predictions[1:10])
train.set.correlation = cor(GROAN.KI$yield[-(1:10)], results.tune$predictions[-(1:10)])
writeLines(paste(
'test-set correlation :', test.set.correlation,
'\ntrain-set correlation:', train.set.correlation
))
#--------- TRAIN ---------
#training the SVR, hyperparameters are given
results.train = phenoRegressor.SVR(
phenotypes = phenos,
genotypes = GROAN.KI$SNPs,
covariances = NULL,
extraCovariates = NULL,
mode = 'train',
kernel = 'linear', cost = 0.01 #SVR-specific parameters
)
#examining the predictions
plot(GROAN.KI$yield, results.train$predictions,
main = 'Mode = TRAIN\nTrain set (black) and test set (red) regressions',
xlab = 'Original phenotypes', ylab = 'Predicted phenotypes')
points(GROAN.KI$yield[1:10], results.train$predictions[1:10], pch=16, col='red')
#printing correlations
test.set.correlation = cor(GROAN.KI$yield[1:10], results.train$predictions[1:10])
train.set.correlation = cor(GROAN.KI$yield[-(1:10)], results.train$predictions[-(1:10)])
writeLines(paste(
'test-set correlation :', test.set.correlation,
'\ntrain-set correlation:', train.set.correlation
))
#--------- RUN ---------
#we recover the trained model from previous run, predictions will be exactly the same
results.run = phenoRegressor.SVR(
phenotypes = phenos,
genotypes = GROAN.KI$SNPs,
covariances = NULL,
extraCovariates = NULL,
mode = 'run',
tuned.model = results.train$extradata
)
#examining the predictions
plot(GROAN.KI$yield, results.run$predictions,
main = 'Mode = RUN\nTrain set (black) and test set (red) regressions',
xlab = 'Original phenotypes', ylab = 'Predicted phenotypes')
points(GROAN.KI$yield[1:10], results.run$predictions[1:10], pch=16, col='red')
#printing correlations
test.set.correlation = cor(GROAN.KI$yield[1:10], results.run$predictions[1:10])
train.set.correlation = cor(GROAN.KI$yield[-(1:10)], results.run$predictions[-(1:10)])
writeLines(paste(
'test-set correlation :', test.set.correlation,
'\ntrain-set correlation:', train.set.correlation
))
}
Run the code above in your browser using DataLab