100% found this document useful (8 votes)
566 views44 pages

(Ebook PDF) Hands-On Machine Learning With Scikit-Learn and TensorFlow Instant Download

The document provides an overview of the eBook 'Hands-On Machine Learning with Scikit-Learn and TensorFlow,' which aims to teach readers the fundamentals of machine learning through practical examples using Python frameworks. It covers a wide range of topics from basic algorithms to deep learning techniques, emphasizing a hands-on approach with available code examples. The book also outlines prerequisites, resources for further learning, and the structure of its content divided into two main parts: fundamentals and neural networks.

Uploaded by

zrikiertoba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (8 votes)
566 views44 pages

(Ebook PDF) Hands-On Machine Learning With Scikit-Learn and TensorFlow Instant Download

The document provides an overview of the eBook 'Hands-On Machine Learning with Scikit-Learn and TensorFlow,' which aims to teach readers the fundamentals of machine learning through practical examples using Python frameworks. It covers a wide range of topics from basic algorithms to deep learning techniques, emphasizing a hands-on approach with available code examples. The book also outlines prerequisites, resources for further learning, and the structure of its content divided into two main parts: fundamentals and neural networks.

Uploaded by

zrikiertoba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

(eBook PDF) Hands-On Machine Learning with

Scikit-Learn and TensorFlow pdf download

https://ebooksecure.com/product/ebook-pdf-hands-on-machine-
learning-with-scikit-learn-and-tensorflow/

Download more ebook from https://ebooksecure.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebooksecure.com
to discover even more!

Visualization Techniques for Climate Change with


Machine Learning and Artificial Intelligence 1st
Edition - eBook PDF

https://ebooksecure.com/download/visualization-techniques-for-
climate-change-with-machine-learning-and-artificial-intelligence-
ebook-pdf/

(eBook PDF) Introduction to Machine Learning with


Python: A Guide for Data Scientists

http://ebooksecure.com/product/ebook-pdf-introduction-to-machine-
learning-with-python-a-guide-for-data-scientists/

(eBook PDF) Machine Learning Refined: Foundations,


Algorithms, and Applications

http://ebooksecure.com/product/ebook-pdf-machine-learning-
refined-foundations-algorithms-and-applications/

(eBook PDF) Hands on Virtual Computing 2nd Edition

http://ebooksecure.com/product/ebook-pdf-hands-on-virtual-
computing-2nd-edition/
(eBook PDF) Hands-On Ethical Hacking and Network
Defense 3rd Edition

http://ebooksecure.com/product/ebook-pdf-hands-on-ethical-
hacking-and-network-defense-3rd-edition/

Applied Machine Learning 1st Edition M. Gopal - eBook


PDF

https://ebooksecure.com/download/applied-machine-learning-ebook-
pdf/

Machine Learning for Planetary Science 1st Edition -


eBook PDF

https://ebooksecure.com/download/machine-learning-for-planetary-
science-ebook-pdf/

(eBook PDF) Hands-On Database 2nd Edition by Steve


Conger

http://ebooksecure.com/product/ebook-pdf-hands-on-database-2nd-
edition-by-steve-conger/

(eBook PDF) Essentials of Marketing Research: A Hands-


On Orientation

http://ebooksecure.com/product/ebook-pdf-essentials-of-marketing-
research-a-hands-on-orientation/
Objective and Approach
This book assumes that you know close to nothing about Machine Learning. Its goal is to give you the
concepts, the intuitions, and the tools you need to actually implement programs capable of learning from
data.
We will cover a large number of techniques, from the simplest and most commonly used (such as linear
regression) to some of the Deep Learning techniques that regularly win competitions.
Rather than implementing our own toy versions of each algorithm, we will be using actual production-
ready Python frameworks:
Scikit-Learn is very easy to use, yet it implements many Machine Learning algorithms efficiently, so
it makes for a great entry point to learn Machine Learning.

TensorFlow is a more complex library for distributed numerical computation using data flow graphs.
It makes it possible to train and run very large neural networks efficiently by distributing the
computations across potentially thousands of multi-GPU servers. TensorFlow was created at Google
and supports many of their large-scale Machine Learning applications. It was open-sourced in
November 2015.

The book favors a hands-on approach, growing an intuitive understanding of Machine Learning through
concrete working examples and just a little bit of theory. While you can read this book without picking up
your laptop, we highly recommend you experiment with the code examples available online as Jupyter
notebooks at https://github.com/ageron/handson-ml.
Prerequisites
This book assumes that you have some Python programming experience and that you are familiar with
Python’s main scientific libraries, in particular NumPy, Pandas, and Matplotlib.
Also, if you care about what’s under the hood you should have a reasonable understanding of college-
level math as well (calculus, linear algebra, probabilities, and statistics).
If you don’t know Python yet, http://learnpython.org/ is a great place to start. The official tutorial on
python.org is also quite good.
If you have never used Jupyter, Chapter 2 will guide you through installation and the basics: it is a great
tool to have in your toolbox.
If you are not familiar with Python’s scientific libraries, the provided Jupyter notebooks include a few
tutorials. There is also a quick math tutorial for linear algebra.
Roadmap
This book is organized in two parts. Part I, The Fundamentals of Machine Learning, covers the
following topics:
What is Machine Learning? What problems does it try to solve? What are the main categories and
fundamental concepts of Machine Learning systems?

The main steps in a typical Machine Learning project.

Learning by fitting a model to data.

Optimizing a cost function.

Handling, cleaning, and preparing data.

Selecting and engineering features.

Selecting a model and tuning hyperparameters using cross-validation.

The main challenges of Machine Learning, in particular underfitting and overfitting (the
bias/variance tradeoff).

Reducing the dimensionality of the training data to fight the curse of dimensionality.

