Showing posts with label Analysis. Show all posts

Market structure, Price Action, and Trading Strategies

Adam Grimes


e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 4.00
 Pages
 3425 p
 File Size 
 13,415 KB
 File Type
 PDF format
 ISBN
 978-1-118-11512-1 (cloth)
 978-1-118-22427-4 (ebk)
 978-1-118-23814-1 (ebk)
 978-1-118-26247-4 (ebk)
 Copyright©   
 2012 by Adam Grimes

About the Author
Adam Grimes has nearly two decades of experience in the
industry as a trader, analyst, and system developer. He
began his trading career with agricultural commodities, a
reflection of his roots in a Midwestern farming community, and traded
Chicago Mercantile Exchange (CME) listed
currency futures during the Asian financial crisis. Later,
he managed a successful private investment
partnership focused on shortterm trading of stock index
futures, and swing trading of other futures and options
products. He spent several years at the NYMEX, and has
held positions for a number of firms in roles such as
portfolio management, risk management, and quantitative
system development. Adam is the CIO of
Waverly Advisors, LLC, an asset management and
advisory firm specializing in tactical allocation and risk
management in liquid markets. Adam is an expert in
applying quantitative tools and methodology to market
data, particularly in modeling volatility and complex intramarket
relationships. In addition to his ongoing
research and trading, Adam is also a prolific writer and
educator. His personal website and blog
extends the work of this book with examples and
applications to live market data. He has been a
contributor on CNBC’s “FastMoney,” and his work
and research have been quoted in major media outlets
such as the Wall Street Journal, Investor’s Business
Daily, TheStreet.com, SmartMoney.com, SFO
Magazine, and many others.

