Regression in R - Assignment-15
Practice Problems: Regression in R
Problem 1: Simple Linear Regression – Predicting Electricity Consumption
Problem Statement
A household wants to study the relationship between the number of electrical appliances used per day and its daily electricity consumption.
The following data are collected:
| Appliances Used | Electricity Consumption (Units) |
|---|---|
| 2 | 8 |
| 3 | 11 |
| 4 | 14 |
| 5 | 17 |
| 6 | 19 |
| 7 | 23 |
| 8 | 26 |
| 9 | 29 |
Tasks
Using Simple Linear Regression in R:
- Create a suitable data frame.
- Build a linear regression model to predict electricity consumption based on the number of appliances used.
- Obtain the regression equation.
- Display the model summary.
- Find the regression coefficients.
- Calculate the predicted electricity consumption for a household using 10 appliances.
- Obtain the predicted values and residuals.
- Plot the actual observations and the fitted regression line.
- Find and interpret the R-squared value.
Problem 2: Multiple Linear Regression – Predicting House Price
Problem Statement
A real estate company wants to predict the price of a house based on:
- Area of the house (square feet)
- Number of bedrooms
The following data are collected:
| House | Area (sq. ft.) | Bedrooms | Price (Lakhs) |
|---|---|---|---|
| 1 | 800 | 1 | 32 |
| 2 | 950 | 2 | 38 |
| 3 | 1100 | 2 | 45 |
| 4 | 1250 | 3 | 52 |
| 5 | 1400 | 3 | 58 |
| 6 | 1550 | 3 | 64 |
| 7 | 1700 | 4 | 72 |
| 8 | 1900 | 4 | 80 |
| 9 | 2100 | 4 | 88 |
| 10 | 2300 | 5 | 98 |
Tasks
Using Multiple Linear Regression in R:
- Create a data frame containing the given data.
-
Build a multiple linear regression model to predict house price using:
- Area
- Number of bedrooms
- Display the regression coefficients.
- Obtain the detailed model summary.
- Find the R-squared and Adjusted R-squared values.
-
Predict the price of a house having:
- Area = 1800 sq. ft.
- Bedrooms = 4
- Obtain predicted values and residuals.
- Create an Actual vs Predicted Price plot.
- Interpret the contribution of the independent variables to the predicted house price.
Problem 3: Logistic Regression – Predicting Customer Purchase
Problem Statement
An online shopping company wants to predict whether a customer will purchase a product based on the amount of time spent browsing the website.
The outcome is represented as:
-
0→ Did Not Purchase -
1→ Purchased
The following data are collected:
| Customer | Browsing Time (Minutes) | Purchase |
|---|---|---|
| 1 | 2 | 0 |
| 2 | 3 | 0 |
| 3 | 4 | 0 |
| 4 | 5 | 1 |
| 5 | 6 | 0 |
| 6 | 7 | 1 |
| 7 | 8 | 0 |
| 8 | 9 | 1 |
| 9 | 10 | 1 |
| 10 | 12 | 1 |
| 11 | 13 | 0 |
| 12 | 14 | 1 |
| 13 | 15 | 1 |
| 14 | 17 | 1 |
| 15 | 18 | 1 |
Tasks
Using Binary Logistic Regression in R:
- Create a data frame containing the browsing time and purchase information.
- Build a Logistic Regression model using browsing time as the predictor.
- Display the model summary and interpret the regression coefficient.
- Predict the probability of purchase for each customer.
- Convert predicted probabilities into class labels using a 0.5 threshold.
- Create a confusion matrix comparing actual and predicted classes.
- Calculate the classification accuracy.
- Predict whether a new customer who spends 11 minutes browsing is likely to purchase the product.
- Plot the actual observations and the Logistic Regression probability curve.
Comments
Post a Comment