The most common learning algorithms: Linear and Polynomial Regression, Logistic Regression, k-
Nearest Neighbors, Support Vector Machines, Decision Trees, Random Forests, and Ensemble
methods.

Part II, Neural Networks and Deep Learning, covers the following topics:
What are neural nets? What are they good for?

Building and training neural nets using TensorFlow.

The most important neural net architectures: feedforward neural nets, convolutional nets, recurrent
nets, long short-term memory (LSTM) nets, and autoencoders.

Techniques for training deep neural nets.

Scaling neural networks for huge datasets.

Reinforcement learning.

The first part is based mostly on Scikit-Learn while the second part uses TensorFlow.

CAUTION
Don’t jump into deep waters too hastily: while Deep Learning is no doubt one of the most exciting areas in Machine Learning,
you should master the fundamentals first. Moreover, most problems can be solved quite well using simpler techniques such as
Random Forests and Ensemble methods (discussed in Part I). Deep Learning is best suited for complex problems such as image
recognition, speech recognition, or natural language processing, provided you have enough data, computing power, and patience.
Other Resources
Many resources are available to learn about Machine Learning. Andrew Ng’s ML course on Coursera and
Geoffrey Hinton’s course on neural networks and Deep Learning are amazing, although they both require a
significant time investment (think months).
There are also many interesting websites about Machine Learning, including of course Scikit-Learn’s
exceptional User Guide. You may also enjoy Dataquest, which provides very nice interactive tutorials,
and ML blogs such as those listed on Quora. Finally, the Deep Learning website has a good list of
resources to learn more.
Of course there are also many other introductory books about Machine Learning, in particular:
Joel Grus, Data Science from Scratch (O’Reilly). This book presents the fundamentals of Machine
Learning, and implements some of the main algorithms in pure Python (from scratch, as the name
suggests).

Stephen Marsland, Machine Learning: An Algorithmic Perspective (Chapman and Hall). This book
is a great introduction to Machine Learning, covering a wide range of topics in depth, with code
examples in Python (also from scratch, but using NumPy).

Sebastian Raschka, Python Machine Learning (Packt Publishing). Also a great introduction to
Machine Learning, this book leverages Python open source libraries (Pylearn 2 and Theano).

Yaser S. Abu-Mostafa, Malik Magdon-Ismail, and Hsuan-Tien Lin, Learning from Data
(AMLBook). A rather theoretical approach to ML, this book provides deep insights, in particular on
the bias/variance tradeoff (see Chapter 4).

Stuart Russell and Peter Norvig, Artificial Intelligence: A Modern Approach, 3rd Edition
(Pearson). This is a great (and huge) book covering an incredible amount of topics, including
Machine Learning. It helps put ML into perspective.

Finally, a great way to learn is to join ML competition websites such as Kaggle.com this will allow you
to practice your skills on real-world problems, with help and insights from some of the best ML
professionals out there.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as
variable or function names, databases, data types, environment variables, statements and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.

TIP
This element signifies a tip or suggestion.

NOTE
This element signifies a general note.

WARNING
This element indicates a warning or caution.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at
https://github.com/ageron/handson-ml.
This book is here to help you get your job done. In general, if example code is offered with this book, you
may use it in your programs and documentation. You do not need to contact us for permission unless
you’re reproducing a significant portion of the code. For example, writing a program that uses several
chunks of code from this book does not require permission. Selling or distributing a CD-ROM of
examples from O’Reilly books does require permission. Answering a question by citing this book and
quoting example code does not require permission. Incorporating a significant amount of example code
from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher,
and ISBN. For example: “Hands-On Machine Learning with Scikit-Learn and TensorFlow by Aurélien
Géron (O’Reilly). Copyright 2017 Aurélien Géron, 978-1-491-96229-9.”
If you feel your use of code examples falls outside fair use or the permission given above, feel free to
contact us at [email protected].
O’Reilly Safari
NOTE
Safari (formerly Safari Books Online) is a membership-based training and reference platform for
enterprise, government, educators, and individuals.
Members have access to thousands of books, training videos, Learning Paths, interactive tutorials, and
curated playlists from over 250 publishers, including O’Reilly Media, Harvard Business Review,
Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press,
Adobe, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks,
Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, and
Course Technology, among others.
For more information, please visit http://oreilly.com/safari.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.

1005 Gravenstein Highway North

Sebastopol, CA 95472

800-998-9938 (in the United States or Canada)

707-829-0515 (international or local)

