Practical Data Analysis - Second Edition by 2016

Practical Data Analysis - Second Edition by 2016

Author:2016
Language: eng
Format: mobi, epub
Publisher: Packt Publishing


Lineal regression

If we want to predict a quantitative value, regression is a great tool due to it uses. It's an independent variable to explain the behavior of a phenomenon such as temperature, asset prices, house prices, and so on. Linear regression finds the best fitting in a straight line.

We use regression or forecast all the time in our daily lives: when we calculate the gas or the time required for a car trip based on previous data (distance, traffic, weather, and so on). In its simplest form, you can think of it in this way: first, get previous data from the phenomena, for example, how much time was spent on previous trips and what was the distance. Then, look at the values form, and try to find a metric to forecast the next value.

In this section, we will program a very simple example of linear regression using scikit-learn, which is a machine-learning library for Python. For this concrete example, we will use the Boston Housing dataset, which represents the data of 506 neighborhoods of Boston, and is included in the scikit-learn library or is available at https://archive.ics.uci.edu/ml/datasets/Housing.

First, we need to import all the required libraries: the pylab, linear_model, and boston datasets:

from pylab import * from sklearn import datasets from sklearn import linear_model from sklearn.cross_validation import train_test_split import numpy as np import matplotlib.pyplot as plt



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.