線形回帰を本当はPythonで解きたいけど表計算で解けと言われたので


# 用いるデータ

例として <a href="http://mh.rgr.jp/memo/mq0111.htm" target="_blank">分子性物質のデータ（融点・沸点）</a> を使ってみましょう。分子量（molecular weight）から沸点（boiling point）を予測するという問題を解いてみたいと思います。


```python
import pandas as pd
data = [['HF', 19.5, 20.0],
        ['HCl', -84.9, 36.5],
        ['HBr', -67.0, 80.9],
        ['HI', -35.1, 127.9],
        ['H2O', 100.0, 18.0],
        ['H2S', -60.7, 34.1],
        ['H2Se', -42, 81.0],
        ['H2Te', -1.8, 129.6],
        ['NH3', -33.4, 17.0],
        ['PH3', -87, 34.0],
        ['AsH3', -55, 77.9],
        ['SbH3', -17.1, 124.8],
        ['CH4', -161.49, 16.0],
        ['SiH4', -111.8, 32.1],
        ['GeH4', -90, 76.6],
        ['SnH4', -52, 122.7],
        ['He', -268.934, 4.0],
        ['Ne', -246.048, 20.2],
        ['Ar', -185.7, 39.9],
        ['Kr', -152.3, 83.8],
        ['Xe', -108.1, 131.3],
       ]
df = pd.DataFrame(data, columns = ['molecule', 'boiling point', 'molecular weight'])
df
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
    </tr>
  </tbody>
</table>
</div>


回帰は y = f(x) という関係において関数 f を同定するという作業です。今回は分子量を x 沸点を y とします。そのときの f を求めてみましょう。

```python
X = df.loc[:, ['molecular weight']].as_matrix()
X
```




    array([[  20. ],
           [  36.5],
           [  80.9],
           [ 127.9],
           [  18. ],
           [  34.1],
           [  81. ],
           [ 129.6],
           [  17. ],
           [  34. ],
           [  77.9],
           [ 124.8],
           [  16. ],
           [  32.1],
           [  76.6],
           [ 122.7],
           [   4. ],
           [  20.2],
           [  39.9],
           [  83.8],
           [ 131.3]])




```python
Y = df['boiling point'].as_matrix()
Y
```




    array([  19.5  ,  -84.9  ,  -67.   ,  -35.1  ,  100.   ,  -60.7  ,
            -42.   ,   -1.8  ,  -33.4  ,  -87.   ,  -55.   ,  -17.1  ,
           -161.49 , -111.8  ,  -90.   ,  -52.   , -268.934, -246.048,
           -185.7  , -152.3  , -108.1  ])


まずは x と y の関係をプロットします。

```python
%matplotlib inline
import matplotlib.pyplot as plt
# 散布図
plt.figure(figsize=(5,4))
plt.scatter(X, Y, alpha=0.3)
for name, x, y in zip(df.loc[:, ['molecule']].as_matrix(), X, Y):
    plt.text(x, y, name[0], size=8)
plt.xlabel('molecular weight')
plt.ylabel('boiling point')
plt.grid()
plt.show()
```


![線形回帰を本当はPythonで解きたいけど表計算で解けと言われたので_4_0.png](https://qiita-image-store.s3.amazonaws.com/0/211162/c7e18302-35f5-4650-6a91-b1b7cef3cb68.png)

これを上手に回帰する直線を求めるという問題です。

# まずは一番便利な scikit-learn から

本当は scikit-learn を使うのが一番便利です。まずは線形回帰を実行するための学習器を定義します。

```python
from sklearn import linear_model
lr = linear_model.LinearRegression()
```

学習（フィッティング）を行います。

```python
lr.fit(X, Y)
```




    LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)


傾きと切片が決まれば直線が得られますが、回帰係数というのが傾きにあたります。

```python
# 回帰係数
lr.coef_
```




    array([ 0.55956295])


そして切片

```python
# 切片
lr.intercept_
```




    -117.75943870102266


つまり、得られた回帰直線は次のようになります。

```python
print("y = f(x) = wx + t; (w, t) = ({0}, {1})".format(lr.coef_[0], lr.intercept_))
```

    y = f(x) = wx + t; (w, t) = (0.5595629540025041, -117.75943870102266)


決定係数は、説明変数 x が従属変数 y のどれくらいを説明できるかを表す値で、1に近いほど相対的な残差が少ないことを表します。回帰方程式のあてはまりの良さの尺度として利用されます。

```python
# 決定係数R2
lr.score(X, Y)
```




    0.083634989644543967


さて、この数字は驚くほど低いわけですが、図示してみましょう。

```python
%matplotlib inline
import matplotlib.pyplot as plt
# 散布図
plt.figure(figsize=(5,4))
plt.scatter(X, Y, alpha=0.3)
 
# 回帰直線
plt.plot(X, lr.predict(X))
for name, x, y in zip(df.loc[:, ['molecule']].as_matrix(), X, Y):
    plt.text(x, y, name[0], size=8)
