<commit_before>"""
Wrapper for OpenCV's support vector machine implementation.
"""

import cv2


class StatModel(object):

    def load(self, fn):
        self.model.load(fn)

    def save(self, fn):
        self.model.save(fn)


class SVM(StatModel):

    def __init__(self):
        """Initializes an SVM"""
        self.model = cv2.SVM()

    def train(self, samples, labels):
        """Trains the SVM from a list of samples and their associated labels

        :param samples: list of samples to use for training
        :type samples: numpy.ndarray
        :param labels: labels for the samples
        :type labels: numpy.ndarray
        """
        params = dict(kernel_type=cv2.SVM_RBF, svm_type=cv2.SVM_C_SVC)
        self.model.train_auto(samples, labels, None, None, params)

    def predict(self, sample):
        """Predict a class for a sample.

        :param sample: the sample to classify
        :returns: numpy.float32
        """
        return self.model.predict(sample, True)<commit_msg>Make SVM object pickleable<commit_after>"""
Wrapper for OpenCV's support vector machine implementation.
"""

import cv2


class StatModel(object):

    def __init__(self):
        self.fn = None

    def load(self, fn):
        self.fn = fn
        self.model.load(fn)

    def save(self, fn):
        self.model.save(fn)


class SVM(StatModel):

    def __init__(self):
        """Initializes an SVM"""
        self.model = cv2.SVM()

    def train(self, samples, labels):
        """Trains the SVM from a list of samples and their associated labels

        :param samples: list of samples to use for training
        :type samples: numpy.ndarray
        :param labels: labels for the samples
        :type labels: numpy.ndarray
        """
        params = dict(kernel_type=cv2.SVM_RBF, svm_type=cv2.SVM_C_SVC)
        self.model.train_auto(samples, labels, None, None, params)

    def predict(self, sample):
        """Predict a class for a sample.

        :param sample: the sample to classify
        :returns: numpy.float32
        """
        return self.model.predict(sample, True)

    def __getstate__(self):
        return self.fn

    def __setstate__(self, state):
        self.__init__()
        self.fn = state

        if self.fn is not None:
            self.model.load(state)
{'fraction_non_alphanumeric': 0.1023417172593235, 'fraction_numerical': 0.005203816131830009, 'mean_word_length': 2.397643593519882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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}}
{'dir': 'git-commits-cleaned', 'id': '7423626', 'n_tokens_mistral': 707, 'n_tokens_neox': 670, 'n_words': 212}