<jupyter_start><jupyter_text>sklearn-porterRepository: https://github.com/nok/sklearn-porter LinearSVCDocumentation: [sklearn.svm.LinearSVC](http://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC.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.LinearSVC(C=1., 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()

print(output)<jupyter_output>class LinearSVC {

    private double[][] coefficients;
    private double[] intercepts;
    
    public LinearSVC(double[][] coefficients, double[] intercepts) {
        this.coefficients = coefficients;
        this.intercepts = intercepts;
    }

    public int predict(double[] features) {
        int classIdx = 0;
        double classVal = Double.NEGATIVE_INFINITY;
        for (int i = 0, il = this.intercepts.length; i < il; i++) {
            double prob = 0.;
            for (int j = 0, jl = this.coefficients[0].length; j < jl; j++) {
                prob += this.coefficients[i][j] * features[j];
            }
            if (prob + this.intercepts[i] > classVal) {
                classVal = prob + this.intercepts[i];
                classIdx = i;
            }
        }
        return classIdx;
    }

    public static void main(String[] args) {
        if (args.length == 4) {

            // Features:
            double[] features = new double[args.length];
            for (int[...]<jupyter_text>Run classification in Java: Save the transpiled estimator:<jupyter_code>with open('LinearSVC.java', 'w') as f:
    f.write(output)<jupyter_output><empty_output><jupyter_text>Compiling:<jupyter_code>%%bash

javac -cp . LinearSVC.java<jupyter_output><empty_output><jupyter_text>Prediction:<jupyter_code>%%bash

java -cp . LinearSVC 1 2 3 4<jupyter_output>2
{'fraction_non_alphanumeric': 0.1288022813688213, 'fraction_numerical': 0.009505703422053232, 'mean_word_length': 3.295918367346939, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '266506', 'license': 'MIT', 'n_tokens_mistral': 770, 'n_tokens_neox': 722, 'n_words': 136, 'path': 'examples/estimator/classifier/LinearSVC/java/basics.ipynb', 'repo_name': 'mathewdgardner/sklearn-porter', 'size': '2104'}