<jupyter_start><jupyter_text>Boston<jupyter_code>from sklearn.datasets import load_boston
from sklearn.linear_model import LinearRegression, Ridge, Lasso
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.preprocessing import PolynomialFeatures
boston = load_boston()
rows, cols = boston.data.shape
print(f'Boston dataset: {rows} rows, {cols} cols')
X_train, X_test, Y_train, Y_test = train_test_split(
    boston.data, boston.target, test_size=0.2)
lr = LinearRegression(normalize=True)
# lr.fit(X_train, Y_train)
print(f'Linear regression: {cross_val_score(lr, X_train, Y_train, cv=7).mean()}')
rg = Ridge(0.001, normalize=True)
print(f'Ridge regression: {cross_val_score(rg, X_train, Y_train, cv=7).mean()}')
ls = Lasso(0.001, normalize=True)
print(f'Lasso score: {cross_val_score(ls, X_train, Y_train, cv=7).mean()}')
# Polynomial features
lr_pf = LinearRegression(normalize=True)
pf = PolynomialFeatures(degree=2)
Xp = pf.fit_transform(X_train)
lr_pf.fit(Xp, Y_train)
print(f'Linear regression (polynomial features): {cross_val_score(lr_pf, X_train, Y_train, cv=7).mean()}')<jupyter_output>Linear regression: 0.7381135178144571
Ridge regression: 0.7381969094325223
Lasso score: 0.7384738650799826
Linear regression (polynomial features): 0.7381135178144571
{'fraction_non_alphanumeric': 0.12219644238205724, 'fraction_numerical': 0.06419180201082754, 'mean_word_length': 8.656716417910447, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '597310', 'license': 'MIT', 'n_tokens_mistral': 543, 'n_tokens_neox': 491, 'n_words': 97, 'path': 'machine-learning/boston/boston.ipynb', 'repo_name': 'nathanielng/python-snippets', 'size': '1293'}