plt.xlabel('molecular weight')
plt.ylabel('boiling point')
plt.grid()
plt.show()
```


![線形回帰を本当はPythonで解きたいけど表計算で解けと言われたので_12_0.png](https://qiita-image-store.s3.amazonaws.com/0/211162/e2e87af0-3fad-6ec9-254a-c48f3d1fc7c0.png)


散布図を描いたときから既に想像できたことと思いますが、分子量と沸点の関係を直線で表すのは無理ゲーだということがよく分かります。

それはそれとして、この得られた回帰直線を使って、様々な分子量の化合物の沸点を予測してみましょう。

```python
lr.predict(200)
```




    array([-5.8468479])




```python
lr.predict([[150], [100]])
```




    array([-33.8249956, -61.8031433])


非常に疑わしいモデルですが、いちおう直線回帰モデルが完成しました。

# 次は、ガチPythonで。

さて、scikit-learn という便利なツールに頼ってると先生に「お前は本当に線形回帰の計算手法が分かっとんのかゴルァ」と言われてしまいますので、scikit-learn に頼らずに実装してみましょう。

```python
# 平均値を求める関数
def mean(list):
    sum = 0
    for x in list:
        sum += x
    return sum / len(list)
```


```python
# 分散を求める関数
def variance(list):
    ave = mean(list)
    sum = 0
    for x in list:
        sum += (x - ave) ** 2
    return sum / len(list)
```


```python
# 標準偏差を求める関数
import math
def standard_deviation(list):
    return math.sqrt(variance(list))
```


```python
# 共分散 = 偏差積の平均
def covariance(list1, list2): 
    mean1 = mean(list1)
    mean2 = mean(list2)
    sum = 0
    for d1, d2 in zip(list1, list2):
        sum += (d1 - mean1) * (d2 - mean2)
    return sum / len(list1)
```


```python
# 相関係数 = 共分散を list1, list2 の標準偏差で割ったもの
def correlation(list1, list2):
    return covariance(list1, list2) / (standard_deviation(list1) * standard_deviation(list2))
```


```python
# 回帰直線の傾き＝相関係数＊（（yの標準偏差）／（xの標準偏差））
def w_fit(xlist, ylist):
    return correlation(xlist, ylist) * standard_deviation(ylist) / standard_deviation(xlist)
```


```python
# y切片＝yの平均－（傾き＊xの平均）
def t_fit(xlist, ylist):
    return mean(ylist) - w_fit(xlist, ylist) * mean(xlist)
```


```python
# 回帰直線の式を表示
w = w_fit(X, Y)
t = t_fit(X, Y)
print("y = f(x) = wx + t; (w, t) = ({0}, {1})".format(w, t))
```

    y = f(x) = wx + t; (w, t) = ([ 0.55956295], [-117.7594387])



```python
# 回帰直線の式を関数として表現
def f(x):
    return w * x + t
```


```python
f(200)
```




    array([-5.8468479])




```python
f([[150], [100]])
```




    array([[-33.8249956],
           [-61.8031433]])




```python
# 決定係数R2
def r2(xlist, ylist):
    wa1 = 0.
    wa2 = 0.
    for x, y in zip(xlist, ylist):
        wa1 += (y - f(x))**2
        wa2 += (y - mean(ylist))**2
    return 1. - wa1 / wa2
```


```python
r2(X, Y)
```




    array([ 0.08363499])



# さて、表計算で解けと言われたので pandas で書いてみましょうか。

先生はそれでも許してくれません。「計算の途中過程を一個一個確認できるように表計算を使って解けやゴルァ」とおっしゃいますので、表計算といえば pandas ですよね先生！？

```python
import copy
from IPython.display import display
excel = copy.deepcopy(df)
excel
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
    </tr>
  </tbody>
</table>
</div>




```python
excel['y'] = excel['boiling point']
excel['x'] = excel['molecular weight']
mean_y = mean(excel['y'])
mean_x = mean(excel['x'])
display(excel, pd.DataFrame([[mean_y, mean_x]], columns=['y','x'], index=['mean']))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.3</td>
    </tr>
  </tbody>
</table>
</div>



```python
excel['y-mean(y)'] = [y - mean_y for y in excel['y']]
excel['x-mean(x)'] = [x - mean_x for x in excel['x']]
display(excel, pd.DataFrame([[mean_y, mean_x]], columns=['y','x'], index=['mean']))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.3</td>
    </tr>
  </tbody>
</table>
</div>



