<jupyter_start><jupyter_text><jupyter_code>from sklearn.datasets import load_boston
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import Lasso
from sklearn.linear_model import Ridge

X, y = load_boston(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, 
                                                    random_state=42)
reg = LinearRegression()
reg.fit(X_train, y_train)
y_pred = reg.predict(X_test)
# calculating the cost
print('R^2 = {}' .format(reg.score(X_test, y_test)))
rmse = np.sqrt(mean_squared_error(y_test, y_pred))
print("Root Mean Squared Error: {}".format(rmse))
# using cross validation
cv_results = cross_val_score(reg, X, y, cv=5)
print(np.mean(cv_results))
# using lasso regression
lasso = Lasso(alpha=0.4, normalize=True)
lasso_coef = lasso.fit(X, y).coef_
print(lasso_coef)
# using Ridge regression
ridge = Ridge(alpha=0.4, normalize=True)
ridge.fit(X_train, y_train)

print(ridge.score(X_test, y_test))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10252237591537836, 'fraction_numerical': 0.008950366151342554, 'mean_word_length': 5.542553191489362, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '441013', 'license': 'Unlicense', 'n_tokens_mistral': 447, 'n_tokens_neox': 432, 'n_words': 96, 'path': 'supervised-learning-with-scikit-learn/Regression/Predict_Boston_GDP.ipynb', 'repo_name': 'prosarahgamal/DataCamp-Projects', 'size': '1229'}