Giter Site home page Giter Site logo

python-machine-learning-cookbook's Introduction

Python Machine Learning Cookbook

Python Machine Learning Cookbook by Packt Publishing

##Instructions and Navigation This is the code repository for Python Machine Learning Cookbook, published by Packt. It contains all the supporting project files necessary to work through the book from start to finish. The code files are organized according to the chapters in the book. These code samples will work on any machine running Linux, Mac OS X, or Windows. Even though they are written and tested on Python 2.7, you can easily run them on Python 3.x with minimal changes.

To run the code samples, you need to install scikit-learn, NumPy, SciPy, and matplotlib. For Chapter 6, you will need to install NLTK and gensim. To run the code in chapter 7, you need to install hmmlearn and python_speech_features. For chapter 8, you need to install Pandas and PyStruct. Chapter 8 also makes use of hmmlearn. For chapters 9 and 10, you need to install OpenCV. For chapter 11, you need to install NeuroLab.

##Description Machine learning is becoming increasingly pervasive in the modern data-driven world. It is used extensively across many fields like search engines, robotics, self-driving cars, and so on. During the course of this book, you will learn how to use Python to build a wide variety of machine learning applications to solve real-world problems. You will understand how to deal with different types of data like images, text, audio, and so on.

We will explore various techniques in supervised and unsupervised learning. We will learn machine learning algorithms like Support Vector Machines, Random Forests, Hidden Markov Models, Conditional Random Fields, Deep Neural Networks, and many more. We will discuss about visualization techniques that can be used to interact with your data. Using these algorithms, we will discuss how to build recommendation engines, perform predictive modeling, build speech recognizers, perform sentiment analysis on text data, develop face recognition systems, and so on.

You will understand what algorithms to use in a given context with the help of this exciting recipe-based guide. You will learn how to make informed decisions about the type of algorithms you need to use and learn how to implement those algorithms to get the best possible results. Stuck while making sense of images, text, speech, or some other form of data? This guide on applying machine learning techniques to each of these will come to your rescue! The code is well commented, so you will be able to get it up and running easily. The book contains all the relevant explanations of the algorithms that are used to build these applications.

There is a lot of debate going on between Python 2.x and Python 3.x. While we believe that the world is moving forward with better versions coming out, a lot of developers still enjoy using Python 2.x. A lot of operating systems have Python 2.x built into them. It also helps in maintaining compatibility with Python libraries that haven't been ported to Python 3.x. Keeping that in mind, the code in this book is oriented towards Python 2.x. We have tried to keep all the code as agnostic as possible to the Python versions, so that Python 3.x users won't face too many issues. We are focused on utilizing the machine learning libraries in the best possible way in Python.

##Related Python/Machine Learning Products:

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781786464477

python-machine-learning-cookbook's People

Contributors

hussaink72 avatar packt-itservice avatar packtutkarshr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-machine-learning-cookbook's Issues

Chapter04/stock_market.py raise socket.gaierror

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>

Chapter02/car.py returns bad input shape

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 ()

Chapter01/bike_sharing.py

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.