707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You
can access this page at http://bit.ly/hands-on-machine-learning-with-scikit-learn-and-tensorflow.
To comment or ask technical questions about this book, send email to [email protected].
For more information about our books, courses, conferences, and news, see our website at
http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
I would like to thank my Google colleagues, in particular the YouTube video classification team, for
teaching me so much about Machine Learning. I could never have started this project without them.
Special thanks to my personal ML gurus: Clément Courbet, Julien Dubois, Mathias Kende, Daniel
Kitachewsky, James Pack, Alexander Pak, Anosh Raj, Vitor Sessak, Wiktor Tomczak, Ingrid von Glehn,
Rich Washington, and everyone at YouTube Paris.
I am incredibly grateful to all the amazing people who took time out of their busy lives to review my book
in so much detail. Thanks to Pete Warden for answering all my TensorFlow questions, reviewing Part II,
providing many interesting insights, and of course for being part of the core TensorFlow team. You should
definitely check out his blog! Many thanks to Lukas Biewald for his very thorough review of Part II: he
left no stone unturned, tested all the code (and caught a few errors), made many great suggestions, and his
enthusiasm was contagious. You should check out his blog and his cool robots! Thanks to Justin Francis,
who also reviewed Part II very thoroughly, catching errors and providing great insights, in particular in
Chapter 16. Check out his posts on TensorFlow!
Huge thanks as well to David Andrzejewski, who reviewed Part I and provided incredibly useful
feedback, identifying unclear sections and suggesting how to improve them. Check out his website!
Thanks to Grégoire Mesnil, who reviewed Part II and contributed very interesting practical advice on
training neural networks. Thanks as well to Eddy Hung, Salim Sémaoune, Karim Matrah, Ingrid von
Glehn, Iain Smears, and Vincent Guilbeau for reviewing Part I and making many useful suggestions. And I
also wish to thank my father-in-law, Michel Tessier, former mathematics teacher and now a great
translator of Anton Chekhov, for helping me iron out some of the mathematics and notations in this book
and reviewing the linear algebra Jupyter notebook.
And of course, a gigantic “thank you” to my dear brother Sylvain, who reviewed every single chapter,
tested every line of code, provided feedback on virtually every section, and encouraged me from the first
line to the last. Love you, bro!
Many thanks as well to O’Reilly’s fantastic staff, in particular Nicole Tache, who gave me insightful
feedback, always cheerful, encouraging, and helpful. Thanks as well to Marie Beaugureau, Ben Lorica,
Mike Loukides, and Laurel Ruma for believing in this project and helping me define its scope. Thanks to
Matt Hacker and all of the Atlas team for answering all my technical questions regarding formatting,
asciidoc, and LaTeX, and thanks to Rachel Monaghan, Nick Adams, and all of the production team for
their final review and their hundreds of corrections.
Last but not least, I am infinitely grateful to my beloved wife, Emmanuelle, and to our three wonderful
kids, Alexandre, Rémi, and Gabrielle, for encouraging me to work hard on this book, asking many
questions (who said you can’t teach neural networks to a seven-year-old?), and even bringing me cookies
and coffee. What more can one dream of?

1 Available on Hinton’s home page at http://www.cs.toronto.edu/~hinton/.


2 Despite the fact that Yann Lecun’s deep convolutional neural networks had worked well for image recognition since the 1990s, although
they were not as general purpose.
Part I. The Fundamentals of Machine Learning
Chapter 1. The Machine Learning Landscape

When most people hear “Machine Learning,” they picture a robot: a dependable butler or a deadly
Terminator depending on who you ask. But Machine Learning is not just a futuristic fantasy, it’s already
here. In fact, it has been around for decades in some specialized applications, such as Optical Character
Recognition (OCR). But the first ML application that really became mainstream, improving the lives of
hundreds of millions of people, took over the world back in the 1990s: it was the spam filter. Not exactly
a self-aware Skynet, but it does technically qualify as Machine Learning (it has actually learned so well
that you seldom need to flag an email as spam anymore). It was followed by hundreds of ML applications
that now quietly power hundreds of products and features that you use regularly, from better
recommendations to voice search.
Where does Machine Learning start and where does it end? What exactly does it mean for a machine to
learn something? If I download a copy of Wikipedia, has my computer really “learned” something? Is it
suddenly smarter? In this chapter we will start by clarifying what Machine Learning is and why you may
want to use it.
Then, before we set out to explore the Machine Learning continent, we will take a look at the map and
learn about the main regions and the most notable landmarks: supervised versus unsupervised learning,
online versus batch learning, instance-based versus model-based learning. Then we will look at the
workflow of a typical ML project, discuss the main challenges you may face, and cover how to evaluate
and fine-tune a Machine Learning system.
This chapter introduces a lot of fundamental concepts (and jargon) that every data scientist should know
by heart. It will be a high-level overview (the only chapter without much code), all rather simple, but you
should make sure everything is crystal-clear to you before continuing to the rest of the book. So grab a
coffee and let’s get started!

TIP
If you already know all the Machine Learning basics, you may want to skip directly to Chapter 2. If you are not sure, try to
answer all the questions listed at the end of the chapter before moving on.
What Is Machine Learning?
Machine Learning is the science (and art) of programming computers so they can learn from data.
Here is a slightly more general definition:
[Machine Learning is the] field of study that gives computers the ability to learn without being
explicitly programmed.
Arthur Samuel, 1959
And a more engineering-oriented one:
A computer program is said to learn from experience E with respect to some task T and some
performance measure P, if its performance on T, as measured by P, improves with experience E.
Tom Mitchell, 1997
For example, your spam filter is a Machine Learning program that can learn to flag spam given examples
of spam emails (e.g., flagged by users) and examples of regular (nonspam, also called “ham”) emails. The
examples that the system uses to learn are called the training set. Each training example is called a
training instance (or sample). In this case, the task T is to flag spam for new emails, the experience E is
the training data, and the performance measure P needs to be defined; for example, you can use the ratio
of correctly classified emails. This particular performance measure is called accuracy and it is often
used in classification tasks.
If you just download a copy of Wikipedia, your computer has a lot more data, but it is not suddenly better
at any task. Thus, it is not Machine Learning.
Why Use Machine Learning?
Consider how you would write a spam filter using traditional programming techniques (Figure 1-1):
1. First you would look at what spam typically looks like. You might notice that some words or
phrases (such as “4U,” “credit card,” “free,” and “amazing”) tend to come up a lot in the subject.
Perhaps you would also notice a few other patterns in the sender’s name, the email’s body, and
so on.

2. You would write a detection algorithm for each of the patterns that you noticed, and your
program would flag emails as spam if a number of these patterns are detected.

3. You would test your program, and repeat steps 1 and 2 until it is good enough.

Figure 1-1. The traditional approach

Since the problem is not trivial, your program will likely become a long list of complex rules — pretty
hard to maintain.
In contrast, a spam filter based on Machine Learning techniques automatically learns which words and
phrases are good predictors of spam by detecting unusually frequent patterns of words in the spam
examples compared to the ham examples (Figure 1-2). The program is much shorter, easier to maintain,
and most likely more accurate.
Figure 1-2. Machine Learning approach

