Model Building and Evaluation
Having crafted some wonderful features for our dataset, we're now ready for the grand finale—the part where we actually build our predictive model! Exciting, right? Let's dive in.
Data Splitting
The first order of business is to divide our dataset into training and testing sets. This way, we can evaluate how well our model performs on unseen data.
from sklearn.model_selection import train_test_split
# Features and target variable
X = df.drop('House_Price', axis=1)
y = df['House_Price']
# Split the data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Model Selection
For predicting house prices, a regression algorithm would be most appropriate. Let's start with a simple Linear Regression model.
from sklearn.linear_model import LinearRegression
# Initialize the model
model = LinearRegression()
# Train the model
model.fit(X_train, y_train)