<jupyter_start><jupyter_text>Regresion LinealnEstimadores de mínimos cuadrados de $\alpha$ y $\beta$$b = \frac{S_{xy}}{S_{xx}}$$a = \widetilde{y} - b\widetilde{x}$donde las cantidades $S_{xy}$ y $S_{xx}$ están definidas como$S_{xy} = \sum (x_i - \widetilde{x})(y_i-\widetilde{y})=\sum x_i y_i - \frac{(\sum x_i)(\sum y_i)}{n}$y$S_{xx} = \sum (x_i - \widetilde{x})^2 = \sum x_i^2 - \frac {(\sum x_i)^2}{n} $$\widetilde{x}= \frac{\sum x_i}{n}$$\widetilde{y}= \frac{\sum y_i}{n}$<jupyter_code>calif = pd.read_csv("regresion_1.csv")
calif
x2 = [x**2 for x in calif["x"].values]
y2 = [x**2 for x in calif["y"].values]
xy = []
for i in range(len(calif["x"].values)):
    xy.append(calif["x"].values[i]*calif["y"].values[i])
calif["x2"]=x2
calif["xy"]=xy
calif["y2"]=y2
calif<jupyter_output><empty_output><jupyter_text>Totales<jupyter_code>tot=calif.sum()
tot<jupyter_output><empty_output><jupyter_text>$S_{xy}$<jupyter_code>sxy=tot["xy"]-((tot["x"]*tot["y"])/calif.shape[0])
sxy<jupyter_output><empty_output><jupyter_text>$S_{xx}$<jupyter_code>sxx = tot["x2"]-((tot["x"]**2)/calif.shape[0])
sxx<jupyter_output><empty_output><jupyter_text>$\widetilde{x}$<jupyter_code>x=tot["x"]/calif.shape[0]
x<jupyter_output><empty_output><jupyter_text>$\widetilde{y}$<jupyter_code>y=tot["y"]/calif.shape[0]
y
b= sxy/sxx
b
a = y -b*x
a<jupyter_output><empty_output><jupyter_text>La recta de Regresión de minímos cuadrados es $$\widehat{y}= a+bx= 40.78415521422797+ 0.7655618431689571x $$<jupyter_code>def model(x):
    return 40.78415521422797+0.7655618431689571*x

line=[]

for i in calif["x"].values:
    line.append(model(i))

    
plt.scatter(calif["x"], calif["y"],color='#003F72')
plt.plot(calif["x"].values, line)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22975301550832855, 'fraction_numerical': 0.0511200459506031, 'mean_word_length': 7.4975609756097565, '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': '593305', 'license': 'MIT', 'n_tokens_mistral': 859, 'n_tokens_neox': 802, 'n_words': 104, 'path': 'regresion_lineal.ipynb', 'repo_name': 'TRMIKO/estadistica', 'size': '1741'}