House Price Prediction
House Price Prediction
#Load the package to split the dataset into training and testing sets
from sklearn.model_selection import train_test_split
#We will split the data into two groups, with 80% as the training set and 20% as
the test set.
#(train_x, train_y) is the 80% training set, used to train the model,
#where x represents the data and y represents the answers (i.e., the actual house
prices).
#(test_x, test_y) is the 20% test set, used to validate the model's predictive
ability.
#random_state: Setting a random_state ensures that your results are reproducible
#shuffle: If shuffle is set to True, the data will be mixed up randomly before
splitting it into training and testing sets.
train_x, test_x, train_y, test_y = train_test_split(my_data.data,
my_data.target, test_size=0.2, random_state=42, shuffle=True)
#Retrieve the preloaded package 'Linear Regression Model' and store it in the
variable my_model.
my_model = LinearRegression()
#We can use the evaluation metric MSE (mean squared error) to assess the model's
actual error.
score = mean_squared_error(pred, test_y)
#A lower MSE score is better, indicating that the predicted values are close to the
actual answers
print(" MSE: ", score)
print("Regression Equation:")
print(equation)