Confused with the flow

Screen Link:

My Code:

import numpy as np

lr = LinearRegression()[['Gr Liv Area']], train['SalePrice'])
from sklearn.metrics import mean_squared_error

train_predictions = lr.predict(train[['Gr Liv Area']])
test_predictions = lr.predict(test[['Gr Liv Area']])

train_mse = mean_squared_error(train_predictions, train['SalePrice'])
test_mse = mean_squared_error(test_predictions, test['SalePrice'])

train_rmse = np.sqrt(train_mse)
test_rmse = np.sqrt(test_mse)


What I expected to happen:

I don’t really understand the logic of the code from train_predictions = lr.predict(train[[‘Gr Liv Area’]])
on down.

Could someone explain what is going on at each line? Thanks

What actually happened:

Replace this line with the output/error

First, break down the code line-by-line, element-by-element -

  • What does train[['Gr Liv Area']] give you?
  • What is lr?
  • What is the predict() function used in lr.predict()?

Break the code down, print out the output when needed, check the documentation as needed.

After that, if you are still confused or getting stuck, ask questions based on where you got stuck.