-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
26 lines (21 loc) · 706 Bytes
/
Copy pathtest.py
File metadata and controls
26 lines (21 loc) · 706 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
import numpy as np
from sklearn.metrics import r2_score, mean_squared_error
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
import pandas as pd
import statsmodels.api as sm
# Extract data
data = pd.read_csv('jaybob.csv')
print(data.head())
x = data['Age'].values.reshape(-1, 1)
y = data['Odometer'].values.reshape(-1, 1)
# Build model
model = LinearRegression().fit(x, y)
X = np.linspace(np.min(x), np.max(x)).reshape(-1, 1)
yhat = model.predict(X) # predict using OLS
# Display regression plot
plt.scatter(x, y, color='blue', label='Samples')
plt.plot(X, yhat, color='red', label='Line of Regression')
plt.show()
# Get generalized statistics
x1 = sm.add_constant(x)