Description Usage Arguments Examples
Build a Java class of a GLM model, creating a predict() Java method.
the dataset through shiny (more control than
expore_all_data()
provides).
1 2 | buildGLMJavaClass(modCoefs, modType = "gaussian", filePath, package,
threshold = 0.5, addMainMeth = FALSE)
|
modCoefs |
A data.frame with coefficient names and values. The intercept must be passed as containing case sensitive text "Intercept". E.g. (Intercept) as from glmnet is fine. |
modType |
A string of the family distribution (gaussian, poisson, binomial, multinomial). |
filePath |
Where to write the Java class too. |
package |
The name of the Java class package. |
threshold |
For binary classification, the probability threshold to use (default=0.5). |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | data(iris)
library(glmnet)
### Fit Gaussian model ###
x = as.matrix(iris[,2:4])
y = iris[,1]
normFit=cv.glmnet(x,y, family="gaussian")
normCoefs = as.data.frame(t(as.matrix(coef(normFit, s="lambda.min"))))
buildGLMJavaClass(modCoefs=normCoefs, modType="gaussian",
filePath="./NormalMod.java", package="glm2java", addMainMeth=TRUE)
### Fit Poisson model ###
poisFit=cv.glmnet(x,y, family="poisson")
poisCoefs = as.data.frame(t(as.matrix(coef(poisFit, s="lambda.min"))))
## With the default naive threshold (0.5)
buildGLMJavaClass(modCoefs=poisCoefs, modType="poisson",
filePath="./PoissonMod.java", package="glm2java", addMainMeth=TRUE)
### Fit binomial model ###
x = as.matrix(iris[,1:4])
y = iris[,5]
y = as.character(y)
y[y=="virginica"]="versicolor"
y=as.factor(y)
# With the default naive threshold (0.5)
buildGLMJavaClass(modCoefs=binCoefs, modType="binomial",
filePath="./BinaryMod.java", package="glm2java", addMainMeth=TRUE)
# With a user provided threshold (0.2)
buildGLMJavaClass(modCoefs=binCoefs, modType="binomial",
filePath="./BinaryMod_2.java", package="glm2java", threshold=0.2, addMainMeth=TRUE)
### Fit multinomial model ###
x = as.matrix(iris[,1:4])
y = iris[,5]
multiFit = cv.glmnet(x,y, family="multinomial" )
multiCoefs = lapply(coef(multiFit, s="lambda.min"),
FUN=function (x) as.data.frame(t(as.matrix(x))))
buildGLMJavaClass(modCoefs=multiCoefs, modType="multinomial",
filePath="./MultinomialMod.java", package="glm2java", addMainMeth=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.