logo

Crowdly

Question 3 (25 marks) 3.1 Use Table 3.1   to answer the following questions: ...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Question 3 (25 marks)

3.1 Use Table 3.1  to answer the following questions:

Table 3.1

square_footage

num_bedrooms

age

location

price

800

2

10

Urban

350000

1200

3

5

Suburban

245000

1500

4

10

Urban

400000

1800

3

20

Urban

300000

2500

4

7

Rural

200000

900

2

25

Urban

250000

1100

5

15

Suburban

320000

2200

4

17

Rural

280000

square_footage is the area of the house in square feet.

num_bedrooms is the number of bedrooms.

age is the age of the house in years.

location is the location of the which is Urban, Suburban or Rural.

price is the cost of the house in ZAR (rand).

Using the following imported libraries:

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_squared_error, r2_score

from sklearn.preprocessing import LabelEncoder

Each question has a weighting of 5 marks.

(a )Write Python code snippet to load the houses data in a dataframe

(b) Write a Python code snippet to separate independent features/attributes and a target feature (price).                                                                                                                   

 

(c) Write a Python code snippet to apply label-encoding (one-hot encoding) to the location column. 

                                                                                                                           

(d) Write a Python code snippet to split the dataset into 80% train and 20% test.

(e) Write a Python code snippet to train a linear regression model (using the test dataset) and predict the house price of a house with 2000 square_footage, num_bedrooms: 5, age: 5 and location:  Urban.                                                                                                                             

(a                                                                                                                               

More questions like this

Want instant access to all verified answers on learning.richfield.ac.za?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!