```python
excel['(y-mean(y))**2'] = [sa ** 2 for sa in excel['y-mean(y)']]
excel['(x-mean(x))**2'] = [sa ** 2 for sa in excel['x-mean(x)']]
display(excel, pd.DataFrame([[mean_y, mean_x]], columns=['y','x'], index=['mean']))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
      <th>(y-mean(y))**2</th>
      <th>(x-mean(x))**2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
      <td>10485.486935</td>
      <td>1789.29</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
      <td>4.005335</td>
      <td>665.64</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
      <td>252.767602</td>
      <td>345.96</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
      <td>2284.712535</td>
      <td>4303.36</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
      <td>33451.922268</td>
      <td>1962.49</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
      <td>492.780802</td>
      <td>795.24</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
      <td>1672.700935</td>
      <td>349.69</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
      <td>6576.993735</td>
      <td>4529.29</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
      <td>2450.118002</td>
      <td>2052.09</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
      <td>16.820935</td>
      <td>800.89</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
      <td>778.335602</td>
      <td>243.36</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
      <td>4329.464535</td>
      <td>3906.25</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
      <td>6176.597675</td>
      <td>2143.69</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
      <td>835.287068</td>
      <td>912.04</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
      <td>50.428935</td>
      <td>204.49</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
      <td>954.727602</td>
      <td>3648.16</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
      <td>34609.145248</td>
      <td>3398.89</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
      <td>26617.704967</td>
      <td>1772.41</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
      <td>10568.114135</td>
      <td>501.76</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
      <td>4816.545068</td>
      <td>462.25</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
      <td>635.107202</td>
      <td>4761.00</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.3</td>
    </tr>
  </tbody>
</table>
</div>



```python
variance_y = mean(excel['(y-mean(y))**2'])
variance_x = mean(excel['(x-mean(x))**2'])
sd_y = math.sqrt(variance_y)
sd_x = math.sqrt(variance_x)
display(excel, pd.DataFrame([[mean_y, mean_x], [variance_y, variance_x], [sd_y, sd_x]], 
                            columns=['y','x'], index=['mean', 'variance', 'sd']))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
      <th>(y-mean(y))**2</th>
      <th>(x-mean(x))**2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
      <td>10485.486935</td>
      <td>1789.29</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
      <td>4.005335</td>
      <td>665.64</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
      <td>252.767602</td>
      <td>345.96</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
      <td>2284.712535</td>
      <td>4303.36</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
      <td>33451.922268</td>
      <td>1962.49</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
      <td>492.780802</td>
      <td>795.24</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
      <td>1672.700935</td>
      <td>349.69</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
      <td>6576.993735</td>
      <td>4529.29</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
      <td>2450.118002</td>
      <td>2052.09</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
      <td>16.820935</td>
      <td>800.89</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
      <td>778.335602</td>
      <td>243.36</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
      <td>4329.464535</td>
      <td>3906.25</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
      <td>6176.597675</td>
      <td>2143.69</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
      <td>835.287068</td>
      <td>912.04</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
      <td>50.428935</td>
      <td>204.49</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
      <td>954.727602</td>
      <td>3648.16</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
      <td>34609.145248</td>
      <td>3398.89</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
      <td>26617.704967</td>
      <td>1772.41</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
      <td>10568.114135</td>
      <td>501.76</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
      <td>4816.545068</td>
      <td>462.25</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
      <td>635.107202</td>
      <td>4761.00</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.300000</td>
    </tr>
    <tr>
      <th>variance</th>
      <td>7050.465101</td>
      <td>1883.249524</td>
    </tr>
    <tr>
      <th>sd</th>
      <td>83.967048</td>
      <td>43.396423</td>
    </tr>
  </tbody>
</table>
</div>



