graphlab.linear_regression.LinearRegression¶

class graphlab.linear_regression.LinearRegression(self)

Linear regression is an approach for modeling a scalar target $$y$$ as a linear function of one or more explanatory variables denoted $$X$$.

Given a set of features $$x_i$$, and a label $$y_i$$, linear regression interprets the probability that the label is in one class as a linear function of a linear combination of the features.

$f_i(\theta) = \theta^T x + \epsilon_i$

where $$\epsilon_i$$ is noise. An intercept term is added by appending a column of 1’s to the features. Regularization is often required to prevent overfitting by penalizing models with extreme parameter values. The linear regression module supports l1 and l2 regularization, which are added to the loss function.

The composite objective being optimized for is the following:

$\min_{\theta} \sum_{i = 1}^{n} (\theta^Tx - y_i)^2 + \lambda_1 ||\theta||_1 + \lambda_2 ||\theta||^{2}_{2}$

where $$\lambda_1$$ is the l1_penalty and $$\lambda_2$$ is the l2_penalty.

This model cannot be constructed directly. Instead, use graphlab.linear_regression.create() to create an instance of this model. A detailed list of parameter options and code samples are available in the documentation for the create function.

Examples

# Load the data (From an S3 bucket)
>>> data =  graphlab.SFrame('https://static.turi.com/datasets/regression/houses.csv')

# Make a linear regression model
>>> model = graphlab.linear_regression.create(data, target='price', features=['bath', 'bedroom', 'size'])

# Extract the coefficients
>>> coefficients = model['coefficients']

# Make predictions
>>> predictions = model.predict(data)

# Evaluate the model
>>> results = model.evaluate(data)


Methods

 LinearRegression.evaluate(model, *args, **kwargs) Evaluate the model by making target value predictions and comparing to actual values. LinearRegression.get(field) Get the value of a given field. LinearRegression.get_current_options() A dictionary describing the options requested during training. LinearRegression.list_fields() List of fields stored in the model. LinearRegression.name() Returns the name of the model. LinearRegression.predict(dataset[, ...]) Return target value predictions for dataset, using the trained linear regression model. LinearRegression.save(location) Save the model. LinearRegression.show([view]) Visualize with GraphLab Canvas canvas. LinearRegression.summary([output]) Print a summary of the model.