Scikit-Learn Confusion Matrix

confusion matrix sklearn

As a Python developer with over a decade of experience, I’ve seen firsthand how crucial evaluation metrics are when building machine learning models. One of the most fundamental tools to assess classification models is the confusion matrix. In this article, I’ll walk you through what a confusion matrix is, how to generate one using Scikit-Learn, … Read more >>

How to Convert an Array to a Dictionary in TypeScript

Convert an array to a dictionary in TypeScript: Command Prompt output of Object.fromEntries building a Record keyed by employee id

The quickest way to convert an array to a dictionary in TypeScript is Object.fromEntries(): map each item to a [key, value] pair and type the result as a Record. Here’s the one-liner I use for an array of objects keyed by id: Every snippet below ran in strict mode on TypeScript 7.0.2 and Node.js v22.22.2, … Read more >>

How to Get the First Element of an Array in TypeScript?

Get the First Element of an Array in TypeScript

Recently, I got a situation where I needed to access the first item in a TypeScript array. TypeScript provides several ways to accomplish this. In this tutorial, I will explain how to get the first element of an array in TypeScript using different methods with examples. Let me show you each method with examples. 1. … Read more >>

Convert TypeScript Enum to String

Enum Datatype in TypeScript

While working with TypeScript enums, I was required to convert the enum to a string because the support ticket had a status field stored as an enum in TypeScript, but I needed to show a readable string for the UI display. There are various methods to do this. In this tutorial, I will explain how to … Read more >>

How to Convert a String to an Enum in TypeScript

Convert string to enum in TypeScript: Command Prompt output of a type guard parsing order statuses

To convert a string to an enum in TypeScript, check the string against the enum’s values with a type guard, then return the enum member or undefined. A plain as cast checks nothing: My test setup for this post: TypeScript 7.0.2 and Node.js v22.22.2, strict mode on, and nothing in the outputs below is edited … Read more >>

Subtract Days From a Date in TypeScript

Subtract days from date in Typescript using library

Recently, while working on a TypeScript project, I needed to find a date a few days before an important event, like when to start preparing or send reminders. If I had changed the dates directly, it could have caused issues in the code. So, I created a reusable function that subtracts days using TypeScript’s Date … Read more >>

How to Format Date with Timezone in TypeScript

Format date with timezone in TypeScript: Command Prompt output of one instant in five US time zones

You can format a date with a timezone in TypeScript by passing an IANA zone name, like America/New_York, as the timeZone option of Intl.DateTimeFormat or toLocaleString(). The Date itself never changes; only the text you print does: I tested the code below with TypeScript 7.0.2 and Node.js v22.22.2 in strict mode. My test machine’s clock … Read more >>

How to Get the Month from a Date in TypeScript

Get month from date in Typescript

Whether you’re working on a calendar app, generating reports, or performing date-based calculations, retrieving the month from a date is a common task. We’ll explore different methods to accomplish this and provide practical examples along the way. In this tutorial, I will explain how to extract the month from a date object in TypeScript. Understanding … Read more >>

How to Use Default Parameter Values in TypeScript?

Default Parameter Values in TypeScript

Default parameters in TypeScript let you define fallback values for function arguments so your code behaves predictably even when some callers omit certain arguments. In real-world applications, such as API wrappers, UI handlers, and business logic services, good defaults make your functions easier to use, safer to refactor, and more self-documenting. What Are Default Parameters … Read more >>

Copy Elements from One List to Another in Python

python copy list

When I started working with Python lists, I often needed to copy elements from one list to another. At first, I thought it would be as simple as assigning one list to another. But then I learned that an assignment creates a reference, not a true copy. I’ve tried different methods to copy lists in … Read more >>