---
title: RuleFit export examples
description: Learn how to generate source code for a model as a Python module or Java class, and use DataRobot Prime with Python or Java.
---

# RuleFit export examples {: #ruleFit-export-examples }

You can generate source code for the model as a [Python module](#using-rulefit-with-python) or [Java class](#using-rulefit-with-java).

## Using RuleFit with Python {: #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:

* &lt;prediction_file> specifies the downloaded Python code version of the RuleFit model.
* &lt;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 <a target="_blank" href="https://docs.python.org/3/library/codecs#standard-encodings">Python-supported standards chart</a> for possible alternative entries.
* &lt;data_file> specifies a .csv file (your dataset); columns must correspond to the feature set used to generate the model.
* &lt;output_file> specifies the filename where DataRobot writes the results.

### Python Example {: #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 {: #using-rulefit-with-java }

To run DataRobot Prime with Java:

* You must use the <a target="_blank" href="https://www.oracle.com/technetwork/java/javase/downloads/index.html">JDK</a> for Java version 1.7.x or later.
* Do not rename any of the classes in the file.
* You must include the <a target="_blank" href="https://commons.apache.org/proper/commons-csv/">Apache commons CSV library</a> 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:

* &lt;data_file> specifies a .csv file (your dataset); columns must correspond to the feature set used to generate the RuleFit model.
* &lt;output_file> specifies the filename where DataRobot writes the results.

### Java Example {: #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](#python-example) for details on the format of input / output data.