```python
excel['(y-mean(y)) * (x-mean(x))'] = excel['y-mean(y)'] * excel['x-mean(x)']
display(excel, pd.DataFrame([[mean_y, mean_x], [variance_y, variance_x], [sd_y, sd_x]], 
                            columns=['y','x'], index=['mean', 'variance', 'sd']))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
      <th>(y-mean(y))**2</th>
      <th>(x-mean(x))**2</th>
      <th>(y-mean(y)) * (x-mean(x))</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
      <td>10485.486935</td>
      <td>1789.29</td>
      <td>-4331.463600</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
      <td>4.005335</td>
      <td>665.64</td>
      <td>51.634400</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
      <td>252.767602</td>
      <td>345.96</td>
      <td>295.715200</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
      <td>2284.712535</td>
      <td>4303.36</td>
      <td>3135.592533</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
      <td>33451.922268</td>
      <td>1962.49</td>
      <td>-8102.410933</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
      <td>492.780802</td>
      <td>795.24</td>
      <td>-626.002400</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
      <td>1672.700935</td>
      <td>349.69</td>
      <td>764.805067</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
      <td>6576.993735</td>
      <td>4529.29</td>
      <td>5457.940267</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
      <td>2450.118002</td>
      <td>2052.09</td>
      <td>-2242.289600</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
      <td>16.820935</td>
      <td>800.89</td>
      <td>116.067733</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
      <td>778.335602</td>
      <td>243.36</td>
      <td>435.219200</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
      <td>4329.464535</td>
      <td>3906.25</td>
      <td>4112.416667</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
      <td>6176.597675</td>
      <td>2143.69</td>
      <td>3638.778733</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
      <td>835.287068</td>
      <td>912.04</td>
      <td>872.820267</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
      <td>50.428935</td>
      <td>204.49</td>
      <td>-101.549067</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
      <td>954.727602</td>
      <td>3648.16</td>
      <td>1866.279467</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
      <td>34609.145248</td>
      <td>3398.89</td>
      <td>10845.859933</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
      <td>26617.704967</td>
      <td>1772.41</td>
      <td>6868.586933</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
      <td>10568.114135</td>
      <td>501.76</td>
      <td>2302.749867</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
      <td>4816.545068</td>
      <td>462.25</td>
      <td>-1492.128667</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
      <td>635.107202</td>
      <td>4761.00</td>
      <td>-1738.892000</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.300000</td>
    </tr>
    <tr>
      <th>variance</th>
      <td>7050.465101</td>
      <td>1883.249524</td>
    </tr>
    <tr>
      <th>sd</th>
      <td>83.967048</td>
      <td>43.396423</td>
    </tr>
  </tbody>
</table>
</div>



```python
covar_xy = mean(excel['(y-mean(y)) * (x-mean(x))'])
corr_xy = covar_xy / (sd_x * sd_y)
display(excel, pd.DataFrame([[mean_y, mean_x], [variance_y, variance_x], [sd_y, sd_x]], 
                            columns=['y','x'], index=['mean', 'variance', 'sd']),
       pd.DataFrame([covar_xy, corr_xy], index=['covariance', 'correlation'], columns=['x,y']))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
      <th>(y-mean(y))**2</th>
      <th>(x-mean(x))**2</th>
      <th>(y-mean(y)) * (x-mean(x))</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
      <td>10485.486935</td>
      <td>1789.29</td>
      <td>-4331.463600</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
      <td>4.005335</td>
      <td>665.64</td>
      <td>51.634400</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
      <td>252.767602</td>
      <td>345.96</td>
      <td>295.715200</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
      <td>2284.712535</td>
      <td>4303.36</td>
      <td>3135.592533</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
      <td>33451.922268</td>
      <td>1962.49</td>
      <td>-8102.410933</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
      <td>492.780802</td>
      <td>795.24</td>
      <td>-626.002400</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
      <td>1672.700935</td>
      <td>349.69</td>
      <td>764.805067</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
      <td>6576.993735</td>
      <td>4529.29</td>
      <td>5457.940267</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
      <td>2450.118002</td>
      <td>2052.09</td>
      <td>-2242.289600</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
      <td>16.820935</td>
      <td>800.89</td>
      <td>116.067733</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
      <td>778.335602</td>
      <td>243.36</td>
      <td>435.219200</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
      <td>4329.464535</td>
      <td>3906.25</td>
      <td>4112.416667</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
      <td>6176.597675</td>
      <td>2143.69</td>
      <td>3638.778733</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
      <td>835.287068</td>
      <td>912.04</td>
      <td>872.820267</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
      <td>50.428935</td>
      <td>204.49</td>
      <td>-101.549067</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
      <td>954.727602</td>
      <td>3648.16</td>
      <td>1866.279467</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
      <td>34609.145248</td>
      <td>3398.89</td>
      <td>10845.859933</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
      <td>26617.704967</td>
      <td>1772.41</td>
      <td>6868.586933</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
      <td>10568.114135</td>
      <td>501.76</td>
      <td>2302.749867</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
      <td>4816.545068</td>
      <td>462.25</td>
      <td>-1492.128667</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
      <td>635.107202</td>
      <td>4761.00</td>
      <td>-1738.892000</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.300000</td>
    </tr>
    <tr>
      <th>variance</th>
      <td>7050.465101</td>
      <td>1883.249524</td>
    </tr>
    <tr>
      <th>sd</th>
      <td>83.967048</td>
      <td>43.396423</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>x,y</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>covariance</th>
      <td>1053.796667</td>
    </tr>
    <tr>
      <th>correlation</th>
      <td>0.289197</td>
    </tr>
  </tbody>
</table>
</div>