Preface
The book you are holding in your hands is the product of nearly two decades of my
study and experience as a trader, covering the full span of actively traded markets
and time frames. I owe much to authors and traders who have come before me, for no
one produces anything significant in a vacuum. I would not have been
successful without the help and guidance of my mentors,
but I learned many of the lessons here from my own
mistakes. In some ways, this work represents a radical
break from many of the books that have preceded it, and I
hope it encourages you to question much of the
traditional thinking of technical analysis.
This book does not present a rigid system to be strictly
followed, nor a set of setups and patterns that can be
assembled at the trader’s whim. Rather, it offers a
comprehensive approach to the problems of technically
motivated, directional trading. The book is
structured to be read from beginning to end, but
individual sections and chapters stand on their own.
Through the entire work, deliberate repetition of
important concepts helps to build a complete perspective
on many of the problems traders face. The tools and
techniques must be adapted to the trader’s personality and
business situation, but most will find a firm foundation
between these covers. There are some underlying themes, perhaps not
expressed explicitly, that tie this work together, and they
may be surprising to many readers: Trading is hard.
Markets are extremely competitive. They are usually
very close to efficient, and most observed price
movements are random. It is therefore exceedingly difficult
to derive a method that makes superior risk-adjusted profits,
and it is even more difficult to successfully apply such a
method in actual trading. Last, it is essential to have a
verifiable edge in the markets—otherwise no consistent
profits are possible. This approach sets this work apart
from the majority of trading books published, which
suggest that simple patterns and proper psychology can
lead a trader to impressive profits. 
Perhaps this is possible, but I have never seen it work in actual practice.
This book is divided into four parts:
Part One begins with a look at some of the probability theory
supporting the concepts of successful trading.
Next comes an in-depth look at a specific approach to chart
reading that focuses on clarity and consistency lays the foundation for
building and understanding of price patterns in markets. This
section concludes with an overview of the Wyckoff market cycle,
which is already well known in the literature of technical analysis.
Part Two focuses on the details of trends, trading
ranges, and critically, the transitions from one to
the other in considerable detail. This is a deep
look at the underlying  foundation of price
movements, and there is information here that, to
my knowledge, has never appeared in print before.
Part Three might appear, at first glance, to be the
meat of this book, as it includes specific trading
patterns and examples of those patterns applied to
real markets. It also advocates a way of
looking at indicators and other confirming factors
that requires a deep understanding of the
nuances of these tools. One of the key elements
of any trading plan is how the trader sizes the
trade and manages the position as it develops;
these elements are also covered in considerable
depth. Much attention is devoted to the many risks traders will
encounter, both from the market and from
themselves. Though most traders are going to
be tempted to turn directly to this section,
remember that these patterns are only the tip
of the spear, and they are meaningless unless they
are placed within the context provided by
Parts One and Two. Part Four is specifically written for the individual
trader, and begins by focusing on elements of
psychology such as cognitive biases and
issues of emotional control. Chapter 11 takes
a look at many of the challenges developing
traders typically face.
Though it is impossible to reduce the trader
development process to a one-size-fits-all
formula, the majority of traders struggle with the
same issues. Most traders fail because they
do not realize that the process of becoming a
trader is a long one, and they are not prepared to
make the commitment. This section concludes
with a look at some performance analysis
tools that can help both the developing and the
established trader to track key performance
metrics and to target problems before they
have a serious impact on the bottom line.
Last, there are three appendixes in this work.
The first appendix is a trading primer that will
be useful for developing traders or for managers
who do not have a familiarity with the
language used by traders. Like any
discipline, trading has its own idioms and lingo,
an understanding of which is important for effective
communication. The second expands on the
some specific details and quirks of moving
averages the MACD, which are used
extensively in other sections of this book.
The last appendix simply contains a list of trade
data used in the performance analysis of
Part Four. This book is written for two
distinct groups of traders. It is overtly addressed to the
individual, self-directed trader, either trading for his
or her own account or who has exclusive trading
authority over a number of client accounts. The selfdirected
trader will find many sections specifically
addressed to the struggles he or she faces, and to the errors
he or she is likely to make along the way. Rather than
focusing on arcane concepts and theories, this trader needs
to learn to properly read a chart, and most importantly,
to understand the emerging story of supply and demand
as it plays out through the patterns in the market.
Though this book is primarily written for that selfdirected
trader, there is also much information that will be
valuable to a second group of traders and managers who do
not approach markets from a technical perspective or who
make decisions within an institutional framework. For
these traders, some of the elements such as trader
psychology may appear, at first glance, to be less
relevant, but they provide a context for all market action.
These traders will also find new perspectives on risk
management, position sizing, and pattern analysis that may
be able to inform their work in different areas.
The material in this book is complex; repeated exposure
and rereading of certain sections will be an essential
part of the learning process for most traders. In addition,
the size of this book may be daunting to many readers.
Once again, the book is structured to be read and
absorbed from beginning to end. Themes and concepts are
developed and revisited, and repetition is used to reinforce
important ideas, but it may also be helpful to have a
condensed study plan for some readers. Considering
the two discrete target audiences, I would suggest
the following plans:
Both the individual and the institutional trader
should page through the entire book, reading
whatever catches their interest. Each chapter
has been made as selfcontained as possible,
while trying to keep redundancy to an absolute minimum.
After an initial quick read, the individual trader should carefully
read Chapters 1 and 2, which provide a
foundation for everything else. This
trader should probably next read Part Four
(Chapters 11 and 12) in depth, paying particular
attention to the elements of the trader
development process. Next, turn to Chapters 6
and 10, which focus on often-misunderstood
aspects of risk and position sizing. Two
important aspects of the book are missed on this
first read: in-depth analysis of market
structure and the use of confirming tools in
setting up and managing actual trades. These are
topics for deeper investigation once the
initial material has been assimilated.
For the institutional trader, Chapter 1 is also
a logical follow-up to a quick read. Next,
Chapter 2 would provide a good background and
motivation for the entire discipline of technical
analysis. Chapters 8 and
9 will likely be very interesting to this trader.
For managers who are used to thinking of risk
in a portfolio context, there are important
lessons to be learned from a tactical/technical
approach to position and risk management. Last,
many of these readers
will have an academic background. Chapters 2
through 5 would round out this trader's
understanding of evolving market structure.
Following both of these study plans, it is advisable to
then begin again from the beginning, or perhaps to turn
to the parts of the book not covered in these shorter plans
and pick up what you have missed. Intellectually, the
material can be assimilated fairly quickly, but flawless
application may remain elusive for some time.
Additional materials supporting this book,
including a blog updated with examples and trades drawn
from current market action, are available at my web site
and blog, www.adamhgrimes.com. The title of this book is The
Art and Science of Technical Analysis. Science deals
primarily with elements that are quantifiable and testable.
The process of teaching a science usually focuses on the development of a body of
knowledge, procedures, and approaches to data—the
precise investigation of what is known and knowable. Art
is often seen as more subjective and imprecise, but
this is not entirely correct. In reality, neither can exist
without the other. Science must deal with the
philosophical and epistemological issues of the
edges of knowledge, and scientific progress depends on
inductive leaps as much as logical steps. Art rests on a
foundation of tools and techniques that can and
should be scientifically quantified, but it also points
to another mode of knowing that stands somewhat apart
from the usual procedures of logic. The two depend on
each other: Science without Art is sterile; Art without
Science is soft and incomplete. Nowhere is this
truer than in the study of modern financial markets.
 ADAM GRIMES
