|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Calling a stored model within the predict() functionHi all,
First of all, I'm a novice R user (less that a week), so perhaps my code isn't very efficient. Using the MBoost package I created a model: model <- gamboost(fpfm,data=SampleClusterData,baselearner="bbs") # Creating a model save(model,file="model.RData") # Saving a model After this, during a new R session, I want to deploy this model: setwd("Q:/Program Files/R/library/mboost/data") NewData <- read.table("NewData.txt",header=TRUE,sep=",") #Calling a new data set setwd("Q:/Program Files/R/library/mboost") model <- load("model.rdata") # Loading the model This won't work. When I check the content of the 'model' object, the only screen output I see is : "model [1]model" ...and that the actual file size from 'model.rdata' is exactly 4,100 kb (is this a limit?!) Then I try to call this model object with the predict() function: CRPredict <- predict(model, newdata= NewData) # Make the predictions This results in the following error message: "Error in UseMethod("predict") : no applicable method for "predict" " Is there a correct way to store and call a model or is it only possible to create & deploy a model during the same R session? Thanks! Jim |
|
|
Re: Calling a stored model within the predict() functionNo replies yet...
Is my problem explanation unclear? Please let me know, thanks! Jim |
|
|
Re: Calling a stored model within the predict() functionRead the last line of every message to r-help.
On Sat, Apr 26, 2008 at 7:14 PM, Jim_S <virtualreal@...> wrote: > > Hi all, > > First of all, I'm a novice R user (less that a week), so perhaps my code > isn't very efficient. > > Using the MBoost package I created a model using the following command and > saved it to a file for later use: > > model <- gamboost(fpfm,data=SampleClusterData,baselearner="bbs") # Creating > a model > save(model,file="model.RData") # Saving a model > > > After this, during a new R session, I want to deploy this model: > > setwd("Q:/Program Files/R/library/mboost/data") > NewData <- read.table("NewData.txt",header=TRUE,sep=,",") #Calling a new > data set > setwd("Q:/Program Files/R/library/mboost") > model <- load("model.rdata") # Loading the model > > This won't work. When I check the content of the 'model' object, the only > screen output I see is : > > "model > [1]model" > > ...and that the actual file size from 'model.rdata' is exactly 4,100 kb (is > this a limit?!) > > > Then I try to call this model object with the predict() function: > > CRPredict <- predict(model, newdata= SampleClusterData) # Make the > predictions > > This results in the following error message: > > "Error in UseMethod("predict") : no applicable method for "predict" " > > Is the a correct way to store and call a model or is it only possible to > create & deploy a model during the same R session? > > Thanks! > > Jim > > > > -- > View this message in context: http://www.nabble.com/Calling-a-stored-model-within-the-predict%28%29-function-tp16918111p16918111.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@... mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@... mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
|
Re: Calling a stored model within the predict() functionAfter a short discussion I decided to post my compete code and data set. I hope this makes sense.
Thanks, Jim # READ DATA # ========= SampleCluster.txt setwd("C:/Program Files/R/library/mboost/data") SampleClusterData <- read.table("SampleCluster.txt",header=TRUE,sep=",") indep <- names(SampleClusterData) [-98]# INPUTS # GENERATE FORMULA # =============== modelformula <- as.formula(paste("CR ~",paste(indep,collapse="+"))) # CREATE MODEL # =========== setwd("C:/Program Files/R/library/mboost") library(mboost) # Additive Model for same Variables # ========================= model <- gamboost(modelformula,data=SampleClusterData,baselearner="bbs") # STORE AND CALL MODEL FILE # ====================== save(model,file="model.RData") # STORE MODEL # ... # New R-Session setwd("C:/Program Files/R/library/mboost") model <- load("model.rdata") # PREDICT WITH A STORED MODEL OBJECT # ============================== Prediction <- predict(model, newdata= SampleClusterData) # WRITE PREDICTION TO FILE # ===================== write.table(Prediction,file="C:/Prediction.txt") |
|
|
Re: Calling a stored model within the predict() functionPlease read ?load more carefully.
Also, don't send multiple copies and completely ignore the posting guide -- people who do reduce dramatically their chances of getting a reply. On Sun, 27 Apr 2008, Jim_S wrote: > After a short discussion I decided to post my compete code and data set. I > hope this makes sence. > > Thanks, > > Jim > > > > # READ DATA > # ========= > http://www.nabble.com/file/p16923910/SampleCluster.txt SampleCluster.txt > setwd("C:/Program Files/R/library/mboost/data") > SampleClusterData <- read.table("SampleCluster.txt",header=TRUE,sep=",") > indep <- names(SampleClusterData) [-98]# INPUTS > > # GENERATE FORMULA > # =============== > modelformula <- as.formula(paste("CR ~",paste(indep,collapse="+"))) > > # CREATE MODEL > # =========== > setwd("C:/Program Files/R/library/mboost") > library(mboost) > > # Additive Model for same Variables > # ========================= > model <- gamboost(modelformula,data=SampleClusterData,baselearner="bbs") > > # STORE AND CALL MODEL FILE > # ====================== > save(model,file="model.RData") # STORE MODEL > # ... > # New R-Session > setwd("C:/Program Files/R/library/mboost") > model <- load("model.rdata") > > > # PREDICT WITH A STORED MODEL OBJECT > # ============================== > Prediction <- predict(model, newdata= SampleClusterData) > > # WRITE PREDICTION TO FILE > # ===================== > write.table(Prediction,file="C:/Prediction.txt") > > > > -- > View this message in context: http://www.nabble.com/Calling-a-stored-model-within-the-predict%28%29-function-tp16918111p16923910.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@... mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Brian D. Ripley, ripley@... Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ R-help@... mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
| Free embeddable forum powered by Nabble | Forum Help |