We'll practice using a scikit-learn model for linear regression. You will do something similar in this week's assignment (but with a logistic regression model).
First, import LinearRegression
, which is a Python 'class'.
# Import the module 'LinearRegression' from sklearn
from sklearn.linear_model import LinearRegression
Next, use the class to create an object of type LinearRegression.
# Create an object of type LinearRegression
model = LinearRegression()
model
Generate some data by importing a module 'load_data', which is implemented for you. The features in `X' are:
The labels in y
indicate whether the patient has a disease (diabetic retinopathy).
# Import the load_data function from the utils module
from utils import load_data
# Generate features and labels using the imported function
X, y = load_data(100)
Explore the data by viewing the features and the labels
# View the features
X.head()
# Plot a histogram of the Age feature
X['Age'].hist();
# Plot a histogram of the systolic blood pressure feature
X['Systolic_BP'].hist();
# Plot a histogram of the diastolic blood pressure feature
X['Diastolic_BP'].hist();
# Plot a histogram of the cholesterol feature
X['Cholesterol'].hist();
Also take a look at the labels
# View a few values of the labels
y.head()
# Plot a histogram of the labels
y.hist();
Fit the LinearRegression using the features in X
and the labels in y
. To "fit" the model is another way of saying that we are training the model on the data.
# Fit the linear regression model
model.fit(X, y)
model
# View the coefficients of the model
model.coef_
In the assignment, you will do something similar, but using a logistic regression, so that the output of the prediction will be bounded between 0 and 1.