R
You can install the SigOptR
package directly from CRAN, or you can use the devtools
package to grab the latest version from GitHub.
CRAN
Install the SigOptR
package directly from CRAN:
install.packages("SigOptR", repos = "http://cran.us.r-project.org")
library(SigOptR)
Latest Version from GitHub
Install the latest SigOptR
package from GitHub by using devtools
:
install.packages("devtools", repos = "http://cran.us.r-project.org")
library(devtools)
install_github("sigopt/SigOptR")
library(SigOptR)
Run Some Code
Now, you can run SigOpt's Optimization Loop.
First, setup the experiment:
install.packages("devtools", repos = "http://cran.us.r-project.org")
library(devtools)
install_github("sigopt/SigOptR")
library(SigOptR)
Sys.setenv(SIGOPT_API_TOKEN=SIGOPT_API_TOKEN)
experiment <- create_experiment(list(
name="Franke Optimization (R)",
# Define which parameters you would like to tune
parameters=list(
list(name="x", type="double", bounds=list(min=0.0, max=1.0)),
list(name="y", type="double", bounds=list(min=0.0, max=1.0))
),
metrics=list(
list(name="function_value")
),
parallel_bandwidth=1,
# Define an Observation Budget for your experiment
observation_budget=30,
project="sigopt-examples"
))
print(paste(
"Created experiment: https://app.sigopt.com/experiment",
experiment$id,
sep="/"
))
Then, run the optimization loop itself:
# Evaluate your model with the suggested parameter assignments
# Franke function - http://www.sfu.ca/~ssurjano/franke2d.html
evaluate_model <- function(assignments) {
return(franke(assignments$x, assignments$y))
}
# Run the Optimization Loop until the Observation Budget is exhausted
while(experiment$progress$observation_count < experiment$observation_budget) {
suggestion <- create_suggestion(experiment$id)
value <- evaluate_model(suggestion$assignments)
create_observation(experiment$id, list(
suggestion=suggestion$id,
value=value
))
# Update experiment object
experiment <- fetch_experiment(experiment$id)
}
Run More Code: Tune a Random Forest
Learn how to Tune a Random Forest using SigOpt's R API Client. This simple example uses an open source machine learning library and can be extended to tune the hyperparameters of any machine learning model.
More Examples
To see more examples of how to use Sigopt and R to tune machine learning models and more, check out our Machine Learning Templates page or clone our GitHub examples repository:
git clone https://github.com/sigopt/sigopt-examples.git