In previous recipes, we have seen how to create intervals based on variable values and distribution. Sometimes, however, we want to divide the variables into intervals, the boundaries of which are arbitrarily determined by the user. In this recipe, we will learn how to discretize a variable into user pre-defined intervals using pandas and the Boston House Prices dataset from scikit-learn.
Allocating the variable values in arbitrary intervals
How to do it...
Let's first import the necessary Python libraries and get the dataset ready:
- Import the required Python libraries and classes:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import load_boston
from sklearn.model_selection...