December 2018
Intermediate to advanced
764 pages
18h 18m
English
To generate the dataset, we use the make_regression function from the datasets module of the sklearn library:
from sklearn import datasets as skdsX, y = skds.make_regression(n_samples=200, n_features=1, n_informative=1, n_targets=1, noise = 20.0)
This generates a dataset for regression with 200 sample values for one feature and one target each, with some noise added. As we are generating only one target, the function generates y with a one-dimensional NumPy Array; thus, we reshape y to have two dimensions:
if (y.ndim == 1): y = y.reshape(len(y),1)
We plot the generated dataset to look at the data with the following code:
import matplotlib.pyplot as pltplt.figure(figsize=(14,8))plt.plot(X,y,'b.')plt.title('Original Dataset') ...Read now
Unlock full access