-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathml8.py
More file actions
34 lines (26 loc) · 960 Bytes
/
ml8.py
File metadata and controls
34 lines (26 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
df = pd.read_csv('D:/MachineLearning/Boston.csv')
df.head(3)
X = df.drop(columns=['medv'], axis=1)
y = df['medv']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
print(X_train.shape)
print(y_train.shape)
print(X_test.shape)
print(y_test.shape)
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
sns.regplot(x=y_test, y=y_pred, scatter_kws={'s': 10}, line_kws={'color': 'red'})
plt.xlabel('Actual Values')
plt.ylabel('Predicted Values')
plt.title('Actual vs Predicted Values')
plt.show()
print('Root Mean Squared error:(RMSE)', np.sqrt(mean_squared_error(y_test, y_pred)))
print('R2-Square:', r2_score(y_test, y_pred))