|
from sklearn.linear_model import LinearRegression |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.metrics import mean_squared_error |
|
import numpy as np |
|
|
|
|
|
X = np.array([[1000], [1500], [2000], [2500], [3000], [3500], [4000], [4500], [5000], [5500]]) |
|
y = np.array([50000, 75000, 100000, 125000, 150000, 175000, 200000, 225000, 250000, 275000]) |
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
|
|
|
|
|
model = LinearRegression() |
|
|
|
|
|
model.fit(X_train, y_train) |
|
|
|
|
|
y_pred = model.predict(X_test) |
|
|
|
|
|
mse = mean_squared_error(y_test, y_pred) |
|
coef = model.coef_[0] |
|
intercept = model.intercept_ |
|
score = model.score(X_test, y_test) |
|
|
|
|
|
def predict(sqft): |
|
return (model.predict([[sqft]])[0]).round(2) |
|
|
|
|
|
def get_model_details(): |
|
return {"mse": mse, "coef": coef, "intercept": intercept, "score": score} |
|
|