code: from IPython.display import Image
  #%matplotlib inline
  
  from distutils.version import LooseVersion as Version
  from sklearn import __version__ as sklearn_version
  #Image(filename='./images/10_01.png', width=500)
  
  
  import pandas as pd
  
  df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/'
                   'housing/housing.data',
                   header=None,
                   sep='\s+')
  
  df.columns = ['CRIM', 'ZN', 'INDUS', 'CHAS', 
                'NOX', 'RM', 'AGE', 'DIS', 'RAD', 
                'TAX', 'PTRATIO', 'B', 'LSTAT', 'MEDV']
  df.head()
  
  df = pd.read_csv('https://raw.githubusercontent.com/rasbt/python-machine-learning-book/master/code/datasets/housing/housing.data',
                    header=None, sep='\s+')
  
  df.columns = ['CRIM', 'ZN', 'INDUS', 'CHAS', 
                'NOX', 'RM', 'AGE', 'DIS', 'RAD', 
                'TAX', 'PTRATIO', 'B', 'LSTAT', 'MEDV']
  df.head()
  
  import matplotlib.pyplot as plt
  import seaborn as sns
  
  
  sns.set(style='whitegrid', context='notebook')
  cols = ['LSTAT', 'INDUS', 'NOX', 'RM', 'MEDV']
  
  sns.pairplot(df[cols], size=2.5)
  plt.tight_layout()
  # plt.savefig('./figures/scatter.png', dpi=300)
  plt.show()
  
  import numpy as np
  
  
  cm = np.corrcoef(df[cols].values.T)
  sns.set(font_scale=1.5)
  hm = sns.heatmap(cm,
                   cbar=True,
                   annot=True,
                   square=True,
                   fmt='.2f',
                   annot_kws={'size': 15},
                   yticklabels=cols,
                   xticklabels=cols)
  
  # plt.tight_layout()
  # plt.savefig('./figures/corr_mat.png', dpi=300)
  plt.show()
  
  
  sns.reset_orig()
  #%matplotlib inline
  
  class LinearRegressionGD(object):
  
      def __init__(self, eta=0.001, n_iter=20):
          self.eta = eta
          self.n_iter = n_iter
  
      def fit(self, X, y):
          self.w_ = np.zeros(1 + X.shape[1])
          self.cost_ = []
  
          for i in range(self.n_iter):
              output = self.net_input(X)
              errors = (y - output)
              self.w_[1:] += self.eta * X.T.dot(errors)
              self.w_[0] += self.eta * errors.sum()
              cost = (errors**2).sum() / 2.0
              self.cost_.append(cost)
          return self
  
      def net_input(self, X):
          return np.dot(X, self.w_[1:]) + self.w_[0]
  
      def predict(self, X):
          return self.net_input(X)
  
  X = df[['RM']].values
  y = df['MEDV'].values
  
  
  
  from sklearn.preprocessing import StandardScaler
  
  
  sc_x = StandardScaler()
  sc_y = StandardScaler()
  X_std = sc_x.fit_transform(X)
  y_std = sc_y.fit_transform(y[:, np.newaxis]).flatten()
  
  
  
  lr = LinearRegressionGD()
  lr.fit(X_std, y_std)
  
  plt.plot(range(1, lr.n_iter+1), lr.cost_)
  plt.ylabel('SSE')
  plt.xlabel('Epoch')
  plt.tight_layout()
  # plt.savefig('./figures/cost.png', dpi=300)
  plt.show()
  
  
  def lin_regplot(X, y, model):
      plt.scatter(X, y, c='lightblue')
      plt.plot(X, model.predict(X), color='red', linewidth=2)    
      return
  lin_regplot(X_std, y_std, lr)
  plt.xlabel('Average number of rooms [RM] (standardized)')
  plt.ylabel('Price in $1000\'s [MEDV] (standardized)')
  plt.tight_layout()
  # plt.savefig('./figures/gradient_fit.png', dpi=300)
  plt.show()
  
apis: numpy.zeros pandas.read_csv matplotlib.pyplot.tight_layout matplotlib.pyplot.show matplotlib.pyplot.ylabel sklearn.preprocessing.StandardScaler numpy.dot matplotlib.pyplot.xlabel matplotlib.pyplot.scatter numpy.corrcoef