predict_house_prices / Training.py
AbdelrahmanRagab's picture
Create Training.py
771e003 verified
raw
history blame contribute delete
651 Bytes
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import pickle
# Load the dataset (assuming it's saved as 'housing.csv')
data = pd.read_csv('housing.csv')
# Split features and target variable
X = data.drop('price', axis=1)
y = data['price']
# Split the data 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)
# Train the linear regression model
model = LinearRegression()
model.fit(X_train, y_train)
# Save the trained model to a file
with open('model.pkl', 'wb') as file:
pickle.dump(model, file)