<jupyter_start><jupyter_text>1.0 Loading the Libraries<jupyter_code>from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>2.0 The Data<jupyter_code>data = {
    'x1': [1,2,3,5,6,7,9,13,15,20],
    'x2': [10,20,30,50,60,70,90,130,150,200]
}
x = pd.DataFrame(data)
y = np.array([2,3,4,6,6,7,8,10,12,13])
y<jupyter_output><empty_output><jupyter_text>3.0 The Model<jupyter_code>lr_model = LinearRegression()

fit = lr_model.fit(x,y)
fit
pred = fit.predict(x)
pred<jupyter_output><empty_output><jupyter_text>4.0 Comparison of actual and predicted<jupyter_code>comp_data = {'actual': y, "predicted": pred}
df = pd.DataFrame(comp_data)
df<jupyter_output><empty_output><jupyter_text>5.0 Model Performance<jupyter_code>print("Coefficient of determination: %.2f" %r2_score(y,pred))
print("Mean Squared error: %.2f" %mean_squared_error(y,pred))
print("Coefficients:", fit.coef_) # there are two coefficients since its a multiple model<jupyter_output>Coefficient of determination: 0.97
Mean Squared error: 0.40
Coefficients: [0.00582972 0.05829717]<jupyter_text>6.0 Model Visualization<jupyter_code>plt.scatter(x['x1'], y)
plt.plot(x['x1'], pred, color="black")
plt.plot(x['x2'], pred, color="purple")
plt.show()
thanks for watching the code is on github<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14523974982626825, 'fraction_numerical': 0.06532314107018763, 'mean_word_length': 8.536423841059603, 'pattern_counts': {'":': 1, '<': 24, '<?xml version=': 0, '>': 24, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '82258', 'license': 'MIT', 'n_tokens_mistral': 632, 'n_tokens_neox': 576, 'n_words': 106, 'path': '1.1 Multiple Linear Regression.ipynb', 'repo_name': 'clinton-mwachia/Machine-Learning-With-Python', 'size': '1439'}