How to do it...

Let's see how to build a linear regressor in Python:

  1. Create a file called regressor.py and add the following lines:
filename = "VehiclesItaly.txt"X = []y = []with open(filename, 'r') as f:    for line in f.readlines():        xt, yt = [float(i) for i in line.split(',')]        X.append(xt)        y.append(yt)

We just loaded the input data into X and y, where X refers to the independent variable (explanatory variables) and y refers to the dependent variable (response variable). Inside the loop in the preceding code, we parse each line and split it based on the comma operator. We then convert them into floating point values and save them in X and y.

  1. When we build a machine learning model, we need a way to validate our model and check whether it ...

Get Python Machine Learning Cookbook - Second Edition 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.