September 2011
New York, New York

Table of Contents

Series
Title Page
Copyright
Dedication
Preface
Acknowledgments
Part I: The
Foundation of
Technical
Analysis
Chapter 1: The
Trader’s Edge
DEFINING A
TRADING EDGE
FINDING AND
DEVELOPING
YOUR EDGE
GENERAL
PRINCIPLES OF
CHART
READING
INDICATORS
THE TWO
FORCES:
TOWARD A
NEW
UNDERSTANDING
OF MARKET
ACTION
PRICE ACTION
AND MARKET
STRUCTURE ON
CHARTS
CHARTING BY
HAND
Chapter 2: The Market
Cycle and the Four
Trades
WYCKOFF’S
MARKET CYCLE
THE FOUR
TRADES
SUMMARY
Part II: Market
Structure
Chapter 3: On Trends
THE
FUNDAMENTAL
PATTERN
TREND
STRUCTURE
A DEEPER
LOOK AT
PULLBACKS:
THE
QUINTESSENTIAL
TREND
TRADING
PATTERN
TREND
ANALYSIS
SUMMARY
Chapter 4: On Trading
Ranges
SUPPORT AND
RESISTANCE
TRADING
RANGES AS
FUNCTIONAL
STRUCTURES
SUMMARY
Chapter 5: Interfaces
between Trends and
Ranges
BREAKOUT
TRADE:
TRADING
RANGE TO
TREND
TREND TO
TRADING
RANGE
TREND TO
OPPOSITE
TREND (TREND
REVERSAL)
TREND TO
SAME TREND
(FAILURE OF
TREND
REVERSAL)
SUMMARY
Part III: Trading
Strategies
CHAPTER 6:
Practical Trading
Templates
FAILURE TEST
PULLBACK,
BUYING
SUPPORT OR
SHORTING
RESISTANCE
PULLBACK,
ENTERING
LOWER TIME
FRAME
BREAKOUT
TRADING
COMPLEX
PULLBACKS
THE ANTI
BREAKOUTS,
ENTERING IN
THE
PRECEDING
BASE
BREAKOUTS,
ENTERING ON
FIRST
PULLBACK
FOLLOWING
FAILED
BREAKOUTS
SUMMARY
CHAPTER 7: Tools
for Confirmation
THE MOVING
AVERAGE—THE
STILL CENTER
CHANNELS:
EMOTIONAL
EXTREMES
INDICATORS:
MACD
MULTIPLE TIME
FRAME
ANALYSIS
CHAPTER 8: Trade
Management
PLACING THE
INITIAL STOP
SETTING PRICE
TARGETS
ACTIVE
MANAGEMENT
PORTFOLIO
CONSIDERATIONS
PRACTICAL
ISSUES
CHAPTER 9: Risk
Management
RISK AND
POSITION
SIZING
THEORETICAL
PERSPECTIVES
ON RISK
MISUNDERSTOOD
RISK
PRACTICAL
RISKS IN
TRADING
SUMMARY
CHAPTER 10: Trade
Examples
TREND
CONTINUATION
TREND
TERMINATION
FAILURE TEST
FAILURES
TRADING
PARABOLIC
CLIMAXES
THE ANTI
TRADING AT
SUPPORT AND
RESISTANCE
SUMMARY
Part IV: The
Individual, Self-
Directed Trader
CHAPTER 11: The
Trader’s Mind
PSYCHOLOGICAL
CHALLENGES
OF THE
MARKETPLACE
EVOLUTIONARY
ADAPTATIONS
COGNITIVE
BIASES
THE RANDOM
REINFORCEMENT
PROBLEM
EMOTIONS: THE
ENEMY WITHIN
INTUITION
FLOW
PRACTICAL
PSYCHOLOGY
SUMMARY
CHAPTER 12:
Becoming a Trader
THE PROCESS
RECORD
KEEPING
STATISTICAL
ANALYSIS OF
TRADING
RESULTS
SUMMARY
Appendix A: Trading
Primer
THE SPREAD
TWO TYPES OF
ORDERS
CHARTS
Appendix B: A Deeper
Look at Moving
Averages and the
MACD
MOVING
AVERAGES
THE MACD
Appendix C: Sample
Trade Data
Glossary
Bibliography
About the Author
Index

