from sklearn.datasets import load_boston
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

# Loading dataset
boston = load_boston()
boston_df = pd.DataFrame(boston.data, columns = boston.feature_names)
boston_df['price'] = boston.target
boston_df

X = boston.data
y = boston.target

# Evaluating the model
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Training
reg = LinearRegression()
reg.fit(x_train, y_train)
y_pred = reg.predict(x_test)
# Ploting
plt.scatter(y_test, y_pred)
plt.xlabel('Prices')
plt.ylabel('Predicted Prices')
plt.show()

#Mean square error (MSE) : to evaluating the model
from sklearn.metrics import  mean_squared_error
mse = mean_squared_error(y_test, y_pred)
print('\n\n mse: ', mse)


print(reg.score(x_test, y_test))

print(reg.score(x_test, y_test))

print(reg.score(x_test, y_test))

print(reg.score(x_test, y_test))

print(reg.score(x_test, y_test))

print(reg.score(x_test, y_test))