```python
w = corr_xy * sd_y / sd_x
t = mean_y - w * mean_x
display(excel, pd.DataFrame([[mean_y, mean_x], [variance_y, variance_x], [sd_y, sd_x]], 
                            columns=['y','x'], index=['mean', 'variance', 'sd']),
        pd.DataFrame([covar_xy, corr_xy], index=['covariance', 'correlation'], columns=['x,y']),
        pd.DataFrame([[w, t]], columns=["w", "t"], index=["y = f(x) = wx + t"]))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
      <th>(y-mean(y))**2</th>
      <th>(x-mean(x))**2</th>
      <th>(y-mean(y)) * (x-mean(x))</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
      <td>10485.486935</td>
      <td>1789.29</td>
      <td>-4331.463600</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
      <td>4.005335</td>
      <td>665.64</td>
      <td>51.634400</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
      <td>252.767602</td>
      <td>345.96</td>
      <td>295.715200</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
      <td>2284.712535</td>
      <td>4303.36</td>
      <td>3135.592533</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
      <td>33451.922268</td>
      <td>1962.49</td>
      <td>-8102.410933</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
      <td>492.780802</td>
      <td>795.24</td>
      <td>-626.002400</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
      <td>1672.700935</td>
      <td>349.69</td>
      <td>764.805067</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
      <td>6576.993735</td>
      <td>4529.29</td>
      <td>5457.940267</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
      <td>2450.118002</td>
      <td>2052.09</td>
      <td>-2242.289600</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
      <td>16.820935</td>
      <td>800.89</td>
      <td>116.067733</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
      <td>778.335602</td>
      <td>243.36</td>
      <td>435.219200</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
      <td>4329.464535</td>
      <td>3906.25</td>
      <td>4112.416667</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
      <td>6176.597675</td>
      <td>2143.69</td>
      <td>3638.778733</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
      <td>835.287068</td>
      <td>912.04</td>
      <td>872.820267</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
      <td>50.428935</td>
      <td>204.49</td>
      <td>-101.549067</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
      <td>954.727602</td>
      <td>3648.16</td>
      <td>1866.279467</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
      <td>34609.145248</td>
      <td>3398.89</td>
      <td>10845.859933</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
      <td>26617.704967</td>
      <td>1772.41</td>
      <td>6868.586933</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
      <td>10568.114135</td>
      <td>501.76</td>
      <td>2302.749867</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
      <td>4816.545068</td>
      <td>462.25</td>
      <td>-1492.128667</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
      <td>635.107202</td>
      <td>4761.00</td>
      <td>-1738.892000</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.300000</td>
    </tr>
    <tr>
      <th>variance</th>
      <td>7050.465101</td>
      <td>1883.249524</td>
    </tr>
    <tr>
      <th>sd</th>
      <td>83.967048</td>
      <td>43.396423</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>x,y</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>covariance</th>
      <td>1053.796667</td>
    </tr>
    <tr>
      <th>correlation</th>
      <td>0.289197</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>w</th>
      <th>t</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>y = f(x) = wx + t</th>
      <td>0.559563</td>
      <td>-117.759439</td>
    </tr>
  </tbody>
</table>
</div>



```python
# 回帰直線の式を関数として表現
def f(x):
    return w * x + t
```


```python
excel['f(x)'] = f(excel['x'])
display(excel, pd.DataFrame([[mean_y, mean_x], [variance_y, variance_x], [sd_y, sd_x]], 
                            columns=['y','x'], index=['mean', 'variance', 'sd']),
        pd.DataFrame([covar_xy, corr_xy], index=['covariance', 'correlation'], columns=['x,y']),
        pd.DataFrame([[w, t]], columns=["w", "t"], index=["y = f(x) = wx + t"]))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
      <th>(y-mean(y))**2</th>
      <th>(x-mean(x))**2</th>
      <th>(y-mean(y)) * (x-mean(x))</th>
      <th>f(x)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
      <td>10485.486935</td>
      <td>1789.29</td>
      <td>-4331.463600</td>
      <td>-106.568180</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
      <td>4.005335</td>
      <td>665.64</td>
      <td>51.634400</td>
      <td>-97.335391</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
      <td>252.767602</td>
      <td>345.96</td>
      <td>295.715200</td>
      <td>-72.490796</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
      <td>2284.712535</td>
      <td>4303.36</td>
      <td>3135.592533</td>
      <td>-46.191337</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
      <td>33451.922268</td>
      <td>1962.49</td>
      <td>-8102.410933</td>
      <td>-107.687306</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
      <td>492.780802</td>
      <td>795.24</td>
      <td>-626.002400</td>
      <td>-98.678342</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
      <td>1672.700935</td>
      <td>349.69</td>
      <td>764.805067</td>
      <td>-72.434839</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
      <td>6576.993735</td>
      <td>4529.29</td>
      <td>5457.940267</td>
      <td>-45.240080</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
      <td>2450.118002</td>
      <td>2052.09</td>
      <td>-2242.289600</td>
      <td>-108.246868</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
      <td>16.820935</td>
      <td>800.89</td>
      <td>116.067733</td>
      <td>-98.734298</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
      <td>778.335602</td>
      <td>243.36</td>
      <td>435.219200</td>
      <td>-74.169485</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
      <td>4329.464535</td>
      <td>3906.25</td>
      <td>4112.416667</td>
      <td>-47.925982</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
      <td>6176.597675</td>
      <td>2143.69</td>
      <td>3638.778733</td>
      <td>-108.806431</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
      <td>835.287068</td>
      <td>912.04</td>
      <td>872.820267</td>
      <td>-99.797468</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
      <td>50.428935</td>
      <td>204.49</td>
      <td>-101.549067</td>
      <td>-74.896916</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
      <td>954.727602</td>
      <td>3648.16</td>
      <td>1866.279467</td>
      <td>-49.101064</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
      <td>34609.145248</td>
      <td>3398.89</td>
      <td>10845.859933</td>
      <td>-115.521187</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
      <td>26617.704967</td>
      <td>1772.41</td>
      <td>6868.586933</td>
      <td>-106.456267</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
      <td>10568.114135</td>
      <td>501.76</td>
      <td>2302.749867</td>
      <td>-95.432877</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
      <td>4816.545068</td>
      <td>462.25</td>
      <td>-1492.128667</td>
      <td>-70.868063</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
      <td>635.107202</td>
      <td>4761.00</td>
      <td>-1738.892000</td>
      <td>-44.288823</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.300000</td>
    </tr>
    <tr>
      <th>variance</th>
      <td>7050.465101</td>
      <td>1883.249524</td>
    </tr>
    <tr>
      <th>sd</th>
      <td>83.967048</td>
      <td>43.396423</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>x,y</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>covariance</th>
      <td>1053.796667</td>
    </tr>
    <tr>
      <th>correlation</th>
      <td>0.289197</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>w</th>
      <th>t</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>y = f(x) = wx + t</th>
      <td>0.559563</td>
      <td>-117.759439</td>
    </tr>
  </tbody>