Bookscreen
e-books shop

With Pandas, NumPy, and Matplotlib

Fabio Nelli


e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 3.00
 Pages
 576 p
 File Size 
 14,283 KB
 File Type
 PDF format
 ISBN
 978-1-4842-3912-4 (pbk)
 978-1-4842-3913-1 (electronic) 
 Copyright©   
 2018 by Fabio Nelli

About the Author
Fabio Nelli is a data scientist and Python consultant, designing and developing Python
applications for data analysis and visualization. He has experience with the scientific
world, having performed various data analysis roles in pharmaceutical chemistry for
private research companies and universities. He has been a computer consultant for
many years at IBM, EDS, and Hewlett-Packard, along with several banks and insurance
companies. He has an organic chemistry master’s degree and a bachelor’s degree in
information technologies and automation systems, with many years of experience in
life sciences (as as Tech Specialist at Beckman Coulter, Tecan, Sciex).
For further info and other examples, 

About the Technical Reviewer
Raul Samayoa is a senior software developer and machine
learning specialist with many years of experience in the
financial industry. An MSc graduate from the Georgia
Institute of Technology, he's never met a neural network or
dataset he did not like. He's fond of evangelizing the use of
DevOps tools for data science and software development.
Raul enjoys the energy of his hometown of Toronto,
Canada, where he runs marathons, volunteers as a
technology instructor with the University of Toronto
coders, and likes to work with data in Python and R.

