<commit_before>import numpy as np
import setuptools

from HPOlibConfigSpace.configuration_space import ConfigurationSpace
from HPOlibConfigSpace.hyperparameters import UniformFloatHyperparameter, \
    UniformIntegerHyperparameter, CategoricalHyperparameter, \
    UnParametrizedHyperparameter, Constant

from sklearn.preprocessing import OneHotEncoder

from ParamSklearn.components.classification_base import ParamSklearnClassificationAlgorithm
from ParamSklearn.util import DENSE, PREDICTIONS
# get our own forests to replace the sklearn ones
import GPy


class GPyClassifier(ParamSklearnClassificationAlgorithm):
    def __init__(self, random_state=None, n_inducing=5, ard=False):
        self.estimators = None
        self.n_inducing = int(n_inducing)

        if ard == "True":
            self.ard = True
        elif ard == "False":
            self.ard = False
        else:
            selfard = ard

        self.enc = None

    def fit(self, X, Y):
        # one hot encode targets for one against all classification
        self.enc = OneHotEncoder(sparse=False)
        targets = self.enc.fit_transform(Y[:,None])

        # create a list of GP models, one for each class
        self.estimators = []
        for i in range(self.enc.n_values_):
            # train model 
            kern = GPy.kern._src.rbf.RBF(X.shape[1], variance=1.0, lengthscale=1.0, ARD=self.ard)
            # dense
            # model = GPy.models.GPClassification(X, targets[:,i,None], kernel=kern)
            # sparse 
            model = GPy.models.SparseGPClassification(X, targets[:,i,None], kernel=kern, num_inducing=self.n_inducing)
            # fit kernel hyperparameters
            model.optimize('bfgs', max_iters=100)
            # add to list of estimators
            self.estimators.append(model)
        return self

    def predict(self, X):
        if self.estimators is None:
            raise NotImplementedError
        # get probabilities for each class
        probs = np.zeros([len(X), len(self.estimators)])
        for i, model in enumerate(self.estimators):
            probs[:,i] = model.predict(X)[0].flatten()        
        # return the most probable label 
        return self.enc.active_features_[np.argmax(probs, 1)]

    def predict_proba(self, X):
        if self.estimators is None:
            raise NotImplementedError()
        probs = np.zeros([len(X), len(self.estimators)])<commit_msg>explicitly turned off normalization in GP<commit_after>import numpy as np
import setuptools

from HPOlibConfigSpace.configuration_space import ConfigurationSpace
from HPOlibConfigSpace.hyperparameters import UniformFloatHyperparameter, \
    UniformIntegerHyperparameter, CategoricalHyperparameter, \
    UnParametrizedHyperparameter, Constant

from sklearn.preprocessing import OneHotEncoder

from ParamSklearn.components.classification_base import ParamSklearnClassificationAlgorithm
from ParamSklearn.util import DENSE, PREDICTIONS

import GPy


class GPyClassifier(ParamSklearnClassificationAlgorithm):
    def __init__(self, random_state=None, n_inducing=5, ard=False):
        self.estimators = None
        self.n_inducing = int(n_inducing)

        if ard == "True":
            self.ard = True
        elif ard == "False":
            self.ard = False
        else:
            selfard = ard

        self.enc = None

    def fit(self, X, Y):
        # one hot encode targets for one against all classification
        self.enc = OneHotEncoder(sparse=False)
        targets = self.enc.fit_transform(Y[:,None])

        # create a list of GP models, one for each class
        self.estimators = []
        for i in range(self.enc.n_values_):
            # train model 
            kern = GPy.kern._src.rbf.RBF(X.shape[1], variance=1.0, lengthscale=1.0, ARD=self.ard)
            # dense
            # model = GPy.models.GPClassification(X, targets[:,i,None], kernel=kern)
            # sparse 
            model = GPy.models.SparseGPClassification(X, 
                    targets[:,i,None], 
                    kernel=kern, 
                    num_inducing=self.n_inducing,
                    normalize_X=False,
                    normalize_Y=False)
            # fit kernel hyperparameters
            model.optimize('bfgs', max_iters=100)
            # add to list of estimators
            self.estimators.append(model)
        return self

    def predict(self, X):
        if self.estimators is None:
            raise NotImplementedError
        # get probabilities for each class
        probs = np.zeros([len(X), len(self.estimators)])
        for i, model in enumerate(self.estimators):
            probs[:,i] = model.predict(X)[0].flatten()        
        # return the most probable label 
        return self.enc.active_features_[np.argmax(probs, 1)]

    def predict_proba(self, X):
        if self.estimators is None:
            raise NotImplementedError()
        probs = np.zeros([len(X), len(self.estimators)])
{'fraction_non_alphanumeric': 0.08729838709677419, 'fraction_numerical': 0.004435483870967742, 'mean_word_length': 2.4985895627644568, 'pattern_counts': {'":': 4, '<': 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': '2649938', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1412, 'n_words': 347}