<jupyter_start><jupyter_text>https://college.cengage.com/mathematics/brase/understandable_statistics/7e/students/datasets/slr/frames/slr06.html<jupyter_code>df = pd.read_csv("Datasets/AutoInsuranceSweden.csv") 
df.head()
df.dtypes
df.describe()
plt.scatter(df['Number of Claims'], df['Total payment'])
plt.xlabel('Number of claims')
plt.ylabel('Total payment')
X = df['Number of Claims']
Y = df['Total payment']
# standardize the data attributes
standardized_X = preprocessing.scale(X)
#standardize the target attribute
standardized_Y = preprocessing.scale(Y)
X_train, X_test, y_train, y_test = train_test_split(standardized_X, standardized_Y, test_size=0.25, random_state=42)
X_train = X_train.reshape(-1,1)
y_train = y_train.reshape(-1,1)
X_test = X_test.reshape(-1,1)
# Model initialization
regression_model = LinearRegression()
# Fit the data(train the model)
regression_model.fit(X_train, y_train)
# Predict
y_predicted = regression_model.predict(X_test)

# model evaluation
rmse = mean_squared_error(y_test, y_predicted)
r2 = r2_score(y_test, y_predicted)

# printing values
print('Slope:' ,regression_model.coef_)
print('Intercept:', regression_model.intercept_)
print('Root mean squared error: ', rmse)
print('R2 score: ', r2)

#print(accuracy_score(y_test, y_predicted))<jupyter_output>Slope: [[0.92016023]]
Intercept: [-0.03941964]
Root mean squared error:  0.16426914499408302
R2 score:  0.8480051329208176
{'fraction_non_alphanumeric': 0.12914608327452365, 'fraction_numerical': 0.05081157374735357, 'mean_word_length': 7.593939393939394, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, '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': '371995', 'license': 'MIT', 'n_tokens_mistral': 577, 'n_tokens_neox': 526, 'n_words': 97, 'path': 'Chapter05/Code_Files/AutoInsuranceSweden.ipynb', 'repo_name': 'bpbpublications/Hands-on-Supervised-Learning-With-Python', 'size': '1417'}