Optimized Python Implementation for Chen Primes

Prime numbers have fascinated mathematicians for centuries. Among the many special categories of primes, Chen Primes occupy an interesting place because they extend the idea of twin primes and connect prime numbers with semiprimes. In this article, we’ll understand: What is a Chen Prime? A prime number P is called a Chen Prime if: A … Read more

Beautiful Days at the Movies | Hackerrank Solutions

Lily likes to play games with integers. She has created a new game where she determines the difference between a number and its reverse. For instance, given the number 12, its reverse is 21. Their difference is 9 . The number 120 reversed is 21, and their difference is 89. She decides to apply her game to decision making. She will … Read more

Finding the Top K Most Frequent Elements in an Array

Python

Finding the top ( k ) most frequent elements in an array is a common question in coding interviews and a useful task in various applications like data analysis and natural language processing. This guide will walk you through three effective methods to solve this problem: using a HashMap with sorting, Min-Heap, and Bucket Sort. … Read more

Finding the Top K Largest Elements in an Array

In many coding interviews and real-world applications, finding the top ( k ) largest elements in an array is a common problem. This tutorial will guide you through three popular methods to solve this problem: Sorting, Min-Heap, and the Quick select algorithm. We’ll focus on the Min-Heap approach due to its efficiency and practical use … Read more

Maximum Subarray Sum Challenge with Kadane’s Algorithm

Introduction: In the realm of algorithmic problem-solving, the quest for the maximum sum of any contiguous subarray within a given array is a classic challenge. In this tutorial, we’ll embark on a journey to conquer this challenge using Kadane’s algorithm, a powerful tool that operates with a time complexity of O(N). Problem Statement: Given an … Read more

Finding the Longest Palindromic Subsequence

Introduction: Dynamic Programming (DP) is a powerful algorithmic technique used to solve a variety of optimization problems. One classic problem where DP shines is in finding the longest palindromic subsequence in a given string. In this tutorial, we’ll delve into the intricacies of this problem and learn how to tackle it using DP. Problem Statement: … Read more

Sending Data in Unstructured File Form

Unstructured data files consist of a series of bits. The file doesn’t separate the bits from each other in any way. You can’t simply look into the file and see any structure because there isn’t any to see. Unstructured file formats rely on the file user to know how to interpret the data. For example, … Read more

Accessing Data in Structured Flat-File Form

In many cases, the data you need to work with won’t appear within a library, such as the toy datasets in the Scikit-learn library. Real-world data usually appears in a file of some type, and a flat file presents the easiest kind of file to work with. In a flat file, the data appears as … Read more

Utopian Tree | Hackerrank Solution

The Utopian Tree goes through 2 cycles of growth every year. Each spring, it doubles in height. Each summer, its height increases by 1 meter. A Utopian Tree sapling with a height of 1 meter is planted at the onset of spring. How tall will the tree be after  growth cycles? For example, if the number of growth cycles is n=5, the calculations are as … Read more

The Hurdle Race | Hackerrank

A video player plays a game in which the character competes in a hurdle race. Hurdles are of varying heights, and the characters have a maximum height they can jump. There is a magic potion they can take that will increase their maximum jump height by 1 unit for each dose. How many doses of the potion … Read more

Gini Impurity or Entropy? How to decide the root node in decision tree?

By default, the Gini impurity measure is used, but you can select the entropy impurity measure instead by setting the criterion hyperparameter to “entropy”. The concept of entropy originated in thermodynamics as a measure of molecular disorder: entropy approaches zero when molecules are still and well ordered. It later spread to a wide variety of … Read more

How can A linear model learn non-linear/discrete patterns?

Introduction During model development, one of the techniques that many don’t experiment with is feature discretization. The core idea is to transform a continuous feature into discrete features, mostly one-hot encoded. 𝐖𝐡𝐲 𝐰𝐨𝐮𝐥𝐝 𝐰𝐞 𝐝𝐨 𝐭𝐡𝐚𝐭? My rationale for using feature discretization has almost always been simple: “It just makes sense to discretize a feature.” … Read more

What is Lasso Regression? | Machine Learning from Scratch

Least Absolute Shrinkage and Selection Operator Regression (simply called Lasso Regression) is another regularized version of Linear Regression: just like Ridge Regression, it adds a regularization term to the cost function, but it uses the ℓ1 norm of the weight vector instead of half the square of the ℓ2 norm. Figure below shows the same … Read more

Regularized Linear Models(Ridge Regression) | Machine Learning from Scratch

As we saw in previous posts, a good way to reduce overfitting is to regularize the model (i.e., to constrain it): the fewer degrees of freedom it has, the harder it will be for it to overfit the data. For example, a simple way to regularize a polynomial model is to reduce the number of … Read more

Hackerrank Problems | Diagonal Difference

Given a square matrix, calculate the absolute difference between the sums of its diagonals. For example, the square matrix  is shown below: The left-to-right diagonal =1+5+9=15. The right to left diagonal = 3+5+9=17. Their absolute difference is |15-17|=2. Function description Complete the  diagonalDifference function in the editor below. diagonalDifference takes the following parameter: Return Input Format The first line … Read more

Hackerrank Problems | Compare the triplets

Python

Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty. The rating for Alice’s challenge is the triplet a = (a[0], a[1], a[2]), and the rating for Bob’s challenge is the triplet b = (b[0], b[1], b[2]). The task is to find … Read more

Polynomial Regression | Machine Learning from Scratch

Polynomial regression

Introduction Till now, We have read about Gradient Descent,Min-Batch Gradient Descent,Stochastic Gradient Descent and other type of Gradient Descents. In this post we will learn about Polynomial Regression. What if your data is actually more complex than a simple straight line? Surprisingly,you can actually use a linear model to fit nonlinear data. A simple way … Read more

Datasets Importing and exporting in Python.

Python Feature Image

What is Dataset? Datasets are container of data in python. It can work as data storage for the various algorithms in python. and also a primary storage of data in Data Science. Below I will be discussing how to import a datasets as dataframe in python. For this post I’ll be using a public dataset … Read more