turicreate.linear_regression.LinearRegression

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 xi, and a label yi, linear regression interprets the probability that the label is in one class as a linear function of a linear combination of the features.

fi(θ)=θTx+ϵi

where ϵ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θni=1(θTxyi)2+λ1||θ||1+λ2||θ||22

where λ1 is the l1_penalty and λ2 is the l2_penalty.

This model cannot be constructed directly. Instead, use turicreate.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.

See also

create

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.