Table of Contents
About the Author ...................................................................................................xvii
About the Technical Reviewer ................................................................................xix
Table of Contents
Chapter 1: An Introduction to Data Analysis ........................................................... 1
Data Analysis ................................................................................................................................ 1
Knowledge Domains of the Data Analyst ...................................................................................... 3
Computer Science ................................................................................................................... 3
Mathematics and Statistics ..................................................................................................... 4
Machine Learning and Artificial Intelligence ........................................................................... 5
Professional Fields of Application ........................................................................................... 5
Understanding the Nature of the Data .......................................................................................... 5
When the Data Become Information ........................................................................................ 6
When the Information Becomes Knowledge ........................................................................... 6
Types of Data ........................................................................................................................... 6
The Data Analysis Process ............................................................................................................ 6
Problem Definition ................................................................................................................... 8
Data Extraction ........................................................................................................................ 9
Data Preparation .................................................................................................................... 10
Data Exploration/Visualization ............................................................................................... 10
Predictive Modeling ............................................................................................................... 12
Model Validation .................................................................................................................... 13
Deployment ........................................................................................................................... 13
Quantitative and Qualitative Data Analysis ................................................................................. 14
Open Data .................................................................................................................................. 15
Python and Data Analysis ............................................................................................................ 17
Conclusions ................................................................................................................................. 17
Chapter 2: Introduction to the Python World ......................................................... 19
Python—The Programming Language ........................................................................................ 19
Python—The Interpreter ....................................................................................................... 21
Python 2 and Python 3 ................................................................................................................ 23
Installing Python .................................................................................................................... 23
Python Distributions .............................................................................................................. 24
Using Python .......................................................................................................................... 26
Writing Python Code .............................................................................................................. 28
IPython ................................................................................................................................... 35
PyPI—The Python Package Index ............................................................................................... 39
The IDEs for Python ............................................................................................................... 40
SciPy ........................................................................................................................................... 46
NumPy ................................................................................................................................... 47
Pandas ................................................................................................................................... 47
matplotlib .............................................................................................................................. 48
Conclusions ................................................................................................................................. 48
Chapter 3: The NumPy Library ................................................................................ 49
NumPy: A Little History ............................................................................................................... 49
The NumPy Installation ............................................................................................................... 50
Ndarray: The Heart of the Library ................................................................................................ 50
Create an Array ...................................................................................................................... 52
Types of Data ......................................................................................................................... 53
The dtype Option ................................................................................................................... 54
Intrinsic Creation of an Array ................................................................................................. 55
Basic Operations ......................................................................................................................... 57
Arithmetic Operators ............................................................................................................. 57
The Matrix Product ................................................................................................................ 59
Increment and Decrement Operators .................................................................................... 60
Universal Functions (ufunc) ................................................................................................... 61
Aggregate Functions ............................................................................................................. 62
Indexing, Slicing, and Iterating .................................................................................................... 62
Indexing ................................................................................................................................. 63
Slicing .................................................................................................................................... 65
Iterating an Array ................................................................................................................... 67
Conditions and Boolean Arrays ................................................................................................... 69
Shape Manipulation .................................................................................................................... 70
Array Manipulation ...................................................................................................................... 71
Joining Arrays ........................................................................................................................ 71
Splitting Arrays ...................................................................................................................... 72
General Concepts ........................................................................................................................ 74
Copies or Views of Objects .................................................................................................... 75
Vectorization .......................................................................................................................... 76
Broadcasting ......................................................................................................................... 76
Structured Arrays ........................................................................................................................ 79
Reading and Writing Array Data on Files ..................................................................................... 82
Loading and Saving Data in Binary Files ............................................................................... 82
Reading Files with Tabular Data ............................................................................................ 83
Conclusions ................................................................................................................................. 84
Chapter 4: The pandas Library—An Introduction ................................................... 87
pandas: The Python Data Analysis Library .................................................................................. 87
Installation of pandas .................................................................................................................. 88
Installation from Anaconda .................................................................................................... 88
Installation from PyPI ............................................................................................................ 89
Installation on Linux .............................................................................................................. 90
Installation from Source ........................................................................................................ 90
A Module Repository for Windows ......................................................................................... 90
Testing Your pandas Installation ................................................................................................. 91
Getting Started with pandas ....................................................................................................... 92
Introduction to pandas Data Structures ...................................................................................... 92
The Series .............................................................................................................................. 93
The DataFrame .................................................................................................................... 102
The Index Objects ................................................................................................................ 112
Other Functionalities on Indexes ............................................................................................... 114
Reindexing ........................................................................................................................... 114
Dropping ............................................................................................................................. 117
Arithmetic and Data Alignment ............................................................................................ 118
Operations Between Data Structures ........................................................................................ 120
Flexible Arithmetic Methods ................................................................................................ 120
Operations Between DataFrame and Series ........................................................................ 121
Function Application and Mapping ............................................................................................ 122
Functions by Element .......................................................................................................... 123
Functions by Row or Column ............................................................................................... 123
Statistics Functions ............................................................................................................. 125
Sorting and Ranking ................................................................................................................. 126
Correlation and Covariance ....................................................................................................... 129
“Not a Number” Data ................................................................................................................ 131
Assigning a NaN Value ......................................................................................................... 131
Filtering Out NaN Values ...................................................................................................... 132
Filling in NaN Occurrences .................................................................................................. 133
Hierarchical Indexing and Leveling ........................................................................................... 134
Reordering and Sorting Levels ............................................................................................ 137
Summary Statistic by Level ................................................................................................. 138
Conclusions ............................................................................................................................... 139
Chapter 5: pandas: Reading and Writing Data ...................................................... 141
I/O API Tools .............................................................................................................................. 141
CSV and Textual Files ................................................................................................................ 142
Reading Data in CSV or Text Files ............................................................................................. 143
Using RegExp to Parse TXT Files ......................................................................................... 146
Reading TXT Files Into Parts ................................................................................................ 148
Writing Data in CSV ............................................................................................................. 150
Reading and Writing HTML Files ............................................................................................... 152
Writing Data in HTML ........................................................................................................... 153
Reading Data from an HTML File ......................................................................................... 155
Reading Data from XML ............................................................................................................ 157
Reading and Writing Data on Microsoft Excel Files .................................................................. 159
JSON Data ................................................................................................................................. 162
The Format HDF5 ...................................................................................................................... 166
Pickle—Python Object Serialization ......................................................................................... 168
Serialize a Python Object with cPickle ................................................................................ 168
Pickling with pandas ........................................................................................................... 169
Interacting with Databases ....................................................................................................... 170
Loading and Writing Data with SQLite3 ............................................................................... 171
Loading and Writing Data with PostgreSQL ......................................................................... 174
Reading and Writing Data with a NoSQL Database: MongoDB .................................................. 178
Conclusions ............................................................................................................................... 180
Chapter 6: pandas in Depth: Data Manipulation ................................................... 181
Data Preparation ....................................................................................................................... 181
Merging ............................................................................................................................... 182
Concatenating ........................................................................................................................... 188
Combining ........................................................................................................................... 191
Pivoting ................................................................................................................................ 193
Removing ............................................................................................................................. 196
Data Transformation .................................................................................................................. 197
Removing Duplicates ........................................................................................................... 198
Mapping ............................................................................................................................... 199
Discretization and Binning ........................................................................................................ 204
Detecting and Filtering Outliers ........................................................................................... 209
Permutation .............................................................................................................................. 210
Random Sampling ............................................................................................................... 211
String Manipulation ................................................................................................................... 212
Built-in Methods for String Manipulation ............................................................................ 212
Regular Expressions ............................................................................................................ 214
Data Aggregation ...................................................................................................................... 217
GroupBy ............................................................................................................................... 218
A Practical Example ............................................................................................................. 219
Hierarchical Grouping .......................................................................................................... 220
Group Iteration .......................................................................................................................... 222
Chain of Transformations ..................................................................................................... 222
Functions on Groups ............................................................................................................ 224
Advanced Data Aggregation ...................................................................................................... 225
Conclusions ............................................................................................................................... 229
Chapter 7: Data Visualization with matplotlib ...................................................... 231
The matplotlib Library ............................................................................................................... 231
Installation ................................................................................................................................ 233
The IPython and IPython QtConsole .......................................................................................... 233
The matplotlib Architecture ....................................................................................................... 235
Backend Layer ..................................................................................................................... 236
Artist Layer .......................................................................................................................... 236
Scripting Layer (pyplot) ....................................................................................................... 238
pylab and pyplot .................................................................................................................. 238
pyplot ........................................................................................................................................ 239
A Simple Interactive Chart ................................................................................................... 239
The Plotting Window ................................................................................................................. 241
Set the Properties of the Plot .............................................................................................. 243
matplotlib and NumPy ......................................................................................................... 246
Using the kwargs ...................................................................................................................... 248
Working with Multiple Figures and Axes ............................................................................. 249
Adding Elements to the Chart ................................................................................................... 251
Adding Text .......................................................................................................................... 251
Adding a Grid ....................................................................................................................... 256
Adding a Legend .................................................................................................................. 257
Saving Your Charts .................................................................................................................... 260
Saving the Code ................................................................................................................... 260
Converting Your Session to an HTML File ............................................................................ 262
Saving Your Chart Directly as an Image ............................................................................... 264
Handling Date Values ............................................................................................................... 264
Chart Typology ........................................................................................................................... 267
Line Charts ................................................................................................................................ 267
Line Charts with pandas ...................................................................................................... 276
Histograms ................................................................................................................................ 277
Bar Charts ................................................................................................................................. 278
Horizontal Bar Charts .......................................................................................................... 281
Multiserial Bar Charts .......................................................................................................... 282
Multiseries Bar Charts with pandas Dataframe ................................................................... 285
Multiseries Stacked Bar Charts ........................................................................................... 286
Stacked Bar Charts with a pandas Dataframe .................................................................... 290
Other Bar Chart Representations ......................................................................................... 291
Pie Charts .................................................................................................................................. 292
Pie Charts with a pandas Dataframe ................................................................................... 296
Advanced Charts ....................................................................................................................... 297
Contour Plots ....................................................................................................................... 297
Polar Charts ......................................................................................................................... 299
The mplot3d Toolkit ................................................................................................................... 302
3D Surfaces ......................................................................................................................... 302
Scatter Plots in 3D ............................................................................................................... 304
Bar Charts in 3D .................................................................................................................. 306
Multi-Panel Plots ....................................................................................................................... 307
Display Subplots Within Other Subplots .............................................................................. 307
Grids of Subplots ................................................................................................................. 309
Conclusions ............................................................................................................................... 312
Chapter 8: Machine Learning with scikit-learn .................................................... 313
The scikit-learn Library ............................................................................................................. 313
Machine Learning ..................................................................................................................... 313
Supervised and Unsupervised Learning .............................................................................. 314
Training Set and Testing Set ................................................................................................ 315
Supervised Learning with scikit-learn ...................................................................................... 315
The Iris Flower Dataset ............................................................................................................. 316
The PCA Decomposition ...................................................................................................... 320
K-Nearest Neighbors Classifier ................................................................................................. 322
Diabetes Dataset ....................................................................................................................... 327
Linear Regression: The Least Square Regression ..................................................................... 328
Support Vector Machines (SVMs) .............................................................................................. 334
Support Vector Classification (SVC) ..................................................................................... 334
Nonlinear SVC ...................................................................................................................... 339
Plotting Different SVM Classifiers Using the Iris Dataset .................................................... 342
Support Vector Regression (SVR) ........................................................................................ 345
Conclusions ............................................................................................................................... 347
Chapter 9: Deep Learning with TensorFlow .......................................................... 349
Artificial Intelligence, Machine Learning, and Deep Learning ................................................... 349
Artificial intelligence ............................................................................................................ 350
Machine Learning Is a Branch of Artificial Intelligence ....................................................... 351
Deep Learning Is a Branch of Machine Learning ................................................................. 351
The Relationship Between Artificial Intelligence, Machine Learning, and Deep Learning ... 351
Deep Learning ........................................................................................................................... 352
Neural Networks and GPUs ................................................................................................. 352
Data Availability: Open Data Source, Internet of Things, and Big Data ................................ 353
Python ................................................................................................................................. 354
Deep Learning Python Frameworks .................................................................................... 354
Artificial Neural Networks ......................................................................................................... 355
How Artificial Neural Networks Are Structured ................................................................... 355
Single Layer Perceptron (SLP) ............................................................................................. 357
Multi Layer Perceptron (MLP) .............................................................................................. 360
Correspondence Between Artificial and Biological Neural Networks .................................. 361
TensorFlow ................................................................................................................................ 362
TensorFlow: Google’s Framework ........................................................................................ 362
TensorFlow: Data Flow Graph .............................................................................................. 362
Start Programming with TensorFlow ......................................................................................... 363
Installing TensorFlow ........................................................................................................... 363
Programming with the IPython QtConsole ........................................................................... 364
The Model and Sessions in TensorFlow ............................................................................... 364
Tensors ................................................................................................................................ 366
Operation on Tensors ........................................................................................................... 370
Single Layer Perceptron with TensorFlow ................................................................................. 371
Before Starting .................................................................................................................... 372
Data To Be Analyzed ............................................................................................................ 372
The SLP Model Definition .................................................................................................... 374
Learning Phase .................................................................................................................... 378
Test Phase and Accuracy Calculation .................................................................................. 383
Multi Layer Perceptron (with One Hidden Layer) with TensorFlow ........................................... 386
The MLP Model Definition .................................................................................................... 387
Learning Phase .................................................................................................................... 389
Test Phase and Accuracy Calculation .................................................................................. 395
Multi Layer Perceptron (with Two Hidden Layers) with TensorFlow .......................................... 397
Test Phase and Accuracy Calculation .................................................................................. 402
Evaluation of Experimental Data ......................................................................................... 404
Conclusions ............................................................................................................................... 407
Chapter 10: An Example— Meteorological Data .................................................. 409
A Hypothesis to Be Tested: The Influence of the Proximity of the Sea ...................................... 409
The System in the Study: The Adriatic Sea and the Po Valley ............................................. 410
Finding the Data Source ............................................................................................................ 414
Data Analysis on Jupyter Notebook .......................................................................................... 415
Analysis of Processed Meteorological Data .............................................................................. 421
The RoseWind ........................................................................................................................... 436
Calculating the Mean Distribution of the Wind Speed ......................................................... 441
Conclusions ............................................................................................................................... 443
Chapter 11: Embedding the JavaScript D3 Library in the IPython Notebook ....... 445
The Open Data Source for Demographics ................................................................................. 445
The JavaScript D3 Library ......................................................................................................... 449
Drawing a Clustered Bar Chart ................................................................................................. 454
The Choropleth Maps ................................................................................................................ 459
The Choropleth Map of the U.S. Population in 2014 .................................................................. 464
Conclusions ............................................................................................................................... 471
Chapter 12: Recognizing Handwritten Digits ........................................................ 473
Handwriting Recognition ........................................................................................................... 473
Recognizing Handwritten Digits with scikit-learn ..................................................................... 474
The Digits Dataset ..................................................................................................................... 475
Learning and Predicting ............................................................................................................ 478
Recognizing Handwritten Digits with TensorFlow ..................................................................... 480
Learning and Predicting ............................................................................................................ 482
Conclusions ............................................................................................................................... 486
Chapter 13: Textual Data Analysis with NLTK ....................................................... 487
Text Analysis Techniques .......................................................................................................... 487
The Natural Language Toolkit (NLTK) ................................................................................... 488
Import the NLTK Library and the NLTK Downloader Tool ..................................................... 489
Search for a Word with NLTK ............................................................................................... 493
Analyze the Frequency of Words ......................................................................................... 494
Selection of Words from Text ............................................................................................... 497
Bigrams and Collocations .................................................................................................... 498
Use Text on the Network ........................................................................................................... 500
Extract the Text from the HTML Pages ................................................................................ 501
Sentimental Analysis ........................................................................................................... 502
Conclusions ............................................................................................................................... 506
Chapter 14: Image Analysis and Computer Vision with OpenCV .......................... 507
Image Analysis and Computer Vision ........................................................................................ 507
OpenCV and Python ................................................................................................................... 508
OpenCV and Deep Learning ...................................................................................................... 509
Installing OpenCV ...................................................................................................................... 509
First Approaches to Image Processing and Analysis ................................................................ 509
Before Starting .................................................................................................................... 510
Load and Display an Image ................................................................................................. 510
Working with Images ........................................................................................................... 512
Save the New Image ........................................................................................................... 514
Elementary Operations on Images ...................................................................................... 514
Image Blending .................................................................................................................... 520
Image Analysis .......................................................................................................................... 521
Edge Detection and Image Gradient Analysis ........................................................................... 522
Edge Detection .................................................................................................................... 522
The Image Gradient Theory ................................................................................................. 523
A Practical Example of Edge Detection with the Image Gradient Analysis .......................... 525
A Deep Learning Example: The Face Detection ......................................................................... 532
Conclusions ............................................................................................................................... 535
Appendix A: Writing Mathematical Expressions with LaTeX ................................ 537
With matplotlib .......................................................................................................................... 537
With IPython Notebook in a Markdown Cell .............................................................................. 537
With IPython Notebook in a Python 2 Cell ................................................................................. 538
Subscripts and Superscripts ..................................................................................................... 538
Fractions, Binomials, and Stacked Numbers ............................................................................ 538
Radicals .................................................................................................................................... 539
Fonts ......................................................................................................................................... 539
Accents ..................................................................................................................................... 540
Appendix B: Open Data Sources ........................................................................... 549
Political and Government Data .................................................................................................. 549
Health Data ............................................................................................................................... 550
Social Data ................................................................................................................................ 550
Miscellaneous and Public Data Sets ......................................................................................... 551
Financial Data ........................................................................................................................... 552
Climatic Data ............................................................................................................................. 552
Sports Data ............................................................................................................................... 553
Publications, Newspapers, and Books ...................................................................................... 553
Musical Data ............................................................................................................................. 553
Index ..................................................................................................................... 555


Bookscreen
e-books shop

Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Todd Green
Development Editor: James Markham
Coordinating Editor: Jill Balzano
Cover image designed by Freepik (www.freepik.com)
Loading...
DMCA.com Protection Status