Girish Rao

[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 …

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

Sklearn fit() vs transform() vs fit_transform() – What’s the Difference?

Scikit-learn has a library of transformers to preprocess a data set. These transformers clean, generate, reduce or expand the feature representation of the data set. These transformers provide the fit(), transform() and fit_transform() methods. The fit() method identifies and learns the model parameters from a training data set. For example, standard deviation and mean for …

Sklearn fit() vs transform() vs fit_transform() – What’s the Difference? Read More »

How To Plot SKLearn Confusion Matrix With Labels?

Summary: The best way to plot a Confusion Matrix with labels, is to use the ConfusionMatrixDisplay object from the sklearn.metrics module. Another simple and elegant way is to use the seaborn.heatmap() function. Note: All the solutions provided below have been verified using Python 3.9.0b5. Problem Formulation Imagine the following lists of Actual and Predicted values …

How To Plot SKLearn Confusion Matrix With Labels? Read More »

How to Check Whether a Variable is a Class or Not?

This tutorial explores the ways one can check if a variable is a class. The direct way to check if a variable is a class, is to use the isclass() runtime service, from Python’s inspect module.  Use isclass() in conjunction with Python’s isinstance() built-in function, to examine a variable. Both of these return a Boolean …

How to Check Whether a Variable is a Class or Not? Read More »

How To Remove All Non-Alphabet Characters From A String?

💡 Summary: This blog explores the steps to remove all non-alphabet characters from a given string. The ‘re’ module in Python provides regular expression operations, to process text. One uses these operations to manipulate text in strings. The compile() method in conjunction with the sub() method can remove all non-alphabet characters from a given string. Note: …

How To Remove All Non-Alphabet Characters From A String? Read More »

What’s New in Python 3.9

Each year, volunteers from all over the world, work on improvements to the Python Language. The official Python 3.9 version was released on October 5, 2020. This version is an improvement made to Python 3.8. The official, detailed explanation of these improvements is available at the Python Website. This blog article attempts to explain these …

What’s New in Python 3.9 Read More »

Python’s NameError: name ‘xxx’ is not defined — How to Fix This Stupid Bug?

The Python interpreter throws the NameError exception if it encounters an undefined variable or function name. To fix it, you must figure out why the variable is not defined—the most frequent bugs are (1) to use the variable or function name in the code before it was defined, or (2) to misspell the name in …

Python’s NameError: name ‘xxx’ is not defined — How to Fix This Stupid Bug? Read More »

How To Eliminate All The Whitespace From A String?

In this article, you’ll learn the ultimate answer to the following question: How To Eliminate All The Whitespace From A String—on Both Ends, and In-Between Words? Summary: Use the string methods join(), split(), strip(), rstrip(), lstrip() and or replace()—in specific combinations—to remove any whitespace in a given string. The simplest way to remove all whitespaces …

How To Eliminate All The Whitespace From A String? Read More »