Moreover, if spammers notice that all their emails containing “4U” are blocked, they might start writing
“For U” instead. A spam filter using traditional programming techniques would need to be updated to flag
“For U” emails. If spammers keep working around your spam filter, you will need to keep writing new
rules forever.
In contrast, a spam filter based on Machine Learning techniques automatically notices that “For U” has
become unusually frequent in spam flagged by users, and it starts flagging them without your intervention
(Figure 1-3).
Figure 1-3. Automatically adapting to change

Another area where Machine Learning shines is for problems that either are too complex for traditional
approaches or have no known algorithm. For example, consider speech recognition: say you want to start
simple and write a program capable of distinguishing the words “one” and “two.” You might notice that
the word “two” starts with a high-pitch sound (“T”), so you could hardcode an algorithm that measures
high-pitch sound intensity and use that to distinguish ones and twos. Obviously this technique will not
scale to thousands of words spoken by millions of very different people in noisy environments and in
dozens of languages. The best solution (at least today) is to write an algorithm that learns by itself, given
many example recordings for each word.
Finally, Machine Learning can help humans learn (Figure 1-4): ML algorithms can be inspected to see
what they have learned (although for some algorithms this can be tricky). For instance, once the spam
filter has been trained on enough spam, it can easily be inspected to reveal the list of words and
combinations of words that it believes are the best predictors of spam. Sometimes this will reveal
unsuspected correlations or new trends, and thereby lead to a better understanding of the problem.
Applying ML techniques to dig into large amounts of data can help discover patterns that were not
immediately apparent. This is called data mining.
Figure 1-4. Machine Learning can help humans learn

To summarize, Machine Learning is great for:


Problems for which existing solutions require a lot of hand-tuning or long lists of rules: one Machine
Learning algorithm can often simplify code and perform better.

Complex problems for which there is no good solution at all using a traditional approach: the best
Machine Learning techniques can find a solution.

Fluctuating environments: a Machine Learning system can adapt to new data.

Getting insights about complex problems and large amounts of data.


Types of Machine Learning Systems
There are so many different types of Machine Learning systems that it is useful to classify them in broad
categories based on:
Whether or not they are trained with human supervision (supervised, unsupervised, semisupervised,
and Reinforcement Learning)

Whether or not they can learn incrementally on the fly (online versus batch learning)

Whether they work by simply comparing new data points to known data points, or instead detect
patterns in the training data and build a predictive model, much like scientists do (instance-based
versus model-based learning)

These criteria are not exclusive; you can combine them in any way you like. For example, a state-of-the-
art spam filter may learn on the fly using a deep neural network model trained using examples of spam and
ham; this makes it an online, model-based, supervised learning system.
Let’s look at each of these criteria a bit more closely.
Another Random Scribd Document
with Unrelated Content
some of his toes fell off. Through the intercession of Bárd, Swein
gave peace to Jón’s companions. He remained there during the
night, but in the morning he and his men went away in a boat
belonging to Bárd, which he gave to him. They went south to
Bardsvík,[432] and stayed in a certain cave. Sometimes Swein took his
meals at a house during the day, but slept during the night down by
his boat, and thus he guarded himself against his enemies.
CHAPTER C

OF ROGNVALD AND SWEIN.

One morning early Swein and his men saw a large long-ship coming
from Hrólfsey (Hrossey?) to Rögnvaldsey,[433] and Swein recognised
it immediately as Earl Rögnvald’s ship, which he used to command
himself. They put in at Rögnvaldsey, where Swein’s boat was lying,
and five of them went on shore. Swein and his men were on a
certain headland, and threw stones at the Earl’s men. When those
on board saw this, they drew forth their arms; and when that was
seen by Swein, they ran down to the beach, and pushed their boat
afloat, and jumped into it. The long-ship stuck fast on the beach.
When they rowed past it, Swein was standing up with a spear in his
hand. When Earl Rögnvald perceived it, he took a shield and held it
before him, but Swein did not throw the spear. When the Earl saw
that they would get away from them, he ordered a truce-shield to be
held aloft, and asked Swein to go on shore. When Swein saw this,
he told his men to put to land, saying that it was his greatest
satisfaction to be at peace with Earl Rögnvald.
CHAPTER CI

OF EARL HARALD AND SWEIN.

Then Earl Rögnvald and Swein went on shore, and had a long
conversation by themselves, and agreed very well. While they were
talking, they saw Earl Harald sailing from Caithness to Vagaland
(Walls), and when the ship approached the island, Swein asked what
was to be done. The Earl said Swein should go over to Ness
immediately. This was during Lent. They left Rögnvaldsey at the
same time. The Earl went to Hrossey,[434] but Swein went west to
Straumsey (Stroma). Earl Harald saw the boat, and thought he
recognised it as Swein’s, and went immediately into the Firth in
pursuit. When Swein saw the pursuit, they left the boat, and hid
themselves. When Earl Harald came to Straumsey (Stroma) he saw
the boat, and suspected that the men were somewhere near, and
would not therefore go on shore. A man named Amundi, the son of
Hnefi, who was Earl Harald’s friend, and father’s brother to Swein,
Asleif’s son’s stepchildren, went between them, and succeeded so far
that they agreed to keep the agreement of peace which they had
made the previous winter. A gale arose, and they were both obliged
to remain there during the night, and Amundi put Earl Harald and
Swein in the same bed, and many of their men slept in the same
house.
After this Swein went over to Ness (Caithness), and Earl Harald to
the Orkneys. Swein heard that the Earl had said that their
agreement to be at peace had been rather loose. He paid little heed
to this, however, and went south to Dalir, and spent the Easter there
with his friend Sumarlidi; but Earl Harald went north to Hjaltland,
and was there a long time during the spring.
After Easter Swein went from the south, and met on his way two
of Jón Vœng’s brothers—one was called Bunu-Pétr, the other Blán.
Swein and his men seized them, and took from them all their goods,
and brought them to land. A gallows was erected for them, and
when everything was ready Swein said they should be allowed to
run up the country, adding that they were greater shame to their
brother Jón alive than dead. They were a long time out on the hills,
and when they came to some habitations they were very much frost-
bitten.
From thence Swein went to Liódhús, in the Sudreyar, and stayed
there some time. When Jón Vœng heard that Swein had taken his
brothers prisoners, and not knowing what he had done with them,
he went to Eyin Helga (Enhallow), and took Olaf, the son of Swein,
Asleif’s son, and Kolbein Hruga’s foster-son, and brought him to
Westrey. They met Earl Rögnvald at Hreppisnes,[435] and when he
saw Olaf, he said: “Why are you here, Olaf?”
He said: “It is the work of Jón Vœng.”
The Earl looked to Jón, and said: “Why did you bring Olaf here?”
He replied: “Swein took my brothers, and I don’t know but he may
have killed them.”
The Earl said: “Take him back again as quickly as you can, and do
not dare to do him any harm, whatever may have become of your
brothers, for if you do, you will not be safe in the Islands from either
Swein or Kolbein.”
CHAPTER CII

