<jupyter_start><jupyter_text>Regresión lineal de la Diabetes<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets, linear_model
from sklearn.metrics import mean_squared_error, r2_score
diabetes = datasets.load_diabetes()
type(diabetes)
type(diabetes.data)
diabetes.data.shape
x = diabetes.data[:,np.newaxis, 2]
y = diabetes.target
x_train = x[:-60]
x_test = x[-60:]
y_train = y[:-60]
y_test = y[-60:]
mod = linear_model.LinearRegression()
mod.fit(x_train, y_train)
mod.coef_
mod.intercept_<jupyter_output><empty_output><jupyter_text>$$\tilde{y} = 940.05574082\cdot x + 152.80161883617347 $$<jupyter_code>plt.scatter(x_train, y_train, color = 'black')
plt.plot(x_train, mod.predict(x_train), color='blue', linewidth=3)
plt.show()<jupyter_output><empty_output><jupyter_text>$$MSE = \frac{\sum_{i=1}^n(y_i - \tilde{y_i})^2}{n}$$<jupyter_code>mean_squared_error(y_train, mod.predict(x_train))
r2_score(y_train, mod.predict(x_train))<jupyter_output><empty_output><jupyter_text>Testing<jupyter_code>y_pred = mod.predict(x_test)
mean_squared_error(y_test, y_pred)
r2_score(y_test, y_pred)
plt.scatter(x_train, y_train, color = 'black')
plt.scatter(x_test, y_test, color = "red")
plt.plot(x_train, mod.predict(x_train), color='blue', linewidth=3)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15238817285822592, 'fraction_numerical': 0.03335860500379075, 'mean_word_length': 8.850746268656716, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '77963', 'license': 'MIT', 'n_tokens_mistral': 591, 'n_tokens_neox': 545, 'n_words': 81, 'path': 'scripts/tema10/01-diabetes.ipynb', 'repo_name': 'Adipiz/EstadisticaDescriptiva', 'size': '1319'}