<commit_before>'use strict';
const Classifier = require('./classifier');

class BayesClassifier extends Classifier {
    constructor(smoothing) {
        super();

        this.classFeatures = this.empty;
        this.classTotals = this.empty;
        this.totalExamples = 1;
        this.smoothing = smoothing || 1.0;

    }

    get empty() {
        return Object.create(null);
    }

    addExample(observation, label) {
        if (!this.classFeatures[label]) {
            this.classFeatures[label] = this.empty;
            this.classTotals[label] = 1;
        }

        if (observation instanceof Array) {
            this.totalExamples++;
            this.classTotals[label]++;

            observation.forEach((o, i) => {
                if (this.classFeatures[label][i]) {
                    this.classFeatures[label][i]++;
                } else {
                    // give an extra for smoothing
                    this.classFeatures[label][i] = 1 + this.smoothing;
                }
            })
        } else {
            // sparse observation
            for (let value of observation) {
                if (this.classFeatures[label][value]) {
                    this.classFeatures[label][value]++;<commit_msg>only measuare if we observed sample<commit_after>'use strict';
const Classifier = require('./classifier');

class BayesClassifier extends Classifier {
    constructor(smoothing) {
        super();

        this.classFeatures = this.empty;
        this.classTotals = this.empty;
        this.totalExamples = 1;
        this.smoothing = smoothing || 1.0;

    }

    get empty() {
        return Object.create(null);
    }

    addExample(observation, label) {
        if (!this.classFeatures[label]) {
            this.classFeatures[label] = this.empty;
            this.classTotals[label] = 1;
        }

        if (observation instanceof Array) {
            this.totalExamples++;
            this.classTotals[label]++;

            observation.forEach((o, i) => {
                if (o) {
                    if (this.classFeatures[label][i]) {
                        this.classFeatures[label][i]++;
                    } else {
                        // give an extra for smoothing
                        this.classFeatures[label][i] = 1 + this.smoothing;
                    }
                }
            })
        } else {
            // sparse observation
            for (let value of observation) {
                if (this.classFeatures[label][value]) {
                    this.classFeatures[label][value]++;
{'fraction_non_alphanumeric': 0.11557985162046076, 'fraction_numerical': 0.003904724716907458, 'mean_word_length': 1.5568862275449102, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5866745', 'n_tokens_mistral': 708, 'n_tokens_neox': 645, 'n_words': 132}