RuleFit export examples¶
You can generate source code for the model as a Python module or Java class.
Using RuleFit with Python¶
Using RuleFit with Python requires:
- Python (Recommended: 3.7)
- Numpy (Recommended: 1.16)
- Pandas < 1.0 (Recommended: 0.23)
To make predictions with a DataRobot Prime model, run the exported Python script file using the following command:
python <prediction_file> --encoding=<encoding> <data_file> <output_file>
Where:
- <prediction_file> specifies the downloaded Python code version of the RuleFit model.
- <encoding> (optional) specifies the encoding of the dataset you are going to make predictions with. RuleFit defaults to UTF-8 if not otherwise specified. See the "Codecs" column of the Python-supported standards chart for possible alternative entries.
- <data_file> specifies a .csv file (your dataset); columns must correspond to the feature set used to generate the model.
- <output_file> specifies the filename where DataRobot writes the results.
Python Example¶
In the following example, rulefit.py
is a Python script containing a RuleFit model trained on the following dataset:
race,gender,age,readmitted
Caucasian,Female,[50-60),0
Caucasian,Male,[50-60),0
Caucasian,Female,[80-90),1
The following command produces predictions for the data in data.csv
and outputs the results to results.csv
.
python rulefit.py data.csv results.csv
The file data.csv
is a .csv file that looks like this:
race,gender,age
Hispanic,Male,[40-50)
Caucasian,Male,[80-90)
AfricanAmerican,Male,[60-70)
The results in results.csv
look like this:
Index,Prediction
0,0.438665626555
1,0.611403738867
2,0.269324648106
Using RuleFit with Java¶
To run DataRobot Prime with Java:
- You must use the JDK for Java version 1.7.x or later.
- Do not rename any of the classes in the file.
- You must include the Apache commons CSV library version 1.1 or later to be able to run the code.
- You must rename the exported code Java file to
Prediction.java
.
Compile the Java file using the following command:
javac -cp ./:./commons-csv-1.1.jar Prediction.java -d ./ -encoding 'UTF-8'
Execute the compiled Java class using the following command:
java -cp ./:./commons-csv-1.1.jar Prediction <data file> <output file>
Where:
- <data_file> specifies a .csv file (your dataset); columns must correspond to the feature set used to generate the RuleFit model.
- <output_file> specifies the filename where DataRobot writes the results.
Java Example¶
The following example generates predictions for data.csv
and writes them to results.csv
:
javac -cp ./:./commons-csv-1.1.jar Prediction.java -d ./ -encoding 'UTF-8'
java -cp ./:./commons-csv-1.1.jar Prediction data.csv results.csv
See the Python example for details on the format of input / output data.