Instant Access to (Ebook) Supervised Learning with Python: Concepts and Practical Implementation Using Python by Vaibhav Verdhan ISBN 9781484261569, 1484261569 ebook Full Chapters
Instant Access to (Ebook) Supervised Learning with Python: Concepts and Practical Implementation Using Python by Vaibhav Verdhan ISBN 9781484261569, 1484261569 ebook Full Chapters
com
https://ebooknice.com/product/supervised-learning-with-
python-concepts-and-practical-implementation-using-
python-24688908
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
https://ebooknice.com/product/unsupervised-learning-with-generative-
ai-meap-v09-56785444
ebooknice.com
(Ebook) Machine Learning Concepts with Python and the
Jupyter Notebook Environment: Using Tensorflow 2.0 by
Nikita Silaparasetty ISBN 9781484259665, 9781484259672,
1484259661, 148425967X
https://ebooknice.com/product/machine-learning-concepts-with-python-
and-the-jupyter-notebook-environment-using-tensorflow-2-0-22417452
ebooknice.com
https://ebooknice.com/product/practical-machine-learning-for-data-
analysis-using-python-11154624
ebooknice.com
ebooknice.com
https://ebooknice.com/product/mastering-unlabeled-data-
meap-v5-49003820
ebooknice.com
Apress Standard
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and
accurate at the date of publication. Neither the publisher nor the
authors or the editors give a warranty, expressed or implied, with
respect to the material contained herein or for any errors or omissions
that may have been made. The publisher remains neutral with regard
to jurisdictional claims in published maps and institutional affiliations.
—Vaibhav Verdhan
Limerick,
Ireland. June 2020
Acknowledgments
I would like to thank Apress publications, Celestin John, Shrikant
Vishwarkarma, and Irfan Elahi for the confidence shown and the
support extended. Many thanks to Dr. Eli Kling for the fantastic forward
to the book. Special words for my family—Yashi, Pakhi, and Rudra—
without their support it would have been impossible to complete this
work.
Table of Contents
Chapter 1:Introduction to Supervised Learning
What Is ML?
Relationship Between Data Analysis, Data Mining, ML, and
AI
Data, Data Types, and Data Sources
How ML Differs from Software Engineering
ML Projects
Statistical and Mathematical Concepts for ML
Supervised Learning Algorithms
Regression vs.Classification Problems
Steps in a Supervised Learning Algorithm
Unsupervised Learning Algorithms
Cluster Analysis
PCA
Semi-supervised Learning Algorithms
Technical Stack
ML’s Popularity
Use Cases of ML
Summary
Chapter 2:Supervised Learning for Regression Analysis
Technical Toolkit Required
Regression analysis and Use Cases
What Is Linear Regression
Assumptions of Linear Regression
Measuring the Efficacy of Regression Problem
Example 1:Creating a Simple Linear Regression
Example 2:Simple Linear Regression for Housing Dataset
Example 3:Multiple Linear Regression for Housing Dataset
Nonlinear Regression Analysis
Identifying a Nonlinear Relationship
Assumptions for a Nonlinear Regression
Challenges with a Regression Model
Tree-Based Methods for Regression
Case study:Petrol consumption using Decision tree
Ensemble Methods for Regression
Case study:Petrol consumption using Random Forest
Feature Selection Using Tree-Based Methods
Summary
Chapter 3:Supervised Learning for Classification Problems
Technical Toolkit Required
Hypothesis Testing and p-Value
Classification Algorithms
Logistic Regression for Classification
Assessing the Accuracy of the Solution
Case Study:Credit Risk
Additional Notes
Naïve Bayes for Classification
Case Study:Income Prediction on Census Data
k-Nearest Neighbors for Classification
Case Study:k-Nearest Neighbor
The Dataset
Business Objective
Tree-Based Algorithms for Classification
Types of Decision Tree Algorithms
Summary
Chapter 4:Advanced Algorithms for Supervised Learning
Technical Toolkit Required
Boosting Algorithms
Using Gradient Boosting Algorithm
SVM
SVM in 2-D Space
KSVM
Case Study Using SVM
Supervised Algorithms for Unstructured Data
Text Data
Use Cases of Text Data
Challenges with Text Data
Text Analytics Modeling Process
Text Data Extraction and Management
Preprocessing of Text Data
Extracting Features from Text Data
Case study:Customer complaints analysis using NLP
Word Embeddings
Case study:Customer complaints analysis using word
embeddings
Image Data
Use Cases of Image Data
Challenges with Image Data
Image Data Management Process
Image Data Modeling Process
Fundamentals of Deep Learning
Artificial Neural Networks
Activation Functions
Loss Function in a Neural Network
Optimization in a Neural Network
Neural Network Training Process
Case Study 1:Create a Classification Model on Structured Data
Case Study 2:Image Classification Model
Summary
Chapter 5:End-to-End Model Development
Technical Toolkit Required
ML Model Development
Step 1:Define the Business Problem
Step 2:Data Discovery Phase
Step 3:Data Cleaning and Preparation
Duplicates in the Dataset
Categorical Variable Treatment in Dataset
Missing Values Present in the Dataset
Imbalance in the Dataset
Outliers in the Dataset
Other Common Problems in the Dataset
Step 4:EDA
Step 5:ML Model Building
Train/Test Split of Data
Finding the Best Threshold for Classification Algorithms
Overfitting vs.Underfitting Problem
Key Stakeholder Discussion and Iterations
Presenting the Final Model
Step 6:Deployment of the Model
Step 7:Documentation
Step 8:Model Refresh and Maintenance
Summary
Index
About the Author
Vaibhav Verdhan
has 12+ years of experience in data
science, machine learning, and artificial
intelligence. An MBA with engineering
background, he is a hands-on technical
expert with acumen to assimilate and
analyze data. He has led multiple
engagements in ML and AI across
geographies and across retail, telecom,
manufacturing, energy, and utilities
domains. Currently he resides in Ireland
with his family and is working as a
Principal Data Scientist.
About the Technical Reviewer
Irfan Elahi
is a full stack customer-focused cloud
analytics specialist bearing the unique
and proven combination of diverse
consulting and technical competencies
(cloud, big data, and machine learning)
with a growing portfolio of successful
projects delivering substantial impact
and value in multiple capacities across
telecom, retail, energy, and health-care
sectors. Additionally, he is an analytics
evangelist as is evident from the
published book, Udemy courses,
blogposts, trainings, lectures, and
presentations with global reach.
© Vaibhav Verdhan 2020
V. Verdhan, Supervised Learning with Python
https://doi.org/10.1007/978-1-4842-6156-9_1
What Is ML?
When we post a picture on Facebook or shop at Amazon, tweet or
watch videos on YouTube, each of these platforms is collecting data for
us. At each of these interactions, we are leaving behind our digital
footprints. These data points generated are collected and analyzed, and
ML allows these giants to make logical recommendations to us. Based
on the genre of videos we like, Netflix/YouTube can update our playlist,
what links we can click, and status we can react to; Facebook can
recommend posts to us, observing what type of product we frequently
purchase; and Amazon can suggest our next purchase as per our pocket
size! Amazing, right?
The short definition for ML is as follows: “In Machine Learning, we
study statistical/mathematical algorithms to learn the patterns from
the data which are then used to make predictions for the future.”
And ML is not limited to the online mediums alone. Its power has
been extended to multiple domains, geographies, and use cases. We
will be describing those use cases in detail in the last section of this
chapter.
So, in ML, we analyze vast amounts of data and uncover the
patterns in it. These patterns are then applied on real-world data to
make predictions for the future. This real-world data is unseen, and the
predictions will help businesses shape their respective strategies. We
do not need to explicitly program computers to do these tasks; rather,
the algorithms take the decisions based on historical data and
statistical models.
But how does ML fit into the larger data analysis landscape? Often,
we encounter terms like data analysis, data mining, ML, and artificial
intelligence (AI). Data science is also a loosely used phrase with no
exact definition available. It will be a good idea if these terms are
explored now.
Figure 1-3 Data quality plays a vital role in development of an ML solution; a lot of
time and effort are invested in improving data quality
ML Projects
An ML project is like any other project. It has a business objective to be
achieved, some input information, tools and teams, desired accuracy
levels, and a deadline!
However, execution of an ML project is quite different. The very
first step in the ML process is the same, which is defining a business
objective and a measurable parameter for measuring the success
criteria. Figure 1-5 shows subsequent steps in an ML project.
Figure 1-5 An ML project is like any other project, with various steps and process.
Proper planning and execution are required for an ML project like any other project.
5. After modeling, results are shared with the business team and the
statistical model is deployed into the production environment.
Since most of the data available is seldom clean, more than 60%–
70% of the project time is spent in data mining, data discovery,
cleaning, and data preparation phase.
Before starting the project, there are some anticipated challenges.
In Figure 1-6, we discuss a few questions we should ask before starting
an ML project.
Figure 1-6 Preparations to be made before starting an ML project. It is imperative
that all the relevant questions are clear and KPIs are frozen.
We should be able to answer these questions about the data
availability, data quality, data preparation, ML model prediction
measurements, and so on. It is imperative to find the answers to these
questions before kicking off the project; else we are risking stress for
ourselves and missing deadlines at a later stage.
Now you know what is ML and the various phases in an ML project.
It will be useful for you to envisage an ML model and what the various
steps are in the process. Before going deeper, it is imperative that we
brush up on some statistical and mathematical concepts. You will also
agree that statistical and mathematical knowledge is required for you
to appreciate ML.
The boss will make no more goods than he can sell at a profit.
Profits for the boss, wages for the workingman; no profits for
the boss, starvation and death for the workingman.
So far, every business man will agree; in fact, this is the doctrine
they hammered into your head during the Coolidge campaign, and it
got them seven million plurality. All right, then; and now let us
suppose, just for the sake of arguing, that the Coolidge
administration believed in allowing the rich to charge as high prices
as they pleased for goods, and to break strikes and beat down the
wages of the poor; what would happen then? Why, obviously the
poor wouldn’t have the money to buy so much goods or to furnish
so much profits for the bosses; it would be only the rich who had the
money, and goods would be more and more for the rich, and less
and less for the poor. Take notice, Judd, the Secretary of the
Treasury estimated that in 1919 the amount spent for luxuries in our
country was $22,700,000,000—and with millions of families lacking
bread!
But with the flood of goods pouring out from the machines, the rich
find it harder and harder to consume the product; they take to
reinvesting their money, that is, using it to make more machines, to
turn out more goods, to be sold for more profits. But already there
are more goods than can be sold; there are no longer enough profits
to supply the demands of the great mass of heaped-up capital. So
comes a glut of goods, and factories have to shut down, and we
have “hard times.” Just what are “hard times,” Judd? Paste this in
your hat now:
And again:
Hard times are weavers in rags, because they have made too
much clothing!
And again:
And finally:
Hard times are workingmen who have finished making the world
for their masters, and are ordered to move on to some other
planet!
You will say, Judd, that such absurd things could never happen. To
that I answer, very simply:
Well, since we American consumers can’t buy our own product, the
owners of the product—that is, the rich—have to look elsewhere for
customers, and so comes the hunt for “foreign markets.” Understand
me, I do not object to our going abroad for the things we can’t raise
at home; to exchange automobiles and moving pictures for bananas
and coffee—that is normal business. What I am talking about is a
glut of goods that we can’t sell at home, but must sell abroad, under
penalty of seeing our workers turned off to starve. We don’t take
goods in exchange—oh no, that would break down our home
industries, and we protect them by a high tariff wall. What we take
are paper promises to pay us at some future date; we go on
continually selling more than we buy, and filling our bank vaults with
these paper promises, and that is called a “favorable balance of
trade.”
But all the highly developed nations, Britain and France and
Germany and Italy and Japan, are in exactly the same plight as
ourselves; they also have more goods than their half-starved
workers can purchase; they also are looking for foreign markets, to
save their business system from collapse. Each finds its chance of
salvation in selling to the backward nations, which cannot yet do
their own manufacturing. So we run upon this curious situation:
And now, see the next step! Trying to save our own business
system, we threaten ruin to the business system of some other
country, say Japan. Naturally, the business men of Japan don’t like
that; so we have trade rivalry, and out of that we have war. The
cause of modern war may be put into one sentence—and I beg you
to realize that it’s no joke, but the grimmest of grim realities:
In a free society what we now have will cost us four hours labor
a day.
How can we stop that? We have tried the plan of sending the
grafters to jail, but that doesn’t work, for the reason that the
grafters buy the prosecuting officials and the judges; in the few
cases where we get them into jail, they buy the jailers. So I suggest
a new plan—that we take away the motive to graft, by making it
impossible for any man to exploit the labor of his fellows, or to
monopolize those things which are necessary to the life of all.
Learning industrial democracy is like learning to swim. You stick one
foot into the water, and you see that it sinks, and so you draw it out
in a hurry, and decide, it is impossible for you to stay on top of the
water. And then along comes a man who says: “Yes, you can swim,
but not until you go all the way in.” It seems an absurdity at first, yet
it is the literal truth about government ownership; you can own and
run it all, but you can’t own and run a small part!
At present private ownership is making all the big profits, and so, of
course, it is paying all the big salaries, and getting most of the
competent men. Not content with that, it is undermining the
competition of government, using its huge resources to buy the
political parties, and nominate incompetent men to public office.
That is no wild statement, but a fact of big business policy. Our
masters, who control the political parties, are afraid to have
competent men in public office, for fear they might take up a notion
to do something real for the public welfare. They prefer a man who
can’t kick over the traces, because he is too feeble. That is why at
the last nominating convention they turned down a really competent
and loyal servant of theirs, Mr. Herbert Hoover, and gave us poor,
shy, pitiful Mr. Coolidge, who can never by any possibility do
anything, for the reason that he doesn’t know what to do.
When you and I, Judd, and the rest of the useful workers of
America, get ready to run our own business, we can do it. We shall
do it, if for no other reason, because we have to—because we need
food in our cities, and machinery on our farms. We shall hire the
best experts to run our industries; and many of them will be the
very men who are running them now—they will be just as well
content to work for the American people as for Johnny Coaloil, who
is now taking a yachting trip with a dozen chorus girls on the Riviera,
or for Mrs. Silly Splash, who is setting the new fashion in diamond-
embroidered bathing suits at Palm Beach. Yes, Judd, we shall find
ways to run our business without these elegant idlers; and whatever
waste there may be won’t be so bad as having them corrupt a whole
generation of our young people by their vicious folly. If there is graft,
we’ll find ways to stop it, and if more efficiency is needed, we’ll get it
—because it will be our business, and our loss if we fail.
I’ll go even further, Judd; I’ll assert that the amount of waste
inherent in capitalism is so frightful, that no amount of inefficiency
under a free system can approach it. Remember the “iron ring,” and
what it will mean to us to get into the factories, with the right to run
them for ourselves! Remember our figures on the wastes of
competition! Let us have a “slogan,” for you to paste in your hat and
learn, Judd:
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com