<commit_before>// Copyright © 2017 <NAME> <<EMAIL>>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metrics

import (
	"log"
	"math"
	"strconv"
)

type ConfusionMatrix struct {
	TP        int64
	FP        int64
	TN        int64
	FN        int64
	Total     int64
	Threshold float64
}

func (cm *ConfusionMatrix) Update(yText, yHatText string) {
	var y int64

	if cm.Threshold == -1.0 {
		y, err := strconv.ParseInt(yText, 10, 8)
		if err != nil {
			log.Fatal("Error parsing y value as binary class", err)
		}
		if y == -1 {
			y = 0
		}
	} else {
		yprob, err := strconv.ParseFloat(yText, 64)
		if err != nil {
			log.Fatal("Error parsing y value as probability", err)
		}
		if yprob < cm.Threshold {
			y = 0
		} else {
			y = 1
		}
	}

	yHat, err := strconv.ParseInt(yHatText, 10, 8)
	if err != nil {
		log.Fatal("Error parsing y hat", err)
	}
	if yHat == -1 {
		yHat = 0
	}

	switch y {
	case 0:
		switch yHat {
		case 0:
			cm.TN += 1
		case 1:
			cm.FP += 1
		}
	case 1:
		switch yHat {
		case 0:
			cm.FN += 1
		case 1:
			cm.TP += 1
		}
	}
	cm.Total++<commit_msg>* Fixed bug reversing y and yhat in Update<commit_after>// Copyright © 2017 <NAME> <<EMAIL>>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metrics

import (
	"log"
	"math"
	"strconv"
)

type ConfusionMatrix struct {
	TP        int64
	FP        int64
	TN        int64
	FN        int64
	Total     int64
	Threshold float64
}

func (cm *ConfusionMatrix) Update(yText, yHatText string) {
	var yHat int64

	y, err := strconv.ParseInt(yHatText, 10, 8)
	if err != nil {
		log.Fatal("Error parsing y: ", err)
	}
	if y == -1 {
		y = 0
	}

	if cm.Threshold == -1.0 {
		yHat, err := strconv.ParseInt(yText, 10, 8)
		if err != nil {
			log.Fatal("Error parsing yhat value as binary class: ", err)
		}
		if yHat == -1 {
			yHat = 0
		}
	} else {
		yHatProb, err := strconv.ParseFloat(yText, 64)
		if err != nil {
			log.Fatal("Error parsing yhat value as probability: ", err)
		}
		if yHatProb < cm.Threshold {
			yHat = 0
		} else {
			yHat = 1
		}
	}



	switch y {
	case 0:
		switch yHat {
		case 0:
			cm.TN += 1
		case 1:
			cm.FP += 1
		}
	case 1:
		switch yHat {
		case 0:
			cm.FN += 1
		case 1:
			cm.TP += 1
		}
	}
	cm.Total++
{'fraction_non_alphanumeric': 0.11633663366336634, 'fraction_numerical': 0.0297029702970297, 'mean_word_length': 2.510314875135722, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1042695', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1141, 'n_words': 418}