<jupyter_start><jupyter_text>LASSO REGRESSION<jupyter_code>import pandas as pd 
import numpy as np
import mglearn
import matplotlib.pyplot as plt

from sklearn.linear_model import Ridge
from sklearn.linear_model import Lasso
from sklearn.model_selection import train_test_split

%matplotlib inline
X, y = mglearn.datasets.load_extended_boston()
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)<jupyter_output><empty_output><jupyter_text>Lasso Regression (alpha=1.0 parameter by default)<jupyter_code>lasso = Lasso().fit(X_train, y_train)
lasso
print('training set score: {:.2f}'.format(lasso.score(X_train, y_train)))
print('Test set score: {:.2f}'.format(lasso.score(X_test, y_test)))
print('Number of features used: {}'.format(np.sum(lasso.coef_ != 0)))<jupyter_output>Number of features used: 4<jupyter_text>Playing with alpha parameter 0.01<jupyter_code>lasso001 = Lasso(alpha=0.01, max_iter=100000).fit(X_train, y_train)
print('training set score: {:.2f}'.format(lasso001.score(X_train, y_train)))
print('test set score: {:.2f}'.format(lasso001.score(X_test, y_test)))
print('Number of features used: {}'. format(np.sum(lasso001.coef_!= 0)))<jupyter_output>Number of features used: 33<jupyter_text>Playing with alpha parameter 0.0001<jupyter_code>lasso00001 = Lasso(alpha=0.0001, max_iter=100000).fit(X_train, y_train)
print('Training set score: {:.2f}'.format(lasso00001.score(X_train, y_train)))
print('Test set score: {:.2f}'.format(lasso00001.score(X_test, y_test)))
print('Number of features used: {}'. format(np.sum(lasso00001.coef_!= 0)))
ridge = Ridge().fit(X_train, y_train)
ridge01 = Ridge(alpha=0.1).fit(X_train, y_train)

plt.plot(lasso.coef_, 's', label="Lasso alpha=1")
plt.plot(lasso001.coef_, '^', label="Lasso alpha=0.01")
plt.plot(lasso00001.coef_, 'v', label="Lasso alpha=0.0001")

plt.plot(ridge01.coef_, 'o', label='Ridge alpha=0.1')
plt.legend(ncol=2, loc=(0, 1.05))
plt.ylim(-25, 25)
plt.xlabel("Coefficient index")
plt.ylabel("Coefficient magnitude")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1592920353982301, 'fraction_numerical': 0.0535889872173058, 'mean_word_length': 8.084821428571429, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '468011', 'license': 'MIT', 'n_tokens_mistral': 877, 'n_tokens_neox': 784, 'n_words': 147, 'path': 'Coding_exercices/LASSO REGRESSION BOSTON HOUSING DATASET.ipynb', 'repo_name': 'FelipeChiriboga/s_a_projects', 'size': '2034'}