File size: 1,122 Bytes
b59614d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
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

# Create a small dataset with 10 rows representing house prices
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])

# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create an instance of the Linear Regression model
model = LinearRegression()

# Train the model on the training data
model.fit(X_train, y_train)

# Make predictions on the testing data
y_pred = model.predict(X_test)

# Evaluate the model's performance
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}