开始使用免费开始使用

Explained variance

You saw that rent prices between Houston and Las Vegas are correlated. However, to what extent can the price change in one city explain the price change in another city? By computing R-squared you are able to precisely quantify this.

A NumPy array of rents has been loaded for Las Vegas (lasvegas_rents) and Houston (houston_rents), as well as the dates associated with each measurement. The packages pandas as pd, NumPy as np, Matplotlib as plt, and the stats package from SciPy have all been loaded for you.

本练习是课程的一部分

Foundations of Inference in Python

查看课程

练习说明

  • Compute the Pearson correlation coefficient between houston_rents and lasvegas_rents.
  • Print the square of the correlation coefficient.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Compute the correlation between Houston and Las Vegas
r, p_value = ____

# Print R-squared
____
编辑并运行代码