Course Content

Linear Regression with Python

## Linear Regression with Python

# Predict House Prices

Let's build a real-world example regression model. We have a file, `houses_simple.csv`

, that holds information about housing prices with its area as a feature.

Let's assign variables and visualize our dataset!

In the example with a person's height, it was much easier to imagine a line fitting the data well.

But now our data has much more variance since the target highly depends on many other things like age, location, interior, etc.

Anyway, the task is to build the line that best fits the data we have; it will show the trend. The `OLS`

class should be used for that. Soon we will learn how to add more features, it will make the prediction better!

Task

- Assign the
`'price'`

column of`df`

to`y`

. - Create the
`X_tilde`

matrix using the`add_constant()`

function from`statsmodels`

(imported as`sm`

). - Initialize the
`OLS`

object and train it. - Preprocess
`X_new`

array the same way as`X`

. - Predict the target for
`X_new_tilde`

matrix.

_{Once you've completed this task, click the Submit Task button below the code to check your solution.}

Task

- Assign the
`'price'`

column of`df`

to`y`

. - Create the
`X_tilde`

matrix using the`add_constant()`

function from`statsmodels`

(imported as`sm`

). - Initialize the
`OLS`

object and train it. - Preprocess
`X_new`

array the same way as`X`

. - Predict the target for
`X_new_tilde`

matrix.

_{Once you've completed this task, click the Submit Task button below the code to check your solution.}

Everything was clear?

# Predict House Prices

Let's build a real-world example regression model. We have a file, `houses_simple.csv`

, that holds information about housing prices with its area as a feature.

Let's assign variables and visualize our dataset!

In the example with a person's height, it was much easier to imagine a line fitting the data well.

But now our data has much more variance since the target highly depends on many other things like age, location, interior, etc.

Anyway, the task is to build the line that best fits the data we have; it will show the trend. The `OLS`

class should be used for that. Soon we will learn how to add more features, it will make the prediction better!

Task

- Assign the
`'price'`

column of`df`

to`y`

. - Create the
`X_tilde`

matrix using the`add_constant()`

function from`statsmodels`

(imported as`sm`

). - Initialize the
`OLS`

object and train it. - Preprocess
`X_new`

array the same way as`X`

. - Predict the target for
`X_new_tilde`

matrix.

_{Once you've completed this task, click the Submit Task button below the code to check your solution.}

Task

- Assign the
`'price'`

column of`df`

to`y`

. - Create the
`X_tilde`

matrix using the`add_constant()`

function from`statsmodels`

(imported as`sm`

). - Initialize the
`OLS`

object and train it. - Preprocess
`X_new`

array the same way as`X`

. - Predict the target for
`X_new_tilde`

matrix.

Everything was clear?

# Predict House Prices

Let's build a real-world example regression model. We have a file, `houses_simple.csv`

, that holds information about housing prices with its area as a feature.

Let's assign variables and visualize our dataset!

In the example with a person's height, it was much easier to imagine a line fitting the data well.

But now our data has much more variance since the target highly depends on many other things like age, location, interior, etc.

Anyway, the task is to build the line that best fits the data we have; it will show the trend. The `OLS`

class should be used for that. Soon we will learn how to add more features, it will make the prediction better!

Task

- Assign the
`'price'`

column of`df`

to`y`

. - Create the
`X_tilde`

matrix using the`add_constant()`

function from`statsmodels`

(imported as`sm`

). - Initialize the
`OLS`

object and train it. - Preprocess
`X_new`

array the same way as`X`

. - Predict the target for
`X_new_tilde`

matrix.

Task

- Assign the
`'price'`

column of`df`

to`y`

. - Create the
`X_tilde`

matrix using the`add_constant()`

function from`statsmodels`

(imported as`sm`

). - Initialize the
`OLS`

object and train it. - Preprocess
`X_new`

array the same way as`X`

. - Predict the target for
`X_new_tilde`

matrix.

Everything was clear?

`houses_simple.csv`

, that holds information about housing prices with its area as a feature.

Let's assign variables and visualize our dataset!

But now our data has much more variance since the target highly depends on many other things like age, location, interior, etc.

Anyway, the task is to build the line that best fits the data we have; it will show the trend. The `OLS`

class should be used for that. Soon we will learn how to add more features, it will make the prediction better!

Task

- Assign the
`'price'`

column of`df`

to`y`

. - Create the
`X_tilde`

matrix using the`add_constant()`

function from`statsmodels`

(imported as`sm`

). - Initialize the
`OLS`

object and train it. - Preprocess
`X_new`

array the same way as`X`

. - Predict the target for
`X_new_tilde`

matrix.