<commit_before>#  File encoding: utf-8

from __future__ import division, print_function, absolute_import
from abc import ABCMeta

from .interface import Classifier, Regressor
from .utils import check_inputs

from nolearn.dbn import DBN

__author__ = '<NAME>'

class NolearnClassifier(Classifier):
    def __init__(self, features=None, layer_sizes=None, learn_rates=0.1, learn_rate_decays=1.0, epochs=10, verbose=0):
        # Что, если layer_sizes[0] не равно len(features)?
        self.clf = DBN(layer_sizes=layer_sizes, learn_rates=learn_rates, epochs=epochs, verbose=verbose)
        Classifier.__init__(self, features=features)

    def fit(self, X, y, sample_weight=None):
        X, y, sample_weight = check_inputs(X, y, sample_weight=sample_weight, allow_none_weights=True)
        if sample_weight is not None:
            raise ValueError("The sample_weight parameter is not supported for nolearn")       
        return self.clf.fit(self._get_train_features(X).values, y)

    def predict(self, X):
        return self.clf.predict(self._get_train_features(X).values)

    def predict_proba(self, X):
        return self.clf.predict_proba(self._get_train_features(X).values)

    def staged_predict_proba(self, X):
        raise AttributeError("Not supported for nolearn")

    def score(self, X, y, sample_weight=None):
        if sample_weight is not None:
            raise ValueError("The sample_weight parameter is not supported for nolearn")
        return self.clf.score(self._get_train_features(X).values, y)<commit_msg>get_params() and set_params() added, score() deleted<commit_after>from __future__ import division, print_function, absolute_import
from abc import ABCMeta

from .interface import Classifier, Regressor
from .utils import check_inputs

from nolearn.dbn import DBN

import inspect

__author__ = '<NAME>'

class NolearnClassifier(Classifier):
    def __init__(self, features=None,
                 layer_sizes=None,
                 scales=0.05,
                 fan_outs=None,
                 output_act_funct=None,
                 real_valued_vis=True,
                 use_re_lu=True,
                 uniforms=False,
                 learn_rates=0.1,
                 learn_rate_decays=1.0,
                 learn_rate_minimums=0.0,
                 momentum=0.9,
                 l2_costs=0.0001,
                 dropouts=0,
                 nesterov=True,
                 nest_compare=True,
                 rms_lims=None,
                 learn_rates_pretrain=None,
                 momentum_pretrain=None,
                 l2_costs_pretrain=None,
                 nest_compare_pretrain=None,
                 epochs=10,
                 epochs_pretrain=0,
                 loss_funct=None,
                 minibatch_size=64,
                 minibatches_per_epoch=None,
                 pretrain_callback=None,
                 fine_tune_callback=None,
                 random_state=None,
                 verbose=0):
        Classifier.__init__(self, features=features)

        self.layer_sizes = layer_sizes
        self.scales = scales
        self.fan_outs = fan_outs
        self.output_act_funct = output_act_funct
        self.real_valued_vis = real_valued_vis
        self.use_re_lu = use_re_lu
        self.uniforms = uniforms

        self.learn_rates = learn_rates
        self.learn_rate_decays = learn_rate_decays
        self.learn_rate_minimums = learn_rate_minimums
        self.momentum = momentum
        self.l2_costs = l2_costs
        self.dropouts = dropouts
        self.nesterov = nesterov
        self.nest_compare = nest_compare
        self.rms_lims = rms_lims

        self.learn_rates_pretrain = learn_rates_pretrain
        self.momentum_pretrain = momentum_pretrain
        self.l2_costs_pretrain = l2_costs_pretrain
        self.nest_compare_pretrain = nest_compare_pretrain

        self.epochs = epochs
        self.epochs_pretrain = epochs_pretrain
        self.loss_funct = loss_funct
        self.minibatch_size = minibatch_size
        self.minibatches_per_epoch = minibatches_per_epoch

        self.pretrain_callback = pretrain_callback
        self.fine_tune_callback = fine_tune_callback

        self.random_state = random_state

        self.verbose = verbose

    def get_params(self):
        params = {}
        args = inspect.getargspec(self.__init__)[0][1:]
        for key in args:
            value = getattr(self,key)
            params[key] = value
        return params

    def set_params(self, **params):
        valid_param_names = self.get_params().keys()
        for key, value in params.items():
            if key not in valid_param_names:
                raise AttributeError("NolearnClassifier has no parameter '{}'".format(key))
            else:
                setattr(self, key, value)

    def fit(self, X, y, sample_weight=None):
        X, y, sample_weight = check_inputs(X, y, sample_weight=sample_weight, allow_none_weights=True)

        if sample_weight is not None:
            raise ValueError("The sample_weight parameter is not supported for nolearn")

        clf_params = self.get_params()
        del clf_params["features"]
        self.clf = DBN(**clf_params)

        return self.clf.fit(self._get_train_features(X).values, y)

    def predict(self, X):
        return self.clf.predict(self._get_train_features(X).values)

    def predict_proba(self, X):
        return self.clf.predict_proba(self._get_train_features(X).values)

    def staged_predict_proba(self, X):
        raise AttributeError("Not supported for nolearn")
{'fraction_non_alphanumeric': 0.07845960050386899, 'fraction_numerical': 0.007198128486593486, 'mean_word_length': 2.445753254804712, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2118032', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1654, 'n_words': 339}