turicreate.linear_regression.LinearRegression — Turi Create API 6.4.1 documentation (original) (raw)

class turicreate.linear_regression. LinearRegression(model_proxy)

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 thel2_penalty.

This model cannot be constructed directly. Instead, useturicreate.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 = turicreate.SFrame('https://static.turi.com/datasets/regression/houses.csv')

Make a linear regression model

model = turicreate.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(dataset[, metric, …]) Evaluate the model by making target value predictions and comparing to actual values.
LinearRegression.export_coreml(filename) Export the model in Core ML format.
LinearRegression.predict(dataset[, …]) Return target value predictions for dataset, using the trained linear regression model.
LinearRegression.save(location) Save the model.
LinearRegression.summary([output]) Print a summary of the model.