OF EARL RÖGNVALD.

After Easter Swein commenced a journey to the Sudreyar, taking


with him sixty men. He went to the Orkneys, and landed first in
Hrólfsey (Rousay). There they took a man, by name Hákon Karl,[436]
who had been with Earl Harald when Earl Erlend was slain. Hákon
ransomed himself with three marks of gold, and thus saved himself
from Swein. In Hrólfsey Swein found the ship which the Earls had
taken from him, and two of the planks were cut, which had been
done by Earl Rögnvald’s order, because Swein had refused to buy it
or to accept it as a gift from the Earls. Swein went from there to
Hrossey, and met Earl Rögnvald at Birgishérad (Birsay). The Earl
received him well, and Swein spent the spring with him. Earl
Rögnvald said that he had ordered the planks of the ship to be cut,
because he did not wish him to row about rashly among the Islands
when he came from the Sudreyar. Earl Harald came from Hjaltland in
the spring during the Whitsuntide, and when he came to the
Orkneys Earl Rögnvald sent men to him to say that he wished the
compact of peace between him and Swein to be renewed, and a
peace meeting was appointed in St. Magnus’s church on Friday
during the holy week. Earl Rögnvald carried a broad axe to the
meeting, and Swein went with him. Then the peace compact which
had been made in the winter was confirmed.
CHAPTER CIII

OF SWEIN, ASLEIF’S SON.

Then Earl Rögnvald gave Earl Harald the ship which had belonged to
Swein, but all other things which had been awarded him from Swein
he returned to him. Earl Rögnvald and Swein were standing at the
church-door while the sail, which had been lying in St. Magnus’s
church, was carried out, and Swein looked rather gloomy. The
following Saturday, after noontide service, Earl Harald’s men came to
Swein, Asleif’s son, and said the Earl wished him to come to speak
with him. Swein consulted Earl Rögnvald, but he did not say much in
favour of his going, and added that one did not know whom to trust.
Swein went, nevertheless, with five men. The Earl was sitting on a
cross bench in a small room, and Thorbiörn Klerk beside him. A few
other men were with the Earl, and they sat for a while and drank.
Then Thorbiörn left the room, and Swein’s companions said to him
that they distrusted the Earl’s conduct very much. Thorbiörn
returned shortly after, and presented Swein with a scarlet tunic and
a cloak, saying that he did not know whether he would call it a gift,
because these things had been taken from Swein in the winter.
Swein accepted the gifts. Earl Harald restored to him the long-ship
which had belonged to him, and the half of his property and estates.
He asked him to stay with him, and said their friendship should
never be dissolved. Swein accepted all this gladly, and went
immediately the same night and told Earl Rögnvald how matters had
turned out between him and Earl Harald. Earl Rögnvald said he was
much pleased with this, and told Swein to take care that they did not
become enemies again.
CHAPTER CIV

OF THE EARLS.

A short time after, the three chiefs—Swein, Thorbiörn, and Eirik—


