<jupyter_start><jupyter_text>Q.2 solve the following matrix using simultaneous equations in python  6x+2y−5z=13 3x+3y−2z=13 7x+5y−3z=26<jupyter_code>import numpy as np
#writing the simultanrous equations in numpy array form

A = np.array([[6,2,-5],[3,3,-2],[7,5,-3]])  
B = np.array([13,13,26])
#Finding the determinant of the matrix to check if the inverse of the matrix exists
np.linalg.det(A)
C = np.linalg.inv(A)
C
sol = np.dot(C,B)
sol<jupyter_output><empty_output><jupyter_text>Thus the solution of the given simultaneous equations is x = 2, y = 3, z = 1      Q.3 The following dataset of size n = 63 provides total payment (in thousands) for all the claims of Swedish Kronor for geographical zones in Sweden. The variables are y = total payment in thousands and x = number of claims. Find the intercept, coefficient value and error term for this regression problem. How would you convey these numbers in a business context?<jupyter_code>import pandas as pd
data = pd.read_csv('slr06-1.csv')
data.head()
X = data.iloc[:,:-1].values
Y = data.iloc[:,1].values
print(X.shape)
print(Y.shape)
from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 1/3, random_state = 0)
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, Y_train)
print('Coefficient = ', model.coef_)
print('Intercept = ',model.intercept_)
import matplotlib.pyplot as plt
plt.scatter(X, Y, color='blue')
plt.title('total payment in thousands VS number of claims')
plt.xlabel('number of claims')
plt.ylabel('total payment in thousands')
plt.show()
Y_predict = model.predict(X_test)
from sklearn.metrics import mean_squared_error,mean_absolute_error

print("Mean squared error = %.2f" %mean_squared_error(Y_test,Y_predict))

print("Mean absolute error = %.2f" %mean_absolute_error(Y_test,Y_predict))

print("Root mean squared error = %.2f" %np.sqrt(mean_squared_error(Y_test,Y_predict)))<jupyter_output>Mean squared error = 1476.80
Mean absolute error = 28.79
Root mean squared error = 38.43<jupyter_text>Intercept, coefficient value and error term for this regression problem are 20.18 , 3.4 & (RMSE - 38.43 & MAE - 28.79) respectively<jupyter_code>plt.scatter(X_test,Y_test,c='red')
plt.plot(X_test,Y_predict)
plt.title("Visulaizing the results")
plt.xlabel("number of claims")
plt.ylabel("total payment in thousands")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11557377049180328, 'fraction_numerical': 0.03114754098360656, 'mean_word_length': 5.954415954415954, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '128251', 'license': 'CC0-1.0', 'n_tokens_mistral': 900, 'n_tokens_neox': 826, 'n_words': 248, 'path': 'Regression/Simple_LR.ipynb', 'repo_name': 'anushpittu/ML_models', 'size': '2440'}