<jupyter_start><jupyter_text>sklearn-porterRepository: [https://github.com/nok/sklearn-porter](https://github.com/nok/sklearn-porter) LinearSVCDocumentation: [sklearn.svm.LinearSVC](http://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC.html)<jupyter_code>import sys
sys.path.append('../../../../..')<jupyter_output><empty_output><jupyter_text>Load 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>/opt/miniconda/envs/sklearn-porter/lib/python2.7/site-packages/sklearn/svm/base.py:922: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
  "the number of iterations.", ConvergenceWarning)<jupyter_text>Transpile classifier<jupyter_code>from sklearn_porter import Porter

porter = Porter(clf, language='c')
output = porter.export()

print(output)<jupyter_output>#include <stdlib.h>
#include <stdio.h>
#include <math.h>

double coefficients[3][4] = {{0.1842387105153816, 0.45123226735416666, -0.8079442418237148, -0.4507120994138801}, {0.05538075463135362, -0.9011091317807134, 0.40964725305179495, -0.9616708418438406}, {-0.8507797840387784, -0.9866797559823655, 1.380978948733964, 1.865367212912733}};
double intercepts[3] = {0.10956037385996253, 1.6860176665898299, -1.7096500573837932};

int predict (float features[]) {
    double class_val = -INFINITY;
    int class_idx = -1;
    int i, il, j, jl;
    for (i = 0, il = sizeof(coefficients) / sizeof (coefficients[0]); i < il; i++) {
        double prob = 0.;
        for (j = 0, jl = sizeof(coefficients[0]) / sizeof (coefficients[0][0]); j < jl; j++) {
            prob += coefficients[i][j] * features[j];
        }
        if (prob + intercepts[i] > class_val) {
            class_val = prob + intercepts[i];
            class_idx = i;
        }
    }
    return class_idx;
}

int main(int argc, const c[...]<jupyter_text>Run classification in C<jupyter_code># Save model:
# with open('linearsvc.c', 'w') as f:
#     f.write(output)

# Compile model:
# $ gcc linearsvc.c -std=c99 -lm -o linearsvc

# Run classification:
# $ ./linearsvc 1 2 3 4<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1522108843537415, 'fraction_numerical': 0.12244897959183673, 'mean_word_length': 4.497663551401869, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, 'https://': 2, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '121272', 'license': 'MIT', 'n_tokens_mistral': 1095, 'n_tokens_neox': 908, 'n_words': 161, 'path': 'examples/estimator/classifier/LinearSVC/c/basics.pct.ipynb', 'repo_name': 'karoka/sklearn-porter', 'size': '2352'}