ML Practical 04
ML Practical 04
to Machine Learning
Practical Session - 04
Steps of the process
01 Import Data
02 Clean the Data
03 Split the data to testing & Training
04 Design the model
05 Train the Model
06 Make Predictions
07 Evaluate and Improve
Today’s session
Simple linear regression model building
01 Split the data to testing & Training
02 Design the model
03 Train the Model
04 Make Predictions
01
Linear Regression
What is Linear Regression?
Linear regression is a statistical method used for modeling the
relationship between a dependent variable and one or more independent
variables by fitting a linear equation to the observed data.
How to predict house price according to the area of the house?
House area (m2) Price ($)
10000 4000
20000 5000
30000 6000
40000 7000
50000 8000
This step reads the Housing dataset from a CSV file into a pandas DataFrame named
data.
This prints the first few rows of the dataset(head), giving you an idea about its structure.
Step 4: Visualize the data
This step creates a scatter plot to visually represent the relationship between the 'Area'
and 'Price' columns.
Step 5: Prepare the data for training
This separates the independent variable (X - 'Area') and the dependent variable (y - 'Price').
Step 6: Split the data into training and testing sets
This step uses the trained model to make predictions on the test set.
● model.predict(X_test): This line uses the trained model to predict the dependent
variable (y) based on the independent variable (X_test), which represents the 'Area'
of the houses in the test set.
● y_pred : The predicted values are stored in the variable y_pred.
Step 9: Evaluate the model
This calculates the Mean Squared Error, a metric to evaluate how well the model is
performing on the test data.
Step 10: Visualize the regression line
This step visualizes the regression line along with the test set to understand how well
the model fits the data.
Step 11: Predict house price for user input
1. This step takes user input for the area of the house, converts it to a DataFrame with
the column name 'Area'.
2. Then uses the trained model to predict the house price based on the user's input.
3. The predicted price is then displayed.
4. This allows users to get a predicted house price for a specific area without having
to look at the entire dataset.
Thanks
Do you have any questions?