gpt4 book ai didi

r - R 中的在线机器学习

转载 作者:行者123 更新时间:2023-11-30 08:45:34 26 4
gpt4 key购买 nike

我在 R 插入符中有一个 ensemebel 算法,工作正常,但我想考虑新的传入数据。我想避免使用所有数据(新旧数据)重新学习算法。

library(caret)
data <- iris
model <- train(Species ~.,data=data[1:145,],method="rf",trControl=trainControl(method="boot",number=10))

## now assume that we get data[146,1:4] after we have completed our model and
## after some time we learn what was the correct outcome. I want to include that
## knowledge into existing algorithm.

# I want to avoid the following call because it is too time consuming;
train(Species ~.,data=data[1:146,],method="rf",trControl=trainControl(method="boot",number=10))

我正在寻找类似partial_fit形式的python SGDClassifier或任何其他建议。

谢谢。

编辑:我尝试应用答案的帮助并得到这个:

library(caret)
data <- iris
model <- train(Species ~.,data=data[1:120,],method="rf",trControl=trainControl(method="boot",number=10))
a <- (predict(model,newdata=data[121:150,1:4])==data[121:150,5])
print(a)
previousModel <- model # load previously saved model object
previousModel$trainingData <- data # change training data to new data
newModel <- update(object = previousModel,forceRefit=T)
b <- (predict(newModel,newdata=data[121:150,1:4])==data[121:150,5])
all(a==b)


[1] TRUE FALSE TRUE FALSE TRUE TRUE FALSE FALSE TRUE FALSE TRUE TRUE
[13] TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE
[25] TRUE TRUE TRUE TRUE TRUE TRUE
### prediction is not perfect
[1] TRUE # after including newdata, nothing changes.. why?

最佳答案

我认为只有一个更新训练参数的函数:

previousModel <- readRDS("....xxx.rds")  # load previously saved model object
previousModel$trainingData <- trainData # change training data to new data
newModel <- update(object = previousModel)

关于基于新训练数据的更新,我通过选项 forceRefit 找到了此 train.updateissue and fix,即使没有更改,模型也会更新在TrainingParameters中(代码可见here)。

我希望这对您有所帮助,您可以从那里获取它。

关于r - R 中的在线机器学习,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51943935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com