3.5 About Using Third-Party Packages on the Client
In Oracle Machine Learning for R, if you want to use functions from an open source R package from the Comprehensive R Archive Network (CRAN) or other third-party R packages, then you would generally do so in the context of embedded R execution.
Using embedded R execution, you can take advantage of the likely greater amount of memory on the database server.
However, if you want to use a third-party package function in your local R session on data from an Oracle database table, you must use the ore.pull
function to get the data from an ore.frame
object to your local session as a data.frame
object. This is the same as using open source R except that you can extract the data from the database without needing the help of a DBA.
When pulling data from a database table to a local data.frame
, you are limited to using the amount of data that can fit into the memory of your local machine. On your local machine, you do not have the benefits provided by embedded R execution.
Note:
While using the OML notebooks on ADB, the Conda environments are stored in an Object Storage . For more information, see Administrative Tasks for Creating and Saving a Conda Environment.To use a third-party package, you must install it on your system and load it in your R session.
For an example that uses the kernlab
package, see Example 2-15.
Example 3-3 Downloading, Installing, and Loading a Third-Party Package on the Client
This example demonstrates downloading, installing, and loading the CRAN package kernlab
. The kernlab
package contains kernel-based machine learning methods. The example invokes the install.packages
function to download and install the package. It then invokes the library
function to load the package.
install.packages("kernlab") library("kernlab")
Listing for This Example
R> install.packages("kernlab") trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.0/kernlab_0.9-19.zip' Content type 'application/zip' length 2029405 bytes (1.9 Mb) opened URL downloaded 1.9 Mb package 'kernlab' successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\oml_user\AppData\Local\Temp\RtmpSKVZql\downloaded_packages R> library("kernlab")
Example 3-4 Using a kernlab Package Function
This example invokes the demo
function to look for example programs in the kernlab
package. Because the package does not have examples, this example then gets help for the ksvm
function. The example invokes example code from the help.
demo(package = "kernlab") help(package = "kernlab", ksvm) data(spam) index <- sample(1:dim(spam)[1]) spamtrain <- spam[index[1:floor(dim(spam)[1]/2)], ] spamtest <- spam[index[((ceiling(dim(spam)[1]/2)) + 1):dim(spam)[1]], ] filter <- ksvm(type~.,data=spamtrain,kernel="rbfdot", + kpar=list(sigma=0.05),C=5,cross=3) filter table(mailtype,spamtest[,58])
Listing for This Example
> demo(package = "kernlab") no demos found > help(package = "kernlab", ksvm) # Output not shown. > data(spam) > index <- sample(1:dim(spam)[1]) > spamtrain <- spam[index[1:floor(dim(spam)[1]/2)], ] > spamtest <- spam[index[((ceiling(dim(spam)[1]/2)) + 1):dim(spam)[1]], ] > filter <- ksvm(type~.,data=spamtrain,kernel="rbfdot", + kpar=list(sigma=0.05),C=5,cross=3) > filter Support Vector Machine object of class "ksvm" SV type: C-svc (classification) parameter : cost C = 5 Gaussian Radial Basis kernel function. Hyperparameter : sigma = 0.05 Number of Support Vectors : 970 Objective Function Value : -1058.218 Training error : 0.018261 Cross validation error : 0.08696 > mailtype <- predict(filter,spamtest[,-58]) > table(mailtype,spamtest[,58]) mailtype nonspam spam nonspam 1347 136 spam 45 772
Parent topic: Install third-party packages