[英]Use tested machine learning model on new unlabeled single observation or dataset?
How can I use a trained and tested algorithm (eg. machine learning classifier) after being saved, on a new observation/dataset, whose I do not know the class (eg. ill vs healthy) based on predictors used for model training?基于用于模型训练的预测变量,我如何在新的观察/数据集上保存经过训练和测试的算法(例如机器学习分类器),我不知道该类(例如生病与健康)的类别? I use caret but can't find any lines of code for this.我使用插入符号,但找不到任何代码行。 many thanks非常感谢
After training and testing any machine learning model you can save the model as .rds
file and call it as在训练和测试任何机器学习模型后,您可以将模型保存为.rds
文件并将其命名为
#Save the fitted model as .rds file
saveRDS(model_fit, "model.rds")
my_model <- readRDS("model.rds")
Creating a new observation from the same dataset or you can use a new dataset also从相同的数据集创建新的观察,或者您也可以使用新的数据集
new_obs <- iris[100,] #I am using default iris dataset, 100 no sample
Prediction on the new observation对新观测的预测
predicted_new <- predict(my_model, new_obs)
confusionMatrix(reference = new_obs$Species, data = predicted_new)
table(new_obs$Species, predicted_new)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.