Upload test.py
Browse files
test.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# house_price_prediction.py
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from sklearn.model_selection import train_test_split
|
| 5 |
+
from sklearn.linear_model import LinearRegression
|
| 6 |
+
from sklearn.metrics import mean_squared_error
|
| 7 |
+
import joblib
|
| 8 |
+
|
| 9 |
+
# Generate some sample data
|
| 10 |
+
data = {'Size': [1400, 1600, 1700, 1875, 1100, 1550, 2350, 2450, 1425, 1700],
|
| 11 |
+
'Price': [245000, 312000, 279000, 308000, 199000, 219000, 405000, 324000, 319000, 255000]}
|
| 12 |
+
|
| 13 |
+
df = pd.DataFrame(data)
|
| 14 |
+
|
| 15 |
+
# Split the data into features (X) and target variable (y)
|
| 16 |
+
X = df[['Size']]
|
| 17 |
+
y = df['Price']
|
| 18 |
+
|
| 19 |
+
# Split the data into training and testing sets
|
| 20 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 21 |
+
|
| 22 |
+
# Train a linear regression model
|
| 23 |
+
model = LinearRegression()
|
| 24 |
+
model.fit(X_train, y_train)
|
| 25 |
+
|
| 26 |
+
# Make predictions on the test set
|
| 27 |
+
y_pred = model.predict(X_test)
|
| 28 |
+
|
| 29 |
+
# Evaluate the model
|
| 30 |
+
mse = mean_squared_error(y_test, y_pred)
|
| 31 |
+
print(f'Mean Squared Error: {mse}')
|
| 32 |
+
|
| 33 |
+
# Save the model
|
| 34 |
+
joblib.dump(model, 'house_price_model.joblib')
|