</table>
</div>



```python
excel['(y-f(x))**2'] = (excel['y'] - excel['f(x)'])**2
display(excel, pd.DataFrame([[mean_y, mean_x], [variance_y, variance_x], [sd_y, sd_x]], 
                            columns=['y','x'], index=['mean', 'variance', 'sd']),
        pd.DataFrame([covar_xy, corr_xy], index=['covariance', 'correlation'], columns=['x,y']),
        pd.DataFrame([[w, t]], columns=["w", "t"], index=["y = f(x) = wx + t"]))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
      <th>(y-mean(y))**2</th>
      <th>(x-mean(x))**2</th>
      <th>(y-mean(y)) * (x-mean(x))</th>
      <th>f(x)</th>
      <th>(y-f(x))**2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
      <td>10485.486935</td>
      <td>1789.29</td>
      <td>-4331.463600</td>
      <td>-106.568180</td>
      <td>15893.185913</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
      <td>4.005335</td>
      <td>665.64</td>
      <td>51.634400</td>
      <td>-97.335391</td>
      <td>154.638946</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
      <td>252.767602</td>
      <td>345.96</td>
      <td>295.715200</td>
      <td>-72.490796</td>
      <td>30.148838</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
      <td>2284.712535</td>
      <td>4303.36</td>
      <td>3135.592533</td>
      <td>-46.191337</td>
      <td>123.017754</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
      <td>33451.922268</td>
      <td>1962.49</td>
      <td>-8102.410933</td>
      <td>-107.687306</td>
      <td>43134.016878</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
      <td>492.780802</td>
      <td>795.24</td>
      <td>-626.002400</td>
      <td>-98.678342</td>
      <td>1442.354459</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
      <td>1672.700935</td>
      <td>349.69</td>
      <td>764.805067</td>
      <td>-72.434839</td>
      <td>926.279451</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
      <td>6576.993735</td>
      <td>4529.29</td>
      <td>5457.940267</td>
      <td>-45.240080</td>
      <td>1887.040538</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
      <td>2450.118002</td>
      <td>2052.09</td>
      <td>-2242.289600</td>
      <td>-108.246868</td>
      <td>5602.053722</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
      <td>16.820935</td>
      <td>800.89</td>
      <td>116.067733</td>
      <td>-98.734298</td>
      <td>137.693756</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
      <td>778.335602</td>
      <td>243.36</td>
      <td>435.219200</td>
      <td>-74.169485</td>
      <td>367.469139</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
      <td>4329.464535</td>
      <td>3906.25</td>
      <td>4112.416667</td>
      <td>-47.925982</td>
      <td>950.241169</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
      <td>6176.597675</td>
      <td>2143.69</td>
      <td>3638.778733</td>
      <td>-108.806431</td>
      <td>2775.558397</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
      <td>835.287068</td>
      <td>912.04</td>
      <td>872.820267</td>
      <td>-99.797468</td>
      <td>144.060777</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
      <td>50.428935</td>
      <td>204.49</td>
      <td>-101.549067</td>
      <td>-74.896916</td>
      <td>228.103133</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
      <td>954.727602</td>
      <td>3648.16</td>
      <td>1866.279467</td>
      <td>-49.101064</td>
      <td>8.403829</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
      <td>34609.145248</td>
      <td>3398.89</td>
      <td>10845.859933</td>
      <td>-115.521187</td>
      <td>23535.491228</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
      <td>26617.704967</td>
      <td>1772.41</td>
      <td>6868.586933</td>
      <td>-106.456267</td>
      <td>19485.851914</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
      <td>10568.114135</td>
      <td>501.76</td>
      <td>2302.749867</td>
      <td>-95.432877</td>
      <td>8148.153524</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
      <td>4816.545068</td>
      <td>462.25</td>
      <td>-1492.128667</td>
      <td>-70.868063</td>
      <td>6631.160338</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
      <td>635.107202</td>
      <td>4761.00</td>
      <td>-1738.892000</td>
      <td>-44.288823</td>
      <td>4071.866330</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.300000</td>
    </tr>
    <tr>
      <th>variance</th>
      <td>7050.465101</td>
      <td>1883.249524</td>
    </tr>
    <tr>
      <th>sd</th>
      <td>83.967048</td>
      <td>43.396423</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>x,y</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>covariance</th>
      <td>1053.796667</td>
    </tr>
    <tr>
      <th>correlation</th>
      <td>0.289197</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>w</th>
      <th>t</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>y = f(x) = wx + t</th>
      <td>0.559563</td>
      <td>-117.759439</td>
    </tr>
  </tbody>
</table>
</div>



```python
r2 = 1. - sum(excel['(y-f(x))**2']) / sum(excel['(y-mean(y))**2'])
display(excel, pd.DataFrame([[mean_y, mean_x], [variance_y, variance_x], [sd_y, sd_x]], 
                            columns=['y','x'], index=['mean', 'variance', 'sd']),
        pd.DataFrame([covar_xy, corr_xy], index=['covariance', 'correlation'], columns=['x,y']),
        pd.DataFrame([[w, t, r2]], columns=["w", "t", "R2"], index=["y = f(x) = wx + t"]))
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>molecule</th>
      <th>boiling point</th>
      <th>molecular weight</th>
      <th>y</th>
      <th>x</th>
      <th>y-mean(y)</th>
      <th>x-mean(x)</th>
      <th>(y-mean(y))**2</th>
      <th>(x-mean(x))**2</th>
      <th>(y-mean(y)) * (x-mean(x))</th>
      <th>f(x)</th>
      <th>(y-f(x))**2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>HF</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>19.500</td>
      <td>20.0</td>
      <td>102.398667</td>
      <td>-42.3</td>
      <td>10485.486935</td>
      <td>1789.29</td>
      <td>-4331.463600</td>
      <td>-106.568180</td>
      <td>15893.185913</td>
    </tr>
    <tr>
      <th>1</th>
      <td>HCl</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-84.900</td>
      <td>36.5</td>
      <td>-2.001333</td>
      <td>-25.8</td>
      <td>4.005335</td>
      <td>665.64</td>
      <td>51.634400</td>
      <td>-97.335391</td>
      <td>154.638946</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HBr</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>-67.000</td>
      <td>80.9</td>
      <td>15.898667</td>
      <td>18.6</td>
      <td>252.767602</td>
      <td>345.96</td>
      <td>295.715200</td>
      <td>-72.490796</td>
      <td>30.148838</td>
    </tr>
    <tr>
      <th>3</th>
      <td>HI</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>-35.100</td>
      <td>127.9</td>
      <td>47.798667</td>
      <td>65.6</td>
      <td>2284.712535</td>
      <td>4303.36</td>
      <td>3135.592533</td>
      <td>-46.191337</td>
      <td>123.017754</td>
    </tr>
    <tr>
      <th>4</th>
      <td>H2O</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>100.000</td>
      <td>18.0</td>
      <td>182.898667</td>
      <td>-44.3</td>
      <td>33451.922268</td>
      <td>1962.49</td>
      <td>-8102.410933</td>
      <td>-107.687306</td>
      <td>43134.016878</td>
    </tr>
    <tr>
      <th>5</th>
      <td>H2S</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>-60.700</td>
      <td>34.1</td>
      <td>22.198667</td>
      <td>-28.2</td>
      <td>492.780802</td>
      <td>795.24</td>
      <td>-626.002400</td>
      <td>-98.678342</td>
      <td>1442.354459</td>
    </tr>
    <tr>
      <th>6</th>
      <td>H2Se</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>-42.000</td>
      <td>81.0</td>
      <td>40.898667</td>
      <td>18.7</td>
      <td>1672.700935</td>
      <td>349.69</td>
      <td>764.805067</td>
      <td>-72.434839</td>
      <td>926.279451</td>
    </tr>
    <tr>
      <th>7</th>
      <td>H2Te</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>-1.800</td>
      <td>129.6</td>
      <td>81.098667</td>
      <td>67.3</td>
      <td>6576.993735</td>
      <td>4529.29</td>
      <td>5457.940267</td>
      <td>-45.240080</td>
      <td>1887.040538</td>
    </tr>
    <tr>
      <th>8</th>
      <td>NH3</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>-33.400</td>
      <td>17.0</td>
      <td>49.498667</td>
      <td>-45.3</td>
      <td>2450.118002</td>
      <td>2052.09</td>
      <td>-2242.289600</td>
      <td>-108.246868</td>
      <td>5602.053722</td>
    </tr>
    <tr>
      <th>9</th>
      <td>PH3</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-87.000</td>
      <td>34.0</td>
      <td>-4.101333</td>
      <td>-28.3</td>
      <td>16.820935</td>
      <td>800.89</td>
      <td>116.067733</td>
      <td>-98.734298</td>
      <td>137.693756</td>
    </tr>
    <tr>
      <th>10</th>
      <td>AsH3</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>-55.000</td>
      <td>77.9</td>
      <td>27.898667</td>
      <td>15.6</td>
      <td>778.335602</td>
      <td>243.36</td>
      <td>435.219200</td>
      <td>-74.169485</td>
      <td>367.469139</td>
    </tr>
    <tr>
      <th>11</th>
      <td>SbH3</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>-17.100</td>
      <td>124.8</td>
      <td>65.798667</td>
      <td>62.5</td>
      <td>4329.464535</td>
      <td>3906.25</td>
      <td>4112.416667</td>
      <td>-47.925982</td>
      <td>950.241169</td>
    </tr>
    <tr>
      <th>12</th>
      <td>CH4</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-161.490</td>
      <td>16.0</td>
      <td>-78.591333</td>
      <td>-46.3</td>
      <td>6176.597675</td>
      <td>2143.69</td>
      <td>3638.778733</td>
      <td>-108.806431</td>
      <td>2775.558397</td>
    </tr>
    <tr>
      <th>13</th>
      <td>SiH4</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-111.800</td>
      <td>32.1</td>
      <td>-28.901333</td>
      <td>-30.2</td>
      <td>835.287068</td>
      <td>912.04</td>
      <td>872.820267</td>
      <td>-99.797468</td>
      <td>144.060777</td>
    </tr>
    <tr>
      <th>14</th>
      <td>GeH4</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-90.000</td>
      <td>76.6</td>
      <td>-7.101333</td>
      <td>14.3</td>
      <td>50.428935</td>
      <td>204.49</td>
      <td>-101.549067</td>
      <td>-74.896916</td>
      <td>228.103133</td>
    </tr>
    <tr>
      <th>15</th>
      <td>SnH4</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>-52.000</td>
      <td>122.7</td>
      <td>30.898667</td>
      <td>60.4</td>
      <td>954.727602</td>
      <td>3648.16</td>
      <td>1866.279467</td>
      <td>-49.101064</td>
      <td>8.403829</td>
    </tr>
    <tr>
      <th>16</th>
      <td>He</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-268.934</td>
      <td>4.0</td>
      <td>-186.035333</td>
      <td>-58.3</td>
      <td>34609.145248</td>
      <td>3398.89</td>
      <td>10845.859933</td>
      <td>-115.521187</td>
      <td>23535.491228</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Ne</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-246.048</td>
      <td>20.2</td>
      <td>-163.149333</td>
      <td>-42.1</td>
      <td>26617.704967</td>
      <td>1772.41</td>
      <td>6868.586933</td>
      <td>-106.456267</td>
      <td>19485.851914</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Ar</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-185.700</td>
      <td>39.9</td>
      <td>-102.801333</td>
      <td>-22.4</td>
      <td>10568.114135</td>
      <td>501.76</td>
      <td>2302.749867</td>
      <td>-95.432877</td>
      <td>8148.153524</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Kr</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-152.300</td>
      <td>83.8</td>
      <td>-69.401333</td>
      <td>21.5</td>
      <td>4816.545068</td>
      <td>462.25</td>
      <td>-1492.128667</td>
      <td>-70.868063</td>
      <td>6631.160338</td>
    </tr>
    <tr>
      <th>20</th>
      <td>Xe</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-108.100</td>
      <td>131.3</td>
      <td>-25.201333</td>
      <td>69.0</td>
      <td>635.107202</td>
      <td>4761.00</td>
      <td>-1738.892000</td>
      <td>-44.288823</td>
      <td>4071.866330</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>y</th>
      <th>x</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>mean</th>
      <td>-82.898667</td>
      <td>62.300000</td>
    </tr>
    <tr>
      <th>variance</th>
      <td>7050.465101</td>
      <td>1883.249524</td>
    </tr>
    <tr>
      <th>sd</th>
      <td>83.967048</td>
      <td>43.396423</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>x,y</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>covariance</th>
      <td>1053.796667</td>
    </tr>
    <tr>
      <th>correlation</th>
      <td>0.289197</td>
    </tr>
  </tbody>
</table>
</div>



<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>w</th>
      <th>t</th>
      <th>R2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>y = f(x) = wx + t</th>
      <td>0.559563</td>
      <td>-117.759439</td>
      <td>0.083635</td>
    </tr>
  </tbody>
</table>
</div>

先生！できました！（ドヤ）


続編として<a href="https://qiita.com/maskot1977/items/f32e1c887d0f2e4ec8f7">線形重回帰を本当はPythonで解きたいけど表計算で解けと言われたので</a>をお楽しみください。