FAQ: Multiple Linear Regression - Correlations

This community-built FAQ covers the “Correlations” exercise from the lesson “Multiple Linear Regression”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Machine Learning

FAQs on the exercise Correlations

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

In this exercise, why is the bedrooms variable coefficient = -302.7, meaning there is a pretty strong negative linear relationship between the number of bedrooms and the rent? Isn’t the rent supposed to increase as the number of bedrooms grows?

3 Likes

I don’t get this either. Help would be appreciated.

1 Like

I think that it depends on locality and the size of the apartment because if we have an apartment of small size then one would prefer to have less no. of bedrooms rather than having more no. of bedrooms.It’s just a guess.

How does looking at scatterplots help us understand if there’s correlation? I still don’t understand how to read scatterplots, especially since colors of data-points both axes are same, makes it really hard to discern the two

If you haven’t tried this, it might be easier to see by clearing the previous figure using plt.clf() before drawing another plot.

plt.scatter(df[['size_sqft']], df[['rent']], alpha=0.4)
plt.show()
plt.clf()

plt.scatter(df[['min_to_subway']], df[['rent']], alpha=0.4)
plt.show()
plt.clf()
3 Likes

I want to share this knowledge with fellow learners.

Pandas has an amazing method called df.corr() that calculates correlations between variables.

Paired with the excellent heatmap plot function from Seaborn, this can illustrate what variables are more influential on rent prices.

import seaborn as sns

sns.set(rc={"figure.figsize": (15, 10)})
sns.heatmap(df.corr(), cmap="seismic", annot=True, vmin=-1, vmax=1)

After glancing at the rent row or column we can see the most influential variables are

  1. size_sqft = 0.86
  2. bathrooms = 0.77
  3. bedrooms = 0.64

Having space and enough toilets and showers in Manhattan are a serious issue.

8 Likes

Thanks for sharing this method. So after checking the correlations between the variables, shall I build the multiple linear regression just using the ones having high correlation with the rent I’m going to predict? So to exclude the disturbance from the non-relevant variables. Wondering if this is the prevail way undertaken by industry. Thanks

So I can’t vouch for what they do in industry as a simple student only. It also depends on the nuances of the data. For example, if you were trying to predict prices for housing data, and for some reason you have similar variables measuring the same thing (e.g. sq ft and sq m) then it would be a good idea to just include one.

Another topic that comes to mind is standardization and normalization of variables.

Regression is an incredible useful tool but sometimes it requires a preliminary look at the variables and what each is measuring.

Again, I’m not an industry professional, yet.

plt.scatter(df[['size_sqft']], df[['rent']], alpha=0.4)

I don’t understand why we use two square brackets in df[[‘size_sqft’]] and df[[‘rent’]]. Shouldn’t it be df['size_sqft']?

1 Like

I used two square brackets according to the description of this exercise, but as you say, single square bracket is more suited here. We can plot the same graph in either case.

What is the difference between other linear regression methods (like ordinary least squares) and machine learning? At what point is a statistical method called ‘machine learning’ instead of being called a statistical method?

If given the same data, would an OLS linear regression and a machine learning linear regression return different parameters?

1 Like

What is the best way to tackle cathegorical variables like has_washer_dryer, has_doorman or has_dishwasher?
Since they can only have one of two possible values. The correlation graph has no so much information about this type of variables.

i’m joining to this question.

i plot the bedrooms vs. rent and plot on it the regrassion line - the corrolation is clearly positive.
uyi