Python Less Than

The Python less than (left<right) operator returns True when its left operand is smaller than its right operand. When the left operand is greater than or equal to the right operand, the < operator returns False. For example, 2<3 evaluates to True, but 3<2 and 2<2 both evaluate to False. Examples Let’s explore a couple … Read more

[Tutorial] K-Means Clustering with SKLearn in One Line

If there is one clustering algorithm you need to know – whether you are a computer scientist, data scientist, or machine learning expert – it’s the K-Means algorithm. In this tutorial drawn from my book Python One-Liners, you’ll learn the general idea and when and how to use it in a single line of Python … Read more

Python Greater Than

The Python greater than (left>right) operator returns True when its left operand exceeds its right operand. When the left operand is smaller than or equal to the right operand, the > operator returns False. For example, 3>2 evaluates to True, but 2>3 and 3>3 both evaluate to False. Examples Let’s explore a couple of examples … Read more

How to Set and Reset Pandas DataFrame Indexes

The set_index( ) and reset_index( ) methods are used on top of a Pandas DataFrame to manipulate its index column. The method set_index( ) is used to set the index of the DataFrame from the existing columns. The method reset_index( ) is used to get back to the default index of the dataset. Pandas set_index … Read more

[NumPy] How to Calculate The Average Along an Axis?

This article explains how to calculate basic statistics such as average, standard deviation, and variance along an axis. We use the NumPy library for linear algebra computations. These three ways are very similar — if you understand one of them, you’ll understand all of them. TLDR; To average a NumPy array x along an axis, … Read more

Python Operators Overview

What Are Python Operators? Python operators are special syntactical sugar to run basic operations without calling their respective methods. For example, you can use the + operator in a + b instead of the more clunky .add() method in a.add(b). Each operator has a unique symbol that is placed between the two arguments called operands. … Read more

How to Divide Two Integers in Python 2 and 3?

In this article, you’ll learn about the division operators // and / in Python 2 and 3. You can check out the version in your Python script as shown here. A short visual overview of the division operator in Python 2 and 3: Assuming two integer values stored in variables a and b, there are … Read more

Introduction to Python Classes

This article introduces classes in Python, explaining what they are, their components, and why we use them. We’ll also look at some unique characteristics of classes to assist us in creating cleaner code. When I first began coding, the subject of classes in Python was a complete mystery to me. The explanations and jargon employed … Read more

[Fixed] Unknown label type: ‘continuous’ in sklearn LogisticRegression

Summary: Use SKLearn’s LogisticRegression Model for classification problems only. The Y variable is a category (e.g., binary [0,1]), not continuous (e.g. float numbers 3.4, 7.9). If the Y variable is non-categorical (i.e., continuous), the potential fixes are as follows. Re-examine the data. Try to encode the continuous Y variable into categories (e.g., use SKLearn’s LabelEncoder preprocessor). Re-examine … Read more