Skip to content

Commit

Permalink
Added support for the 'negbin' model type
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Aug 1, 2024
1 parent 3a505e6 commit 0c08352
Show file tree
Hide file tree
Showing 8 changed files with 2,342 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Java library and command-line application for converting [R](https://www.r-proje
* `party` - CHi-squared Automated Interaction Detection (CHAID) classification
* [`earth`](https://cran.r-project.org/package=earth) package:
* `earth` - Multivariate Adaptive Regression Spline (MARS) regression
* [`elmNNRcpp`](https://CRAN.R-project.org/package=elmNNRcpp) package:
* [`elmNNRcpp`](https://cran.r-project.org/package=elmNNRcpp) package:
* `elm` - Extreme Learning Machine (ELM) regression
* [`evtree`](https://cran.r-project.org/package=evtree) package:
* `party` - Evolutionary Learning of Trees (EvTree) regression and classification
Expand All @@ -52,6 +52,8 @@ Java library and command-line application for converting [R](https://www.r-proje
* `iForest` - Isolation Forest (IF) anomaly detection
* [`lightgbm`](https://cran.r-project.org/package=lightgbm) package:
* `lgb.Booster` - LightGBM regression and classification.
* [`MASS`](https://cran.r-project.org/package=MASS) package:
* `negbin` - Generalized Linear Model (GLM) regression.
* [`mlr`](https://cran.r-project.org/package=mlr) package:
* `WrappedModel` - Selected JPMML-R model types.
* [`neuralnet`](https://cran.r-project.org/package=neuralnet) package:
Expand Down
26 changes: 26 additions & 0 deletions pmml-rexp/src/main/java/org/jpmml/rexp/NegbinConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2024 Villu Ruusmann
*
* This file is part of JPMML-R
*
* JPMML-R is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JPMML-R is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with JPMML-R. If not, see <http://www.gnu.org/licenses/>.
*/
package org.jpmml.rexp;

public class NegbinConverter extends GLMConverter {

public NegbinConverter(RGenericVector negbin){
super(negbin);
}
}
1 change: 1 addition & 0 deletions pmml-rexp/src/main/resources/META-INF/r2pmml.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ multinom = org.jpmml.rexp.MultinomConverter
multnet = org.jpmml.rexp.MultNetConverter
mvr = org.jpmml.rexp.MVRConverter
naiveBayes = org.jpmml.rexp.NaiveBayesConverter
negbin = org.jpmml.rexp.NegbinConverter
nn = org.jpmml.rexp.NNConverter
nnet.formula = org.jpmml.rexp.NNetConverter
ols = org.jpmml.rexp.OLSConverter
Expand Down
17 changes: 17 additions & 0 deletions pmml-rexp/src/test/R/negbin.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
library("MASS")

source("util.R")

visit = loadVisitCsv("Visit")

generateNegbinFormulaVisit = function(){
visit.negbin = glm.nb(docvis ~ ., data = visit)
print(visit.negbin)

docvis = predict(visit.negbin, newdata = visit, type = "response")

storeRds(visit.negbin, "NegbinFormulaVisit")
storeCsv(data.frame("docvis" = docvis), "NegbinFormulaVisit")
}

generateNegbinFormulaVisit()
2 changes: 1 addition & 1 deletion pmml-rexp/src/test/R/version.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ print(paste(R.version$major, R.version$minor, sep = "."))
latest_versions = available.packages()

print("R package versions:")
packages = c("ada", "adabag", "apollo", "caret", "caretEnsemble", "CHAID", "e1071", "earth", "elmNNRcpp", "evtree", "gbm", "glmnet", "IsolationForest", "mlr", "neuralnet", "nnet", "party", "partykit", "pls", "randomForest", "ranger", "rattle", "recipes", "rms", "rpart", "statmod", "xgboost")
packages = c("ada", "adabag", "apollo", "caret", "caretEnsemble", "CHAID", "e1071", "earth", "elmNNRcpp", "evtree", "gbm", "glmnet", "IsolationForest", "MASS", "mlr", "neuralnet", "nnet", "party", "partykit", "pls", "randomForest", "ranger", "rattle", "recipes", "rms", "rpart", "statmod", "xgboost")
for(package in packages){
version = tryCatch({
packageVersion(package)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Villu Ruusmann
*
* This file is part of JPMML-R
*
* JPMML-R is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JPMML-R is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with JPMML-R. If not, see <http://www.gnu.org/licenses/>.
*/
package org.jpmml.rexp.testing;

import org.jpmml.converter.testing.Datasets;
import org.junit.Test;

public class NegbinConverterTest extends RExpEncoderBatchTest implements Datasets {

@Test
public void evaluateFormulaVisit() throws Exception {
evaluate("NegbinFormula", VISIT);
}
}
Loading

0 comments on commit 0c08352

Please sign in to comment.