Confusion matrix, Accuracy, Precision, Sensitivity, Specificity, F1 score, and Roc curve, let’s remember them once for all

Image for post

Despite having seen all these concepts more than a thousand times, I’m still getting confused sometimes. Is there a good way to think about all these concepts so that they start making sense?

In this post, I will focus on how to remember them. If you’re not familiar with them, please read the following posts first.

Table of content

  1. Confusion Matrix
  2. Accuracy
  3. Precision
  4. Recall
  5. Specificity
  6. Tradeoff
  7. Roc Curve

1. Confusion Matrix

A confusion matrix is a table used to evaluate the performance of a classification model. It summarizes the count combinations of every predicted and actual class.

Let’s understand this concept in a simple example. Below…

Image for post

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.

Redis is the world’s most popular in-memory data structure server. In order to make good use of it, we need to understand its basic data structures first.


The Redis String type is the simplest type of value you can associate with a Redis key. …

Image for post
Image for post

Problem Statement

A company is planning to interview 2N people. Given the array costs, the cost of flying the i-th person to city A is costs[i][0], and the cost of flying the i-th person to city B is costs[i][1].

Return the minimum cost to fly every person to a city such that exactly n people arrive in each city.

Example 1:

Input: costs = [[10,20],[30,200],[400,50],[30,20]] Output: 110 Explanation: The first person goes to city A for a cost of 10. The second person goes to city A for a cost of 30. The third person goes to city B for a cost…

Image for post
Image for post
sudoku problem

Backtracking algorithm is a really cool technique to solve some kind of puzzles like N queen problem, sudoku problem.

This post provides a framework or blueprint to conquer these kinds of problems.


Backtracking is a general algorithm for finding solutions to some computational problems.

It incrementally builds candidates to the solutions and abandons each partial candidate as soon as it determines that the candidate cannot possibly be completed.

Be similar to a brute force algorithm, a backtracking algorithm essentially explores all solutions. However, In backtracking, we stop evaluating a possibility as soon as it breaks some constraint provided in the…

Image for post
Image for post

Bitwise operations are hard to understand for some beginning programmers. So this post is to explain them easily and unforgettably.

What’s a bit and bit string?

A bit is the smallest unit of information that can be stored or manipulated on a computer. It consists of a single Boolean value (0 or 1).

A bit string is a sequence of bits. It can be used to represent sets or to manipulate binary data.

Bitwise Operations

Bitwise AND (&)

The bitwise AND operator (&) returns a 1 in each bit position for which the corresponding bits of both operands (input and mask) are 1s.

Two principles:

a. Y AND 1 = Y

Image for post
Image for post

Linked-List is the high frequently interviewed question for software engineers. Even though this data structure is easy to understand, interview problems related to it, however, are not easy to solve.

Because it’s very difficult to predict ahead what you will need to end up with in terms of temporary pointers just by writing a line of codes one after the others.

Solve Procedure

A standard step by step procedure helps:

  • Draw the linked-list boxes and links between each other (as arrows between the boxes horizontally).
  • Ask yourself, when you override a link (node->next), do you still need access to that node further…

Image for post
Image for post
binary tree

A binary Tree is a tree-like data structure where every node has at most two children.

If you flip the tree upside down, it kind of looks like a tree. That’s where the name comes from!


  • Node — a data structure consisting of a value, together with left and right references to other nodes.
class TreeNode:    def __init__(self, val=0, left=None, right=None):   
self.val = val
self.left = left
self.right = right
  • Root — the top node without a parent
  • Edge — the connection between two nodes
  • Leaf — a node without any children

How to recognize the leaf node in code?

Let’s understand binary tree creation details by a little example.

Class Definition

The Definition ofTreeNode is the following.

class TreeNode:

def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right

Two Variables

  • root — the variable is useful to access the binary tree
  • curnode — the variable is for iteration inside of the binary tree
root = curnode = TreeNode(val=1)
Image for post
Image for post
two tree node object

Create Children

Creating two child tree node, their parent node curnode is used

curnode.left = TreeNode(1)
curnode.right = TreeNode(2)

Binary Tree traversal such as preorder traversal, inorder traversal, postorder traversal, and level order traversal is commonly interviewed by many IT companies. So why not conquer the monster only in this post?

Preorder Traversal

Preorder means “Visit” a node first, then traverse its children.

Video of pre-order traversal

Procedure: Root > Left > Right

  • Step 1: “Visit” the node
  • Step 2: Traverse left
  • Step 3: Traverse right
Image for post
Image for post
pre-order traversal remember plot

Remember trick:

We walk the graph, from top going counter-clockwise. Shout every time we pass the LEFT of a node.

Recursive implementation

To convert an inherently recursive procedure to an iterative one, we need an explicit stack. Iterative implementation as following:


Recognize Captcha is a human-centered test to distinguish a human from bots. Some of the captchas are easy to crack, while others may need to adopt advanced techniques such as deep learning.

In this series, I will focus on bypassing a certain kind of captcha problem — slide captcha problem using a deep learning method.

Image for post
Image for post
slide captcha example

1. Define Problem

It is easy to understand that this captcha problem is an object detection problem.

Object detection is a computer vision technique that allows us to identify and locate objects in an image or video.

Jerry An

Developer in China, AI and machine learning enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store