<jupyter_start><jupyter_text><NAME>   Cognitive Systems Mathematics and Methods   Mathematics / Python Exercises 3: Exercise 1<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('fish.txt', skiprows=37)
X = data[:, 1:3]
y = data[:, 3:]
X1 = np.concatenate((np.ones((44,1)), X), axis=1)
X1
M = np.linalg.inv(np.dot(X.T, X)).dot(X.T).dot(y)
M
y_estimate = X.dot(M)
results = np.concatenate((y, y_estimate, y_estimate - y), axis=1)
results
results.shape
print('Linear regression mean absolute error:', np.sum(np.abs(y_estimate - y))/44)<jupyter_output>Linear regression mean absolute error: 534.722049449
{'fraction_non_alphanumeric': 0.1550632911392405, 'fraction_numerical': 0.04430379746835443, 'mean_word_length': 5.663157894736842, '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': '99129', 'license': 'MIT', 'n_tokens_mistral': 267, 'n_tokens_neox': 246, 'n_words': 59, 'path': 'Mathematics Python Exercises 3 Exercise 1.ipynb', 'repo_name': 'Joonakle/-Cognitive-Systems-Mathematics-and-Methods', 'size': '655'}