Repository: scikit-learn/scikit-learn
Pull request: [MRG] pulling data from openml.org rather than original data source
Fixes #11858 

#### What does this implement/fix? Explain your changes.
This pulls data from openml.org rather than the original data source. 

#### Any other comments?
The dataset has spent several days on openml.org but is still "in_preparation". Data can be pulled via `fetch_openml`, but gives a warning about the "in_preparation" status of the dataset's current version. `plot_gpr_co2` is technically functional, but need to get dataset to "active" state.

Left to-do:
- More efficient aggregation of monthly sum averages
- Upload additional versions of arff file to get dataset activated by openml admins



Problem statement:
Upload Mauna Loa CO2 data to OpenML.org
examples/gaussian_process/plot_gpr_co2.py relies on a dataset that we used to fetch from mldata.org. Now we download it from its original source, but that server may not be reliable, etc. We also process only the monthly averages from a weekly reading.

We should have this data on openml. I don't know whether we should try to replicate the form it was in on mldata, or create something new.

Hints from issue discussion:
Hi @jnothman, is it cool if I help on this? 

Since `load_mauna_loa_atmospheric_co2()` only outputs the date and co2 data (and mldata only has the two), are you thinking have just those two features on openml? Or upload the full dataset from its original source and parse as needed? 
We also only use monthly averages. I'd upload as much detail as I can, but
maybe make an aggregated version available

Commit message: fixing pep8 issues

Patch to review:
diff --git a/examples/gaussian_process/plot_gpr_co2.py b/examples/gaussian_process/plot_gpr_co2.py
index 8170de01898dc..5c25d71d45fcf 100644
--- a/examples/gaussian_process/plot_gpr_co2.py
+++ b/examples/gaussian_process/plot_gpr_co2.py
@@ -66,7 +66,7 @@
 import numpy as np
 
 from matplotlib import pyplot as plt
-
+from sklearn.datasets import fetch_openml
 from sklearn.gaussian_process import GaussianProcessRegressor
 from sklearn.gaussian_process.kernels \
     import RBF, WhiteKernel, RationalQuadratic, ExpSineSquared
@@ -80,28 +80,24 @@
 
 
 def load_mauna_loa_atmospheric_c02():
-    url = ('http://cdiac.ess-dive.lbl.gov/'
-           'ftp/trends/co2/sio-keel-flask/maunaloa_c.dat')
+    ml_data = fetch_openml(data_id=41187)
     months = []
     ppmv_sums = []
     counts = []
-    for line in urlopen(url):
-        line = line.decode('utf8')
-        if not line.startswith('MLO'):
-            # ignore headers
-            continue
-        station, date, weight, flag, ppmv = line.split()
-        y = date[:2]
-        m = date[2:4]
-        month_float = (int(('20' if y < '20' else '19') + y) +
-                       (int(m) - 1) / 12)
-        if not months or month_float != months[-1]:
-            months.append(month_float)
-            ppmv_sums.append(float(ppmv))
+
+    y = ml_data.data[:, 0]
+    m = ml_data.data[:, 1]
+    month_float = y + (m - 1) / 12
+    ppmvs = ml_data.target
+
+    for i in range(len(ppmvs)):
+        if not months or month_float[i] != months[-1]:
+            months.append(month_float[i])
+            ppmv_sums.append(ppmvs[i])
             counts.append(1)
         else:
             # aggregate monthly sum to produce average
-            ppmv_sums[-1] += float(ppmv)
+            ppmv_sums[-1] += float(ppmvs[i])
             counts[-1] += 1
 
     months = np.asarray(months).reshape(-1, 1)


Code review comments:
diff_hunk: @@ -80,28 +80,24 @@
 
 
 def load_mauna_loa_atmospheric_c02():
-    url = ('http://cdiac.ess-dive.lbl.gov/'
-           'ftp/trends/co2/sio-keel-flask/maunaloa_c.dat')
+    ml_data = fetch_openml(data_id=41187)
     months = []
     ppmv_sums = []
     counts = []
-    for line in urlopen(url):
-        line = line.decode('utf8')
-        if not line.startswith('MLO'):
-            # ignore headers
-            continue
-        station, date, weight, flag, ppmv = line.split()
-        y = date[:2]
-        m = date[2:4]
-        month_float = (int(('20' if y < '20' else '19') + y) +
-                       (int(m) - 1) / 12)
-        if not months or month_float != months[-1]:
-            months.append(month_float)
-            ppmv_sums.append(float(ppmv))
+
+    y = ml_data.data[:, 0]
+    m = ml_data.data[:, 1]
+    month_float = y + (m - 1) / 12
+    ppmvs = ml_data.target
+
+    for i in range(len(ppmvs)):
+        if not months or month_float[i] != months[-1]:
+            months.append(month_float[i])
+            ppmv_sums.append(ppmvs[i])
             counts.append(1)
         else:
             # aggregate monthly sum to produce average
-            ppmv_sums[-1] += float(ppmv)
+            ppmv_sums[-1] += float(ppmvs[i])
path: examples/gaussian_process/plot_gpr_co2.py
text: @user1:
do we still need this `float`?

@author:
you're right, this is redundant

diff_hunk: @@ -80,28 +80,24 @@
 
 
 def load_mauna_loa_atmospheric_c02():
-    url = ('http://cdiac.ess-dive.lbl.gov/'
-           'ftp/trends/co2/sio-keel-flask/maunaloa_c.dat')
+    ml_data = fetch_openml(data_id=41187)
     months = []
     ppmv_sums = []
     counts = []
-    for line in urlopen(url):
-        line = line.decode('utf8')
-        if not line.startswith('MLO'):
-            # ignore headers
-            continue
-        station, date, weight, flag, ppmv = line.split()
-        y = date[:2]
-        m = date[2:4]
-        month_float = (int(('20' if y < '20' else '19') + y) +
-                       (int(m) - 1) / 12)
-        if not months or month_float != months[-1]:
-            months.append(month_float)
-            ppmv_sums.append(float(ppmv))
+
+    y = ml_data.data[:, 0]
+    m = ml_data.data[:, 1]
+    month_float = y + (m - 1) / 12
+    ppmvs = ml_data.target
+
+    for i in range(len(ppmvs)):
path: examples/gaussian_process/plot_gpr_co2.py
text: @user1:
You might as well just iterate over `zip(month_float, ppmvs)`

@author:
good idea.