fetch_california_housing()μ μ¬μ©νμ¬ μν λ°μ΄ν° μΈνΈλ₯Ό λ€μ΄λ‘λν μ μμ΅λλ€. μΈμ¦μκ° λ§λ£λ κ² κ°μ΅λκΉ?
print('scikit-learn λ²μ μ {}μ
λλ€.'.format(sklearn.__version__))
sklearn.datasetsμμ κ°μ Έμ€κΈ° fetch_california_housing
μ£Όν = fetch_california_housing()
Downloading Cal. housing from https://ndownloader.figshare.com/files/5976036 to /Users/test/scikit_learn_data
The scikit-learn version is 0.19.1.
---------------------------------------------------------------------------
SSLError Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1317 h.request(req.get_method(), req.selector, req.data, headers,
-> 1318 encode_chunked=req.has_header('Transfer-encoding'))
1319 except OSError as err: # timeout error
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked)
1238 """Send a complete request to the server."""
-> 1239 self._send_request(method, url, body, headers, encode_chunked)
1240
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1284 body = _encode(body, 'body')
-> 1285 self.endheaders(body, encode_chunked=encode_chunked)
1286
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked)
1233 raise CannotSendHeader()
-> 1234 self._send_output(message_body, encode_chunked=encode_chunked)
1235
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked)
1025 del self._buffer[:]
-> 1026 self.send(msg)
1027
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in send(self, data)
963 if self.auto_open:
--> 964 self.connect()
965 else:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in connect(self)
1399 self.sock = self._context.wrap_socket(self.sock,
-> 1400 server_hostname=server_hostname)
1401 if not self._context.check_hostname and self._check_hostname:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
400 server_hostname=server_hostname,
--> 401 _context=self, _session=session)
402
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in __init__(self, sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, family, type, proto, fileno, suppress_ragged_eofs, npn_protocols, ciphers, server_hostname, _context, _session)
807 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 808 self.do_handshake()
809
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in do_handshake(self, block)
1060 self.settimeout(None)
-> 1061 self._sslobj.do_handshake()
1062 finally:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in do_handshake(self)
682 """Start the SSL/TLS handshake."""
--> 683 self._sslobj.do_handshake()
684 if self.context.check_hostname:
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
During handling of the above exception, another exception occurred:
URLError Traceback (most recent call last)
<ipython-input-18-dc07bc139b51> in <module>()
1 print('The scikit-learn version is {}.'.format(sklearn.__version__))
2 from sklearn.datasets import fetch_california_housing
----> 3 housing = fetch_california_housing()
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/datasets/california_housing.py in fetch_california_housing(data_home, download_if_missing)
99 ARCHIVE.url, data_home))
100
--> 101 archive_path = _fetch_remote(ARCHIVE, dirname=data_home)
102
103 with tarfile.open(mode="r:gz", name=archive_path) as f:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/datasets/base.py in _fetch_remote(remote, dirname)
872 file_path = (remote.filename if dirname is None
873 else join(dirname, remote.filename))
--> 874 urlretrieve(remote.url, file_path)
875 checksum = _sha256(file_path)
876 if remote.checksum != checksum:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in urlretrieve(url, filename, reporthook, data)
246 url_type, path = splittype(url)
247
--> 248 with contextlib.closing(urlopen(url, data)) as fp:
249 headers = fp.info()
250
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
221 else:
222 opener = _opener
--> 223 return opener.open(url, data, timeout)
224
225 def install_opener(opener):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
524 req = meth(req)
525
--> 526 response = self._open(req, data)
527
528 # post-process response
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in _open(self, req, data)
542 protocol = req.type
543 result = self._call_chain(self.handle_open, protocol, protocol +
--> 544 '_open', req)
545 if result:
546 return result
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
502 for handler in handlers:
503 func = getattr(handler, meth_name)
--> 504 result = func(*args)
505 if result is not None:
506 return result
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in https_open(self, req)
1359 def https_open(self, req):
1360 return self.do_open(http.client.HTTPSConnection, req,
-> 1361 context=self._context, check_hostname=self._check_hostname)
1362
1363 https_request = AbstractHTTPHandler.do_request_
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1318 encode_chunked=req.has_header('Transfer-encoding'))
1319 except OSError as err: # timeout error
-> 1320 raise URLError(err)
1321 r = h.getresponse()
1322 except:
URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>
κΈμ, λλ κ·Έκ²μ΄ λ§€μ° μΌμμ μ΄κΈ°λ₯Ό λ°λλλ€. κ·Έκ²μ μ¬μ ν ββλ¬Έμ μ λκΉ?
μλ Jnothman
λλ κΈμμΌμ μ΄ λ¬Έμ λ₯Ό μ²μ μμλ€. μ¬μ ν κ°μ μ€λ₯κ° λ°μν©λλ€.
URLμ€λ₯: μλΆ μ€λ
λλ κ·Έλ° λ¬Έμ κ° μμ΅λλ€. μκ³κ° μ€μ λμ΄ μμ§ μμκ°μ?
μλͺ»λκ±°λ λκ°?
μλ Jnothman
μ λ λ§₯λΆνλ‘λ₯Ό μ¬μ©νκ³ μμ΅λλ€. λ΄ μ»΄ν¨ν°μ νμλ μκ°μ΄ λ§λ κ² κ°μ΅λλ€. λ°©κΈ μ½λλ₯Ό λ€μ μ€ννλλ° λμΌν μ€λ₯κ° λ°μν©λλ€.
λ΄ μκ³κ° μ¬λ°λ₯΄κ² μ€μ λμλμ§ νμΈνλ λ°©λ²μ μκ³ μμ΅λκΉ?
μ€λ
λλ μΈκΈνλ κ²μ μμλ€. λλ μ½λλ₯Ό λ³΄μ§ μμμ§λ§ μ΄λ―Έ λ°μ΄ν° μΈνΈλ₯Ό λ‘컬 λμ€ν¬μ λ€μ΄λ‘λνλ€λ©΄ μ€μ λ‘ κ°μ Έμ€μ§ μμ κ²μ΄λ―λ‘ μλ§λ κ·Έκ²μ΄ λΉμ μ μν΄ μλνλ μ΄μ μΌ κ²μ λλ€
μ΄μνκ²λ νμ€ν μ¬νν μ μκ³ ~/scikit_learn_data
μμ cal_housing λ°μ΄ν°λ₯Ό μμ νλμ§ νμΈνμ¬ scikit-learnμμ λ¬Έμ κ° λμ§ μλ κ² κ°μ΅λλ€. λλ μ΄κ²μ λ«μ κ²μ
λλ€. @AEDWIP λ¬Έμ λ₯Ό ν΄κ²°ν μ μλ κ²½μ°μ λλΉνμ¬ μΆκ° μ 보λ₯Ό μ 곡νμμμ€.
λΉμ·ν λ¬Έμ κ° λ°μνμ΅λλ€ - Mac Book Pro, High Sierra.
μ΄ SSL μΈμ¦μμ λν μ λ¬Έκ°λ μλμ§λ§ μμμ μΈκΈν λλ‘ μ΄κ²μ΄ scikit-learnκ³Ό κ΄λ ¨μ΄ μλ€κ³ μκ°νμ§ μμ΅λλ€.
μ΄ μ€λν«μμ λμΌν μ€λ₯κ° λ°μν©λκΉ?
from six.moves.urllib.request import urlretrieve
urlretrieve('https://ndownloader.figshare.com/files/5976036')
μΌμ !
λ¬Έμ λ₯Ό μ°Ύμμ΅λλ€. Macμ python 3.6μλ μ€μΉ ν λ¨κ³κ° νμν©λλ€.
$ less /Applications/Python\ 3.6/ReadMe.rtf
" μ΄μ 릴리μ€μ λ¬λ¦¬ λ μ΄μ μ¬μ©λμ§ μλ Apple μ 곡 OpenSSL λΌμ΄λΈλ¬λ¦¬λ λ μ΄μ μ¬μ©λμ§ μμ΅λλ€. μ΄λ λν Keychain Access μ ν리μΌμ΄μ λ° λ³΄μ λͺ λ Ήμ€ μ νΈλ¦¬ν°κ° κ΄λ¦¬νλ μμ€ν λ° μ¬μ©μ ν€μ²΄μΈμ μ λ’° μΈμ¦μκ° λ μ΄μ κΈ°λ³Έκ°μΌλ‘ μ¬μ©λμ§ μμμ μλ―Έν©λλ€."
ν΄κ²°μ± μ
$ sudo /Applications/Python\ 3.6/Install\ Certificates.command
Ubuntu 16.04μ python 3.6κ³Ό λμΌν λ¬Έμ κ° μμ΅λλ€.
μ¬κΈ°μμ μ루μ μ μ°Ύμμ΅λλ€. http://blog.pengyifan.com/how-to-fix-python-ssl-certificate_verify_failed/
import os, ssl
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and
getattr(ssl, '_create_unverified_context', None)):
ssl._create_default_https_context = ssl._create_unverified_context
κ°μ¬ν©λλ€. nfrikμ μ½λκ° μλνμ΅λλ€.
κ°μ₯ μ μ©ν λκΈ
μΌμ !
λ¬Έμ λ₯Ό μ°Ύμμ΅λλ€. Macμ python 3.6μλ μ€μΉ ν λ¨κ³κ° νμν©λλ€.
$ less /Applications/Python\ 3.6/ReadMe.rtf
" μ΄μ 릴리μ€μ λ¬λ¦¬ λ μ΄μ μ¬μ©λμ§ μλ Apple μ 곡 OpenSSL λΌμ΄λΈλ¬λ¦¬λ λ μ΄μ μ¬μ©λμ§ μμ΅λλ€. μ΄λ λν Keychain Access μ ν리μΌμ΄μ λ° λ³΄μ λͺ λ Ήμ€ μ νΈλ¦¬ν°κ° κ΄λ¦¬νλ μμ€ν λ° μ¬μ©μ ν€μ²΄μΈμ μ λ’° μΈμ¦μκ° λ μ΄μ κΈ°λ³Έκ°μΌλ‘ μ¬μ©λμ§ μμμ μλ―Έν©λλ€."
ν΄κ²°μ± μ
$ sudo /Applications/Python\ 3.6/Install\ Certificates.command