<jupyter_start><jupyter_text>Course 2 week 1 lecture notebook 01 Create a Linear Model  Linear model using scikit-learnWe'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).[sklearn.linear_model.LinearRegression()](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html) First, import `LinearRegression`, which is a Python 'class'.<jupyter_code># Import the module 'LinearRegression' from sklearn
from sklearn.linear_model import LinearRegression<jupyter_output><empty_output><jupyter_text>Next, use the class to create an object of type LinearRegression.<jupyter_code># Create an object of type LinearRegression
model = LinearRegression()
model<jupyter_output><empty_output><jupyter_text>Generate some data by importing a module 'load_data', which is implemented for you.  The features in `X' are: - Age: (years)- Systolic_BP: Systolic blood pressure (mmHg)- Diastolic_BP: Diastolic blood pressure (mmHg)- Cholesterol: (mg/DL)The labels in `y` indicate whether the patient has a disease (diabetic retinopathy).- y = 1 : patient has retinopathy.- y = 0 : patient does not have retinopathy.<jupyter_code># 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)
print(len(X),len(y))<jupyter_output>100 100<jupyter_text>Explore the data by viewing the features and the labels<jupyter_code># 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();<jupyter_output><empty_output><jupyter_text>Also take a look at the labels<jupyter_code># View a few values of the labels
y.head()
# Plot a histogram of the labels
y.hist();<jupyter_output><empty_output><jupyter_text>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.<jupyter_code># Fit the linear regression model
model.fit(X, y)
model<jupyter_output><empty_output><jupyter_text>- View the coefficients of the trained model.- The coefficients are the 'weights' or $\beta$s associated with each feature- You'll use the coefficients for making predictions.$$\hat{y} = \beta_1x_1 + \beta_2x_2 + ... \beta_N x_N$$<jupyter_code># View the coefficients of the model
model.coef_<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09056886227544911, 'fraction_numerical': 0.007110778443113772, 'mean_word_length': 6.147058823529412, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '122803', 'license': 'Apache-2.0', 'n_tokens_mistral': 848, 'n_tokens_neox': 783, 'n_words': 299, 'path': 'AI for Medical Prognosis Week1/Datasets and backups/C2_W1_lecture_ex_01.ipynb', 'repo_name': 'ajitpande/AI-in-Medical-Prognosis', 'size': '2672'}