<jupyter_start><jupyter_text>Chapter 7===============================  1. Import Modules<jupyter_code>import pandas as pd
import numpy as np<jupyter_output><empty_output><jupyter_text>2. Load Dataset - Simple Variable<jupyter_code>df = pd.read_csv('./data/test.csv')
df.head()
X = df['x'].values.reshape(-1, 1)
y = df['y'].values<jupyter_output><empty_output><jupyter_text>3. Build Model<jupyter_code>import normal_equation_lr
import imp
imp.reload(normal_equation_lr)
lr = normal_equation_lr.LinearRegression(fit_intercept = True)
lr.fit(X, y)
lr.intercept
lr.coef
lr.predict(X)[:10]<jupyter_output><empty_output><jupyter_text>4. Validation<jupyter_code>from sklearn import linear_model
sk_lr = linear_model.LinearRegression(normalize = True)
sk_lr.fit(X, y)
sk_lr.intercept_
import numpy.testing as npt
npt.assert_almost_equal(sk_lr.intercept_, lr.intercept)
sk_lr.coef_
lr.coef
np.isclose(lr.coef, sk_lr.coef_)
df_test = pd.read_csv('./data/train.csv')
df_test.head()
X_test = df['x'].values.reshape(-1, 1)
lr.predict(X_test)[:5]
sk_lr.predict(X_test)[:5]<jupyter_output><empty_output><jupyter_text>5. Load Dataset - Multiple Variables<jupyter_code>df = pd.read_csv('./data/mlr09.csv')
df.head()
y = df['average_points_scored'].values
df.iloc[:, :-1].head()
X = df.iloc[:,:-1].values
X[:5]<jupyter_output><empty_output><jupyter_text>6. Rescaled<jupyter_code>mu_X = np.mean(X, axis = 0)
std_X = np.std(X, axis = 0)

rescaled_X = (X - mu_X) / std_X
rescaled_X[:5]<jupyter_output><empty_output><jupyter_text>7. Validation<jupyter_code>lr.fit(rescaled_X, y)
lr.coef
lr.intercept
sk_lr.fit(rescaled_X, y)
sk_lr.coef_
sk_lr.intercept_<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16977724262492475, 'fraction_numerical': 0.014449127031908489, 'mean_word_length': 7.61139896373057, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '477982', 'license': 'MIT', 'n_tokens_mistral': 720, 'n_tokens_neox': 703, 'n_words': 99, 'path': 'Chapter.7/4.ipynb', 'repo_name': 'alstn2468/Python_For_Machine_Learning', 'size': '1661'}