went out on a plundering expedition. They went first to the
Sudreyar, and all along the west to the Syllingar, where they gained
a great victory in Maríuhöfn[437] on Columba’s-mas (9th June), and
took much booty. Then they returned to the Orkneys.
When the Earls Harald and Rögnvald had made peace with Swein,
Asleif’s son, they were always together, and Earl Rögnvald governed,
but they agreed very well. When they came home from the Syllingar,
Thorbiörn Klerk went to Earl Harald, and became his counsellor.
Swein went home to Gáreksey, and resided there during the winter
with many men, living upon his booty, and other stores which he
possessed there in the Islands. He was most attached to Earl
Rögnvald. Every summer he was out on marauding expeditions. It
was said that Thorbiörn did not improve the harmony between Earl
Harald and Earl Rögnvald.
Thórarinn Killinef was one of Earl Rögnvald’s men, a great friend
of his, and was always with the Earl. A man named Thorkel was one
of Thorbiörn Klerk’s followers, and a friend of his. Thórarinn and
Thorkel quarrelled over their drink at Kirkiuvag, and Thorkel
wounded Thórarinn, and then escaped to Thorbiörn. Thórarinn’s
companions pursued Thorkel, but Thorbiörn and his men defended
themselves in a loft. The Earls were informed of this, and they went
to part them. Thorbiörn refused to leave the decision of this case to
Earl Rögnvald, as it was his men that were concerned in the pursuit.
When Thórarinn had recovered from his wounds, he slew Thorkel as
he was going to church. He ran into the church, but Thorbiörn and
his men pursued him. Earl Rögnvald was told what was happening,
and he went there with his men, and asked Thorbiörn whether he
was going to break the church open. Thorbiörn said the church
ought not to shelter him who was within. Earl Rögnvald said there
should be no violation of the church at this time, and Thorbiörn was
pushed away from it. No agreement was come to about this case.
Thorbiörn went over to Caithness, and was there for a while. Then
many things happened to estrange them, for Thorbiörn was often
guilty of violence to women, and of manslaying. He went secretly
out to the Orkneys in a boat with thirty men, and landed at Skálpeid,
and walked to Kirkiuvag with three men. In the evening he went
alone into an inn where Thórarinn was drinking, and struck him a
death-blow immediately. Then he ran out into the darkness and far
away. For this the Earl made him an outlaw in every part of his
dominions. Thorbiörn went over to Ness, and remained in hiding
with his brother-in-law, Hösvir, who was called the strong. He had
married Thorbiörn’s sister, Ragnhild, and their son was Stefán
Rádgiafi (counsellor), Thorbiörn’s follower. Shortly afterwards
Thorbiörn went to Malcolm, King of Scots, and remained there a
while, in high favour with the King. There was a man called
Gillaodran with the King of Scots. He was of a great family, but a
violent man. He had incurred the displeasure of the King of Scots for
violent acts and manslaughters which he had committed in his
kingdom. He fled to the Orkneys, and the Earls received him. Then
he went to Caithness, and acted as a steward for the Earls. There
was a noble Bondi in Caithness, by name Helgi, a friend of Earl
Rögnvald’s. Gillaodran quarrelled with him about the stewardship,
and Gillaodran attacked and killed him. After the slaughter he went
west to Scotland’s Fiord, and was received by a chief named
Sumarlidi Höld,[438] who had possessions in Dalir, on Scotland’s Fiord.
His wife was Ragnhild, the daughter of Olaf Bitling (little bit), King of
the Sudreyar. Their sons were King Dufgall, Rögnvald, and Engull.[439]
They were called the Dalverja family.
Earl Rögnvald sent for Swein, Asleif’s son, before he went out on
his expedition. When they met, Earl Rögnvald asked him to have an
eye on Gillaodran if he had an opportunity. Swein said he did not
know how far he might succeed.
CHAPTER CV

SWEIN SLAYS SUMARLIDI.

Then Swein went on a marauding expedition, having five long-ships.


When he came west to Scotland’s Fiord, he heard that Sumarlidi
Höld had gone on board a ship, and was about to set out on an
expedition. He had seven ships, and Gillaodran commanded one. He
had gone into the firths to bring up some troops that had not
arrived. When Swein heard of Sumarlidi, he gave him battle, and it
was a fierce fight. Sumarlidi Höld was killed in that fight, and many
men with him. When Swein became aware that Gillaodran was not
there, he went in search of him, and slew him in Myrkvifiörd,[440] and
fifty men with him. Then he went on his expedition, and returned
home in the autumn, as his custom was. He went to see Earl
Rögnvald soon after his return, and he was much pleased with these
deeds.
CHAPTER CVI

OF EARL RÖGNVALD AND EARL HARALD.

Every summer the Earls were wont to go over to Caithness, and up


into the forests to hunt the red-deer or the reindeer.[441] Thorbiörn
Klerk was with the King of Scots, and sometimes he went to
Caithness and stayed in hiding with his friends. He had three friends
in Caithness whom he trusted most. One was his brother-in-law,
Hösvir; the second, Liótólf, who lived in Thórsdal; and the third was
Hallvard, Dúfa’s son, in Kálfadal (Calder), at a certain promontory off
Thórsdal. All these were his intimate friends.
CHAPTER CVII

THE SLAYING OF EARL RÖGNVALD.

When Earl Rögnvald had been an Earl two-and-twenty winters from


