<jupyter_start><jupyter_text>sklearn-porterRepository: https://github.com/nok/sklearn-porter NuSVCDocumentation: [sklearn.svm.NuSVC](http://scikit-learn.org/stable/modules/generated/sklearn.svm.NuSVC.html)  Loading data:<jupyter_code>from sklearn.datasets import load_iris

iris_data = load_iris()
X = iris_data.data
y = iris_data.target

print(X.shape, y.shape)<jupyter_output>((150, 4), (150,))<jupyter_text>Train classifier:<jupyter_code>from sklearn import svm

clf = svm.NuSVC(gamma=0.001, kernel='rbf', random_state=0)
clf.fit(X, y)<jupyter_output><empty_output><jupyter_text>Transpile classifier:<jupyter_code>%%time

from sklearn_porter import Porter

porter = Porter(clf)
output = porter.export(export_data=True)

print(output)<jupyter_output>import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import com.google.gson.Gson;


class NuSVC {

    private enum Kernel { LINEAR, POLY, RBF, SIGMOID }
    private class Classifier {
        private int nClasses;
        private int nRows;
        private int[] classes;
        private double[][] vectors;
        private double[][] coefficients;
        private double[] intercepts;
        private int[] weights;
        private String kernel;
        private Kernel kkernel;
        private double gamma;
        private double coef0;
        private double degree;
    }

    private Classifier clf;

    public NuSVC(String file) throws FileNotFoundException {
        String jsonStr = new Scanner(new File(file)).useDelimiter("\\Z").next();
        this.clf = new Gson().fromJson(jsonStr, Classifier.class);
        this.clf.classes = new int[this.clf.nClasses];
        for (int i = 0; i < this.clf.nClasses; i++) {
            th[...]<jupyter_text>Parameters:<jupyter_code>%%bash

cat data.json<jupyter_output>{"nRows": 3, "kernel": "rbf", "nClasses": 3, "weights": [29, 49, 27], "gamma": 0.001, "degree": 3.0, "intercepts": [0.100618401918, 0.0517481601563, -0.084181689668], "vectors": [[4.9, 3.0, 1.4, 0.2], [4.6, 3.1, 1.5, 0.2], [5.4, 3.9, 1.7, 0.4], [5.0, 3.4, 1.5, 0.2], [4.9, 3.1, 1.5, 0.1], [5.4, 3.7, 1.5, 0.2], [4.8, 3.4, 1.6, 0.2], [5.7, 4.4, 1.5, 0.4], [5.7, 3.8, 1.7, 0.3], [5.1, 3.8, 1.5, 0.3], [5.4, 3.4, 1.7, 0.2], [5.1, 3.7, 1.5, 0.4], [5.1, 3.3, 1.7, 0.5], [4.8, 3.4, 1.9, 0.2], [5.0, 3.0, 1.6, 0.2], [5.0, 3.4, 1.6, 0.4], [5.2, 3.5, 1.5, 0.2], [4.7, 3.2, 1.6, 0.2], [4.8, 3.1, 1.6, 0.2], [5.4, 3.4, 1.5, 0.4], [4.9, 3.1, 1.5, 0.1], [4.9, 3.1, 1.5, 0.1], [5.1, 3.4, 1.5, 0.2], [4.5, 2.3, 1.3, 0.3], [5.0, 3.5, 1.6, 0.6], [5.1, 3.8, 1.9, 0.4], [4.8, 3.0, 1.4, 0.3], [5.1, 3.8, 1.6, 0.2], [5.3, 3.7, 1.5, 0.2], [7.0, 3.2, 4.7, 1.4], [6.4, 3.2, 4.5, 1.5], [6.9, 3.1, 4.9, 1.5], [5.5, 2.3, 4.0, 1.3], [6.5, 2.8, 4.6, 1.5], [5.7, 2.8, 4.5, 1.3], [6.3, 3.3, 4.7, 1.6], [4.9, 2.4, 3.3, 1.0], [6.6, 2[...]<jupyter_text>Run classification in Java: Save the transpiled estimator:<jupyter_code>with open('NuSVC.java', 'w') as f:
    f.write(output)<jupyter_output><empty_output><jupyter_text>Download the dependencies:<jupyter_code>%%bash

wget http://central.maven.org/maven2/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar<jupyter_output>--2017-12-01 22:22:50--  http://central.maven.org/maven2/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar
Resolving central.maven.org... 172.16.58.3
Connecting to central.maven.org|172.16.58.3|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 232932 (227K) [application/java-archive]
Saving to: 'gson-2.8.2.jar'

     0K .......... .......... .......... .......... .......... 21% 1.59M 0s
    50K .......... .......... .......... .......... .......... 43% 5.35M 0s
   100K .......... .......... .......... .......... .......... 65% 2.97M 0s
   150K .......... .......... .......... .......... .......... 87%  109M 0s
   200K .......... .......... .......                         100% 5.61M=0.06s

2017-12-01 22:22:50 (3.61 MB/s) - 'gson-2.8.2.jar' saved [232932/232932]<jupyter_text>Compiling:<jupyter_code>%%bash

javac -cp .:gson-2.8.2.jar NuSVC.java<jupyter_output><empty_output><jupyter_text>Prediction:<jupyter_code>%%bash

java -cp .:gson-2.8.2.jar NuSVC data.json 1 2 3 4<jupyter_output>0
{'fraction_non_alphanumeric': 0.25113500597371563, 'fraction_numerical': 0.12329749103942653, 'mean_word_length': 2.5444538526672313, 'pattern_counts': {'":': 8, '<': 29, '<?xml version=': 0, '>': 28, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '505382', 'license': 'MIT', 'n_tokens_mistral': 2120, 'n_tokens_neox': 1844, 'n_words': 372, 'path': 'examples/estimator/classifier/NuSVC/java/basics_imported.ipynb', 'repo_name': 'mathewdgardner/sklearn-porter', 'size': '4191'}