<jupyter_start><jupyter_text>Regression<jupyter_code>%reset
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import pandas as pd
from sklearn.linear_model import LinearRegression

# These are some parameters to make figures nice (and big)
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
plt.rcParams['figure.figsize'] = 16,8
params = {'legend.fontsize': 'x-large',
          'figure.figsize': (15, 5),
         'axes.labelsize': 'x-large',
         'axes.titlesize':'x-large',
         'xtick.labelsize':'x-large',
         'ytick.labelsize':'x-large'}
plt.rcParams.update(params)
#Generate some data:
Npoints=100;
beta=3
sigma_e=10;
x=np.linspace(0,10,Npoints).reshape(-1,1)


Nrealizations=1000


eps=stats.norm.rvs(loc=0,scale=sigma_e,size=Npoints).reshape(-1,1)
y_tilde=beta*x+eps


# fit the data and obtain a prediction yhat
reg=LinearRegression().fit(x.reshape(-1,1),y_tilde)
yhat=reg.predict(x);
r2=reg.score(x,y_tilde)

fig, ax = plt.subplots(1, 1,figsize=[8,8])
ax.plot(x,y_tilde)
ax.plot(x,yhat,'r')

print(np.var(beta*x))
print(r2)

np.shape(y_tilde)
x=np.linspace(0,10,Npoints,axis=-1).reshape(-1,1)
np.shape(x)
plot(x,y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1630794701986755, 'fraction_numerical': 0.03145695364238411, 'mean_word_length': 5.535135135135135, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '277859', 'license': 'CC0-1.0', 'n_tokens_mistral': 511, 'n_tokens_neox': 488, 'n_words': 83, 'path': 'content/Module02/.ipynb_checkpoints/M02_N02_Regression2-checkpoint.ipynb', 'repo_name': 'cdds-uiuc/simles-book', 'size': '1208'}