the time that Earl Paul was taken prisoner, the Earls went over to
Caithness during the latter part of the summer as usual, and when
they came to Thórsá they heard a rumour to the effect that
Thorbiörn was there in hiding with not a few men, and that he
intended to attack them if he had an opportunity. Then the Earls
called men together, and went with a hundred men, twenty of whom
were on horseback and the rest on foot. In the evening they went
up into the valley,[442] and took up their quarters for the night. When
they were sitting by the fire in the evening, Earl Rögnvald sneezed
very much. Earl Harald said: “That was a loud sneeze, kinsman.” In
the morning they went along the valley.
During the day Earl Rögnvald rode always ahead of his men, and a
man with him called Asólf, and another by name Jómar, his kinsman.
They rode five together along Kálfadal; and when they came to the
farm, farmer Höskuld was on the top of a corn-stack piling up the
corn, which his servants brought to him. Earl Harald was some
distance behind. When Höskuld recognised Earl Rögnvald, he saluted
him by name, and asked for news, speaking very loud, so that he
could be heard far away. This was a short distance from the sitting-
room of the house. The homestead stood on an eminence, and one
had to go through narrow and very steep passages up to it.
Thorbiörn was at this farm, and was sitting indoors drinking. The
passages led to the end of the house close to the gable, which had a
door filled loosely with stones. Thorbiörn and his men, hearing the
words of Höskuld when he saluted Earl Rögnvald, seized their
weapons, pushed the stones from the concealed door, and ran out.
Thorbiörn ran round the gable, and on to the wall of the passage.
The Earl was then close to the door. Thorbiörn struck at him, and
Asólf warded off the blow with his hand, and it was cut off; and then
the sword touched the Earl’s chin, inflicting a great wound.
On receiving the blow Asólf said: “Let them serve the Earl better
who have to thank him for greater gifts.” He was then eighteen
winters old, and had lately entered the Earl’s service.
Earl Rögnvald was going to jump off his horse, and his foot stuck
fast in the stirrup. At that moment Stefán arrived and stabbed him
with a spear; and Thorbiörn wounded him again; but Jómar stabbed
Thorbiörn in the thigh, the spear entering the bowels. Then
Thorbiörn and his men ran behind the homestead, and down a steep
bank, into a wet morass. Then Earl Harald and his men arrived and
met Thorbiörn. They recognised each other, and the Earl’s men,
when they knew his intentions, advised to pursue him; but Earl
Harald dissuaded them from it, saying that he wished to wait for Earl
Rögnvald’s opinion, “Because,” said he, “I am very intimately
connected with Thorbiörn, as you know, both through relationship
and other ties.”
Those who were with Earl Rögnvald stood sorrowing over his dead
body, and some time passed before Earl Harald heard the news.
Thorbiörn and his men had got out on the bog, and across the
moss-hag running along it. But through the urgency of the Earl’s
followers, he and his men ran down to the bog, and they met at the
moss-hag—the two parties standing one on either side. Thorbiörn’s
party defended themselves from the bank, and his followers ran to
his assistance from the neighbouring homesteads, until they were
fifty in number. They defended themselves bravely, for they had a
strong position. The moss-hag was both deep and broad, and the
bog was soft; so they could only hurl spears at each other. Thorbiörn
told his men to throw none back; and when the Earl’s party had
exhausted their missiles they spoke to each other, and Thorbiörn
called to Earl Harald, saying, “Kinsman! I wish to ask you to give me
quarter, and I am willing to leave the decision of this case entirely in
your hands. I will reserve nothing which may contribute to your
honour. I also think, kinsman, you must remember that there have
been quarrels in which you would not have made such a difference
between Earl Rögnvald and me that you would have killed me for
having done this deed, when he had you under his thumb, and left
you no more power than if you had been his page; but I gave you
the best gifts, and endeavoured to further your honour in every way
I could. The deed which I have committed is indeed a great crime,
and weighs heavily upon me, but the whole of his dominions revert
to you. You may also know that Earl Rögnvald intended for me the
same fate which he met at my hands. And I suspect, kinsman, that if
it had so happened that I were dead, and Earl Rögnvald alive, you
would not have quarrelled with him; and yet you wish to take away
my life.”
Thorbiörn urged his case with many fair words, and many pleaded
for him, and begged that quarter might be given him. And at last,
when so many pleaded, the Earl began to listen to them.
Then Magnus, the son of Gunni, Hávard’s son, a chief and a
kinsman of the Earl’s, and the noblest born of Earl Harald’s followers,
took speech as follows:—“We are not able to counsel you, Earl, after
these great deeds, but I shall tell you what will be said if quarter is
given to Thorbiörn when he has done such a deed, and even dared
to say to your face, almost in so many words, that he has done this
wickedness in your interest, or for your honour; and it will be an
everlasting shame and dishonour to you and to all the Earl’s kinsmen
if he is not avenged. I think Earl Rögnvald’s friends will believe it to
be the truth that for a long time you have been planning his death,
and that it is your plan which has now been accomplished. Do you
think he will acquit you from complicity in his guilt when he has to
defend himself; since no one says a word for you when he tells you
to your face that he has committed this crime in your interest? And
how can you better confirm this suspicion than by now granting him
peace? I have resolved, for my part, never to give him quarter, if any
doughty men are willing to follow me, whether you like it or not.”
His brother Thorstein, and Hákon, and Swein, Hróald’s son, spoke
to the same effect. Then they left the Earl and went along by the
moss-hag, trying to find a place where they might cross.
When Thorbiörn saw Magnus and his followers walking along the
moss-hag, he said: “Now, I suppose, they must have disagreed in
their counsels; the Earl has wished to give me peace, and Magnus
has spoken against it.”
While they were thus talking, Thorbiörn and his men went farther
away from the moss-hag.
Harald’s party stood on the brink, and when he saw that no
quarter would be given, he leapt across in full armour, though it was
nine ells[443] broad. His followers leapt after him, but none of them
were able to leap so far; and most of them caught the bank and
crawled up out of the mud.
Thorbiörn’s men urged him to advance against Magnus and his
men, and decide the matter with them; but he said: “I think the best
plan is, that each of you do what he thinks likely to be best, but I
shall go to Earl Harald.”
Most of his men dissuaded him from this, and begged him rather
to flee to the woods and save himself. He did not, however, accept
that advice. Then his followers left him, and tried to save themselves
in various ways, and at last there were eight men only with
Thorbiörn. When he saw that Earl Harald had crossed the ditch, he
went to him and fell on his knees, saying that he brought his head to
him. Many of the Earl’s men asked that peace might be given him;
and the Earl said: “Save yourself, Thorbiörn; I have not the heart to
kill you.”
While they were talking, they moved down the valley along
Kalfadalsá,[444] and Magnus’s party pursued them. When the Earl saw
it, he said: “Save yourself, Thorbiörn, I will not fight for you against
my men.” Then Thorbiörn and his men left the Earl’s party, and went
to some deserted shielings called Asgrím’s ærgin.[445] Magnus’s party
pursued them, and set the buildings on fire immediately. Thorbiörn
and his men defended themselves bravely; and when the buildings
began to fall down with the burning, they went out and were
attacked by the other party with their weapons, as soon as they
could reach them. They were already very much exhausted by the
fire, and fell there all nine. When Thorbiörn’s wounds were
examined, it was found that the intestines protruded through the
wound inflicted by Jómar. Earl Harald led his men down the valley,
but those who were with Magnus went to Fors (Forss), wrapped up
Earl Rögnvald’s body, and brought it down to Thórsá.
CHAPTER CVIII

THE REMOVAL OF EARL RÖGNVALD’S BODY.

