Adi Biton

Adi biton • Dec 5, 2023 • 2 min read

How to Choose the Right Metrics for Classification Models

Introduction

Classification models are widely used in data science and machine learning to predict a class for a given input. For example, given a picture of a dog, we need to predict if it’s a dog or not. However, how do we know if our model is accurate and reliable? How do we measure the performance of our model and compare it with other models? In this blog post, I will explain some common metrics for classification models, such as accuracy, precision, recall, and F1 score. I will also show you some examples and pitfalls of using these metrics, and how to choose the best metric for your problem and data. The common sense tell us that the accuracy of our model can be measured simply by an accuracy metric, which divide the total correct predictions by the total number of observations. The common sense is wrong. For example, let’s say we have a dataset of 1000 pictures of dogs and one picture of cat. The model that always predict dog will have 99.9% accuracy, however, it’s a bad model, for a different dataset (for example 1000 cats and one dog) it will have close to 0% accuracy. Let’s see some other metrics that can help us to evaluate model accuracy, the measerments are on the accuracy of specific class.

Precision

Recall

Since both precision and recall are important, we need a way to combine them into one metric, this metric is called F1 Score.

F1 Score:

 Read →

Adi biton • Nov 12, 2018 • 1 min read

Digital signature

In this post i’ll give a simple example of how you can sign (digitally) with builtin crypto (node.js) module. Digital signature is a mathematical process that tries to ensure the contents of message has not been changed after creation. This process involve signing the document (message) using some private key and hash function. The result of the process + public key constructs the Digital signature. If someone would like to confront the message has not been altered, a validation process involving the original message and the Digital signature can check this. Ok, it’s time to see some code: In this tutorial we would use openssl for creating private/public key pair Let’s grab some public/private key pair:

openssl genrsa -out rsa_1024_private.pem 1024
openssl rsa -pubout -in rsa_1024_private.pem -out rsa_1024_public.pem
We created a private/public key pair named rsa_1024_private.pem and rsa_1024_public.pem Signing a message using the private key:
const crypto = require('crypto')
...
function sign(message) {
    const sign = crypto.createSign('sha384')
    sign.update(message)
    return sign.sign(privateKey, 'hex')
}
Where: Now let’s try to validate the signature using the public key:
function validate(message, signature) {
    const verify = crypto.createVerify('sha384')
    verify.update(message)
    return verify.verify(publicKey, signature, 'hex')
}
Where: You can find the full code here  Read →

Adi biton • Jun 30, 2015 • 5 min read

Some thoughts on inheritance in JavaScript

javascript inheritance Read →