# Import linear_model from sklearn.
import sklearn.linear_model as lm
# Create a linear regression model instance.
m = lm.LinearRegression()
# Let's use pandas to read a csv file and organise our data.
import pandas as pd
# Read the iris csv from online.
df = pd.read_csv('https://datahub.io/machine-learning/iris/r/iris.csv')
# Let's pretend we want to do linear regression on these variables to predict petal width.
x = df[['sepallength', 'sepalwidth', 'petallength']]
# Here's petal width.
y = df['petalwidth']
# Ask our model to fit the data.
m.fit(x, y)
# Here's our intercept.
print(' intercept: ',m.intercept_)
# Here's our coefficients, in order.
print('coefficients: ',m.coef_)
# See how good our fit is.
print(' score: ',m.score(x, y))