<jupyter_start><jupyter_text>performing linear least square fitting<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>generate some random data about the trend line<jupyter_code>#set a random number seed
np.random.seed(119)

#set number of data pts
npoints = 50

#set x
x = np.linspace(0, 10., npoints)

#set slope, intercept, and scatter rms
m = 2.0
b = 1.0
sigma = 2.0

#generate y pts
y = m*x + b + np.random.normal(scale=sigma, size=npoints)
#plot data
f = plt.figure(figsize=(7,7))
plt.errorbar(x, y, sigma, fmt='o')
plt.xlabel('x')
plt.ylabel('y')<jupyter_output><empty_output><jupyter_text>method 1 polyfit()<jupyter_code>m_fit, b_fit = np.poly1d(np.polyfit(x, y, 1, w=1./y_err))  #weight with uncertainties
print(m_fit, b_fit)

y_fit = m_fit * x + b_fit<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13264129181084197, 'fraction_numerical': 0.02306805074971165, 'mean_word_length': 6.114754098360656, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '204672', 'license': 'MIT', 'n_tokens_mistral': 371, 'n_tokens_neox': 355, 'n_words': 85, 'path': 'line fitting.ipynb', 'repo_name': 'hleal023/ASTR-119-Session6', 'size': '867'}