<jupyter_start><jupyter_text>Linear regression<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

from sklearn.datasets import load_boston<jupyter_output><empty_output><jupyter_text>Linear regression for house prices in Boston based on the number of rooms<jupyter_code>boston_dataset = load_boston()
print(boston_dataset.DESCR)
# Features 
X = np.array(boston_dataset.data[:, 5])
# Target
Y = np.array(boston_dataset.target)
# Plot the selected data
plt.scatter(X, Y, alpha=0.3)
plt.xlabel('average number of rooms per dwelling')
plt.ylabel('house-price')
plt.show()
# A column of ones is added for the independent term
X = np.array([np.ones(X.shape[0]), X]).T<jupyter_output><empty_output><jupyter_text>Minimization of the mean square error:$\beta = (X^{T}X)^{-1}X^{T}Y$<jupyter_code>B = np.linalg.inv(X.T @ X) @ X.T @ Y
# Plot results
plt.scatter(X.T[1], Y, alpha=0.3)
min_plot_x, max_plot_x = 4, 9
plt.plot([min_plot_x, max_plot_x], [B[0] + B[1] * min_plot_x, B[0] + B[1] * max_plot_x], c='red')
plt.xlabel('average number of rooms per dwelling')
plt.ylabel('house-price')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1486725663716814, 'fraction_numerical': 0.012389380530973451, 'mean_word_length': 6.54, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '57923', 'license': 'MIT', 'n_tokens_mistral': 461, 'n_tokens_neox': 443, 'n_words': 98, 'path': 'notebooks/from_scratch/linear_regression.ipynb', 'repo_name': 'lcambero/ml-playground', 'size': '1130'}