Earl Rögnvald Kali died five nights after the summer Marymas.[446]
Earl Harald brought the body with a splendid following to the
Orkneys, and it was buried at the Magnus Kirk; and there it rested
until God manifested Rögnvald’s merits by many and great miracles.
Then Bishop Bjarni had his holy remains exhumed with the
permission of the Pope.[447] Where the blood of the Earl fell on the
stones when he died, it may be seen to this day as fresh as if it had
just come from the wounds.
Earl Rögnvald’s death was much lamented, because he was very
popular in the Islands and in many other parts. He had been helpful
to many, was liberal with his money, gentle, and a true friend, highly
accomplished, and a good scald. He left a daughter, Ingigerd, an
only child, who was married to Eirík Slagbrellir. Their children were
Harald Ungi, Magnus Mangi, Rögnvald, Ingibiorg, Elín, and Ragnhild.
CHAPTER CIX

OF HARALD AND SWEIN.

After Earl Rögnvald’s death, Earl Harald took possession of the


whole of the Islands, and became their sole ruler. He was a mighty
chief, and a man of large stature and great strength. His wife was
Afreka, and their children were—Heinrek, Hákon, Helena, and
Margarét. When Hákon was only a few winters old, Swein, Asleif’s
son, offered to foster him, and when he was able to take his part
with other men, Swein took him out on marauding expeditions every
summer, and honoured him in everything. Swein used to reside at
home in Gáreksey, in winter, keeping there eighty men at his own
expense. He had such a large drinking-hall that there was none
equal to it anywhere else in the Orkneys. In the spring he was very
busy sowing a large breadth of seed, and he usually did a great part
of the work himself. When this work was finished, he went every
spring on marauding expeditions. He plundered in the Sudreyar and
Ireland, and returned home after midsummer. This he called spring-
viking. Then he stayed at home till the fields were reaped and the
corn brought in. Then he went out again, and did not return until
one month of winter had passed. This he called autumn-viking.
CHAPTER CX

SWEIN GOES TO IRELAND.

Once it happened that Swein went out on a spring expedition, taking


with him Hákon, the son of Earl Harald. They had five rowing ships,
all large. They plundered in the Sudreyar. All the inhabitants were so
afraid of him that they hid all their movable property in the ground
or in heaps of loose stones. Swein went all the way south to Man,
and obtained very little booty. Then they went to Ireland and
plundered there, but when they were approaching Dýflin (Dublin)
two merchant-ships came from England, laden with English cloth
and other merchandise; they were going to Dýflin. Swein made for
the vessels, and offered them battle. There was little resistance by
the English, and Swein’s party took every penny in the vessels,
leaving to the Englishmen only what they stood in, and a small
quantity of provisions. They sailed away in the vessels, but Swein’s
party went to the Sudreyar, and divided their booty. They sailed from
the west with great pomp. When they were lying in harbours, they
covered their ships with the English cloth, to make a show; and
when they sailed to the Orkneys, they sewed the cloth upon their
sails, and then it looked as if the sails were made entirely of the fine
stuffs. This they named the Skrud-viking.[448]
Swein went home to his estate in Gáreksey. He had taken a large
quantity of wine and English mead from the vessels. When he had
been at home a short time he invited Earl Harald, and prepared a
splendid feast for him. When Earl Harald was at the feast a great
deal was said of Swein’s magnificence. The Earl said: “I wish, Swein,
you would now leave off your marauding expeditions; it is good now
to drive home a whole waggon. You know that your plundering has
fed you and your men a long time, but to most men of violence it
happens that they perish in their raiding, if they do not leave it off in
time.”
Swein looked to the Earl and said, smiling: “This is well said, my
Lord; you have spoken like a friend, and it is good to take sound
advice from you; but some complain that you are not an over just
man yourself.”
The Earl replied: “I must be responsible for my own acts, but I
spoke as it occurred to me.”
Swein replied: “Your intention is no doubt good, my Lord; and it
shall be so, that I will discontinue my marauding expeditions, for I
am getting old, and my strength is wasting away in the wet work
and the fighting. I am now going to make an autumn expedition,
and I wish it to be not less glorious than the spring one. Then I shall
leave off war-going.”
The Earl replied: “It is difficult to know, comrade, which comes
first—death or lasting fame.”
Then their conversation ceased. When Earl Harald left the feast
honourable gifts were presented to him, and he and Swein parted
very good friends.
CHAPTER CXI

SWEIN, ASLEIF’S SON’S (LAST) EXPEDITION.

Shortly after this Swein prepared to go on a marauding expedition


with seven long-ships, all of them large. Hákon, the son of Earl
Harald, went with him. They went first to the Sudreyar, and found
there little booty. Then they went to Ireland, and plundered there in
many places. They went all the way south to Dýflin (Dublin), and
took the inhabitants by surprise, so that they did not know till they
were in the town. They took a great deal of plunder, and took
captive the rulers of the city, and their negotiations ended in the
surrender of the town to Swein, and they promised to pay as much
money as he might levy on them. He was to quarter his men on the
town, and have the command of it, and the Dýflin men confirmed
this arrangement with oaths. Swein and his men went down to their
ships in the evening, but in the morning they were to come into the
town and receive hostages from the inhabitants.
Now it is to be told what was going on in the town during the
night. The rulers of the town had a meeting, and considered the
difficulties in which they were placed. They thought it a grievous
hardship that they should have to surrender their town to the
Orkneymen, especially to him whom they knew to be the most
exacting man in the whole West; and they came to the
determination to play him false if they could. They resolved to dig
large pits inside of the city gates, and in many other places between
the houses, where it was intended that Swein’s men should come in,
and armed men were hidden in the houses close by. They placed
such coverings over the pits as were sure to fall in when the weight

You might also like