<commit_before>'''
Created on 22.01.2015

@author: marscher
'''
import numpy as np
from sklearn.cluster import MiniBatchKMeans

from transformer import Transformer


class KmeansClustering(Transformer):

    '''
    classdocs
    '''

    def __init__(self, data_producer, n_clusters, max_iter=1000):
        '''
        Constructor
        '''
        super(KmeansClustering, self).__init__()

        self.data_producer = data_producer

        self.algo = MiniBatchKMeans(n_clusters,
                                    max_iter=max_iter,
                                    batch_size=self.chunksize)

        self.dtrajs = []
        self.param_finished = False

    def add_chunk(self, X, itraj, t, first_chunk, last_chunk_in_traj, last_chunk, ipass, Y=None):
        L = np.shape(X)[0]
        if ipass == 0:
            self.algo.partial_fit(X)
        if ipass == 1:
            # discretize all
            if t == 0:
                self.dtrajs.append(<commit_msg>set correct attribute<commit_after>'''
Created on 22.01.2015

@author: marscher
'''
import numpy as np
from sklearn.cluster import MiniBatchKMeans

from transformer import Transformer


class KmeansClustering(Transformer):

    '''
    classdocs
    '''

    def __init__(self, data_producer, n_clusters, max_iter=1000):
        '''
        Constructor
        '''
        super(KmeansClustering, self).__init__()

        self.data_producer = data_producer

        self.algo = MiniBatchKMeans(n_clusters,
                                    max_iter=max_iter,
                                    batch_size=self.chunksize)

        self.dtrajs = []
        self._param_finished = False

    def add_chunk(self, X, itraj, t, first_chunk, last_chunk_in_traj, last_chunk, ipass, Y=None):
        L = np.shape(X)[0]
        if ipass == 0:
            self.algo.partial_fit(X)
        if ipass == 1:
            # discretize all
            if t == 0:
                self.dtrajs.append(
{'fraction_non_alphanumeric': 0.0959673302705462, 'fraction_numerical': 0.01633486472690148, 'mean_word_length': 1.929745889387145, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2560899', 'n_tokens_mistral': 653, 'n_tokens_neox': 595, 'n_words': 127}