packtpublishing / python-machine-learning-cookbook Goto Github PK
View Code? Open in Web Editor NEWCode files for Python-Machine-Learning-Cookbook
License: MIT License
Code files for Python-Machine-Learning-Cookbook
License: MIT License
In Chapter01/bike_sharing.py, I am getting the following error:
$ python bike_sharing.py bike_day.csv
Traceback (most recent call last):
File "bike_sharing.py", line 39, in <module>
rf_regressor.fit(X_train, y_train)
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/ensemble/forest.py", line 326, in fit
for i, t in enumerate(trees))
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 758, in __call__
while self.dispatch_one_batch(iterator):
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 608, in dispatch_one_batch
self._dispatch(tasks)
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 571, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/externals/joblib/_parallel_backends.py", line 109, in apply_async
result = ImmediateResult(func)
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/externals/joblib/_parallel_backends.py", line 326, in __init__
self.results = batch()
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 131, in __call__
return [func(*args, **kwargs) for func, args, kwargs in self.items]
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/ensemble/forest.py", line 120, in _parallel_build_trees
tree.fit(X, y, sample_weight=curr_sample_weight, check_input=False)
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/tree/tree.py", line 1029, in fit
X_idx_sorted=X_idx_sorted)
File "/home/BenQuigley/local_projects/machine_learning/venv/local/lib/python2.7/site-packages/sklearn/tree/tree.py", line 199, in fit
% self.min_samples_split)
ValueError: min_samples_split must be at least 2 or in (0, 1], got 1
This comes from line 37 in bike_sharing.py:
rf_regressor = RandomForestRegressor(n_estimators=1000, max_depth=10, min_samples_split=1)
Deleting the min_samples_split
argument lets sklearn default it to 2, which fixes the bug. 1 is not a valid min_samples_split arg per this issue in the sklearn repo.
Chapter02/car.py returns bad input shape with scikit-learn 0.18-2. How to fix?
-> python car.py
/usr/lib64/python2.7/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
Accuracy of the classifier: 78.19%
Traceback (most recent call last):
File "car.py", line 45, in <module>
input_data_encoded[i] = int(label_encoder[i].transform(input_data[i]))
File "/usr/lib64/python2.7/site-packages/sklearn/preprocessing/label.py", line 143, in transform
y = column_or_1d(y, warn=True)
File "/usr/lib64/python2.7/site-packages/sklearn/utils/validation.py", line 562, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape ()
When I run vector_quantization.py on pthon 3, i came to this problem. How to fix it ?
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\iweut\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\co
6, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
ValueError: Need at least 1 and at most 32 array objects.
I got an socket.gaierror when I was running stock_market.py, how to fix it?
MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead.
warnings.warn(message, mplDeprecation, stacklevel=1)
Traceback (most recent call last):
File "E:\Anaconda3\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "E:\Anaconda3\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "E:\Anaconda3\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "E:\Anaconda3\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "E:\Anaconda3\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "E:\Anaconda3\lib\http\client.py", line 964, in send
self.connect()
File "E:\Anaconda3\lib\http\client.py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "E:\Anaconda3\lib\socket.py", line 704, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "E:\Anaconda3\lib\socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:/SourceCode/PythonStudy/Python-Machine-Learning-Cookbook/Chapter04/stock_market.py", line 21, in <module>
quotes = [quotes_yahoo(symbol, start_date, end_date, asobject=True) for symbol in symbols]
File "F:/SourceCode/PythonStudy/Python-Machine-Learning-Cookbook/Chapter04/stock_market.py", line 21, in <listcomp>
quotes = [quotes_yahoo(symbol, start_date, end_date, asobject=True) for symbol in symbols]
File "E:\Anaconda3\lib\site-packages\matplotlib\finance.py", line 411, in quotes_historical_yahoo_ochl
ochl=True)
File "E:\Anaconda3\lib\site-packages\matplotlib\finance.py", line 501, in _quotes_historical_yahoo
fh = fetch_historical_yahoo(ticker, date1, date2, cachename)
File "E:\Anaconda3\lib\site-packages\matplotlib\finance.py", line 360, in fetch_historical_yahoo
with contextlib.closing(urlopen(url)) as urlfh:
File "E:\Anaconda3\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "E:\Anaconda3\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "E:\Anaconda3\lib\urllib\request.py", line 544, in _open
'_open', req)
File "E:\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "E:\Anaconda3\lib\urllib\request.py", line 1346, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "E:\Anaconda3\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.