如何用插入符号绘制预测机器学习?
How to plot predictive machine learning with caret?
我想绘制 knn 回归图,是否有绘制机器学习回归图的函数或最佳方法?
一旦我选择了最好的模型,我应该绘制什么?
非常感谢您的帮助!
df <- mtcars
library(caret)
set.seed(123)
trainRowNumbers <- createDataPartition(df$mpg, p=0.8, list=FALSE)
trainData <- df[trainRowNumbers,]
testData <- df[-trainRowNumbers,]
y = trainData$mpg
preProcess_range_model <- preProcess(trainData, method='range')
trainData <- predict(preProcess_range_model, newdata = trainData)
trainData$mpg <- y
set.seed(123)
options(warn=-1)
subsets <- c(2:5, 8, 9, 12)
ctrl <- rfeControl(functions = rfFuncs,
method = "repeatedcv",
repeats = 5,
verbose = FALSE)
lmProfile <- rfe(x=trainData[, 2:11], y=trainData$mpg,
sizes = subsets,
rfeControl = ctrl)
lmProfile
control <- trainControl(method = "cv", number = 15)
set.seed(123)
model_lm = train(mpg ~ wt+hp+disp+cyl, data=trainData, method='lm', trControl = control)
model_lm
linear.predict <- predict(model_lm, testData)
linear.predict
postResample(linear.predict, testData$mpg)
model_knn = train(mpg ~ wt+hp+disp+cyl, data=trainData, method='knn', trControl = control)
model_knn
knn.predict <- predict(model_knn, testData)
knn.predict
postResample(knn.predict, testData$mpg)
你可以画出两件事如下
#To show the changes in RMSE with changing tuning parameters
plot(model_knn)
#The observed vs. predicted plot
library("lattice")
library(mosaic)
df1 <- data.frame(Observed=testData$mpg, Predicted=linear.predict)
xyplot(Predicted ~ Observed, data = df1, pch = 19, panel=panel.lmbands,
band.lty = c(conf =2, pred = 1))
我想绘制 knn 回归图,是否有绘制机器学习回归图的函数或最佳方法? 一旦我选择了最好的模型,我应该绘制什么?
非常感谢您的帮助!
df <- mtcars
library(caret)
set.seed(123)
trainRowNumbers <- createDataPartition(df$mpg, p=0.8, list=FALSE)
trainData <- df[trainRowNumbers,]
testData <- df[-trainRowNumbers,]
y = trainData$mpg
preProcess_range_model <- preProcess(trainData, method='range')
trainData <- predict(preProcess_range_model, newdata = trainData)
trainData$mpg <- y
set.seed(123)
options(warn=-1)
subsets <- c(2:5, 8, 9, 12)
ctrl <- rfeControl(functions = rfFuncs,
method = "repeatedcv",
repeats = 5,
verbose = FALSE)
lmProfile <- rfe(x=trainData[, 2:11], y=trainData$mpg,
sizes = subsets,
rfeControl = ctrl)
lmProfile
control <- trainControl(method = "cv", number = 15)
set.seed(123)
model_lm = train(mpg ~ wt+hp+disp+cyl, data=trainData, method='lm', trControl = control)
model_lm
linear.predict <- predict(model_lm, testData)
linear.predict
postResample(linear.predict, testData$mpg)
model_knn = train(mpg ~ wt+hp+disp+cyl, data=trainData, method='knn', trControl = control)
model_knn
knn.predict <- predict(model_knn, testData)
knn.predict
postResample(knn.predict, testData$mpg)
你可以画出两件事如下
#To show the changes in RMSE with changing tuning parameters
plot(model_knn)
#The observed vs. predicted plot
library("lattice")
library(mosaic)
df1 <- data.frame(Observed=testData$mpg, Predicted=linear.predict)
xyplot(Predicted ~ Observed, data = df1, pch = 19, panel=panel.lmbands,
band.lty = c(conf =2, pred = 1))