Phase 5
Phase 5
Learning
Phase 5
Introduction:
• Loading the required dataset with pd.read_csv and select the features we want to use for
prediction (e.g., bedrooms, bathrooms, sqft_living, sqft_lot, floors, and zip code), as well as the
target variable (price).
• Split the data into a training set and a test set using the train_test_split function, with 80% of the
data used for training and 20% for testing.
• Create an instance of the linear regression model using LinearRegression(). We then perform
the model training by calling the function fit() with the training data.
• Once the model is trained, we make predictions for the test data set using predict and store the
results in y_pred.
To evaluate the performance of the model, we calculate the R^2 score using the score for the test set.
• Demonstrate how to predict the price of a new house by creating a new dataframe new_house
with the features of the house. We pass this dataframe to the model’s prediction function to
obtain the predicted price.
.
.
code :
# We will perform the data splitting into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X1, y1,
test_size=0.2, random_state=42)
# instance of the Linear Regression model creation
model = LinearRegression()
Out put :
Model R^2 Score: 0.5152176902631012
Predicted Price: 121215.61449578404
Conclusion:
In conclusion, using machine learning in Python is a powerful tool for predicting house prices. By
gathering and cleaning data, visualizing patterns, and training and evaluating our models, we can make
informed decisions in the dynamic world of real estate.
By leveraging advanced algorithms and data analysis, we can make accurate predictions and inform
decision-making processes. This approach empowers buyers, sellers, and investors to make informed
choices in a dynamic and competitive market, ultimate