{ "cells": [ { "cell_type": "markdown", "id": "8b420745", "metadata": {}, "source": [ "(lecture14:covariance)=\n", "# Covariance between two random variables\n", "\n", "The concept of covariance summarizes with a single number how two random variables $X$ and $Y$ vary together.\n", "And there are three possibilities:\n", "\n", "- if $X$ is increased, then $Y$ will likely increase,\n", "- if $Y$ is decreased, then $Y$ will likely decrease, and\n", "- $X$ and $Y$ are not linked.\n", "\n", "Before defining these concepts exactly, let's load the smart buildings dataset which will help us demonstrate the concept.\n", "Here we go:" ] }, { "cell_type": "code", "execution_count": 9, "id": "b1333a54", "metadata": { "tags": [ "hide-input", "hide-output" ] }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import seaborn as sns\n", "sns.set(rc={\"figure.dpi\":100, 'savefig.dpi':300})\n", "sns.set_context('notebook')\n", "sns.set_style(\"ticks\")\n", "from IPython.display import set_matplotlib_formats\n", "set_matplotlib_formats('retina', 'svg')\n", "import numpy as np\n", "import scipy.stats as st" ] }, { "cell_type": "code", "execution_count": 2, "id": "3aad2824", "metadata": { "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/html": [ "
\n", " | household | \n", "date | \n", "score | \n", "t_out | \n", "t_unit | \n", "hvac | \n", "
---|---|---|---|---|---|---|
0 | \n", "a1 | \n", "2018-01-07 | \n", "100.0 | \n", "4.283373 | \n", "66.693229 | \n", "246.473231 | \n", "
1 | \n", "a10 | \n", "2018-01-07 | \n", "100.0 | \n", "4.283373 | \n", "66.356134 | \n", "5.492116 | \n", "
2 | \n", "a11 | \n", "2018-01-07 | \n", "58.0 | \n", "4.283373 | \n", "71.549132 | \n", "402.094327 | \n", "
3 | \n", "a12 | \n", "2018-01-07 | \n", "64.0 | \n", "4.283373 | \n", "73.429514 | \n", "211.692244 | \n", "
4 | \n", "a13 | \n", "2018-01-07 | \n", "100.0 | \n", "4.283373 | \n", "63.923937 | \n", "0.850536 | \n", "