Building a multivariable regressor
In the previous section, we discussed how to build a regression model for a single variable. In this section, we will deal with multidimensional data. Create a new Python file and import the following packages:
import numpy as np from sklearn import linear_model import sklearn.metrics as sm from sklearn.preprocessing import PolynomialFeatures
We will use the file data_multivar_regr.txt
provided to you.
# Input file containing data input_file = 'data_multivar_regr.txt'
This is a comma-separated file, so we can load it easily with a one-line function call:
# Load the data from the input file data = np.loadtxt(input_file, delimiter=',') X, y = data[:, :-1], data[:, -1]
Split the data into training and testing:
# Split ...
Get Artificial Intelligence with Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.