Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (3 votes)
2K views65 pages

Hands-on Scikit-Learn for machine learning applications: data science fundamentals with Python David Paper all chapter instant download

fundamentals

Uploaded by

reinikriegze
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (3 votes)
2K views65 pages

Hands-on Scikit-Learn for machine learning applications: data science fundamentals with Python David Paper all chapter instant download

fundamentals

Uploaded by

reinikriegze
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 65

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Hands-on Scikit-Learn for machine learning


applications: data science fundamentals with
Python David Paper

https://textbookfull.com/product/hands-on-scikit-learn-for-
machine-learning-applications-data-science-fundamentals-
with-python-david-paper/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Hands On Machine Learning with Scikit Learn and TensorFlow


Aurélien Géron

https://textbookfull.com/product/hands-on-machine-learning-with-
scikit-learn-and-tensorflow-aurelien-geron/

textboxfull.com

Hands On Machine Learning with Scikit Learn and TensorFlow


1st Edition Aurélien Géron

https://textbookfull.com/product/hands-on-machine-learning-with-
scikit-learn-and-tensorflow-1st-edition-aurelien-geron/

textboxfull.com

Hands On Machine Learning with Scikit Learn and TensorFlow


Early Release 2nd Edition Aurélien Géron

https://textbookfull.com/product/hands-on-machine-learning-with-
scikit-learn-and-tensorflow-early-release-2nd-edition-aurelien-geron/

textboxfull.com

Data Science Fundamentals for Python and MongoDB 1st


Edition David Paper

https://textbookfull.com/product/data-science-fundamentals-for-python-
and-mongodb-1st-edition-david-paper/

textboxfull.com
Hands On Machine Learning with Scikit Learn Keras and
TensorFlow Concepts Tools and Techniques to Build
Intelligent Systems 2nd Edition Aurelien Geron [Géron
https://textbookfull.com/product/hands-on-machine-learning-with-
scikit-learn-keras-and-tensorflow-concepts-tools-and-techniques-to-
build-intelligent-systems-2nd-edition-aurelien-geron-geron/
textboxfull.com

Machine Learning Theory and Applications: Hands-on Use


Cases with Python on Classical and Quantum Machines 1st
Edition Vasques
https://textbookfull.com/product/machine-learning-theory-and-
applications-hands-on-use-cases-with-python-on-classical-and-quantum-
machines-1st-edition-vasques/
textboxfull.com

Hands On Unsupervised Learning Using Python How to Build


Applied Machine Learning Solutions from Unlabeled Data 1st
Edition Ankur A. Patel
https://textbookfull.com/product/hands-on-unsupervised-learning-using-
python-how-to-build-applied-machine-learning-solutions-from-unlabeled-
data-1st-edition-ankur-a-patel/
textboxfull.com

Introduction to Machine Learning with Python A Guide for


Data Scientists Andreas C. Müller

https://textbookfull.com/product/introduction-to-machine-learning-
with-python-a-guide-for-data-scientists-andreas-c-muller/

textboxfull.com

Advanced Data Analytics Using Python: With Machine


Learning, Deep Learning and NLP Examples Mukhopadhyay

https://textbookfull.com/product/advanced-data-analytics-using-python-
with-machine-learning-deep-learning-and-nlp-examples-mukhopadhyay/

textboxfull.com
David Paper

Hands-on Scikit-Learn for Machine


Learning Applications
Data Science Fundamentals with Python
David Paper
Logan, UT, USA

Any source code or other supplementary material referenced by the


author in this book is available to readers on GitHub via the book’s
product page, located at www.​apress.​com/​9781484253724 . For more
detailed information, please visit http://​www.​apress.​com/​source-code
.

ISBN 978-1-4842-5372-4 e-ISBN 978-1-4842-5373-1


https://doi.org/10.1007/978-1-4842-5373-1

© David Paper 2020

This work is subject to copyright. All rights are reserved by the


Publisher, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other
physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather
than use a trademark symbol with every occurrence of a trademarked
name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark. The use in this publication
of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of
opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true
and accurate at the date of publication, neither the authors nor the
editors nor the publisher can accept any legal responsibility for any
errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained
herein.

Distributed to the book trade worldwide by Springer Science+Business


Media New York, 233 Spring Street, 6th Floor, New York, NY 10013.
Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-
ny@springer-sbm.com, or visit www.springeronline.com. Apress Media,
LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM
Finance Inc is a Delaware corporation.
For my mother, brothers, and friends.
Introduction
We apply the popular Scikit-Learn library to demonstrate machine
learning exercises with Python code to help readers solve machine
learning problems. The book is designed for those with intermediate
programming skills and some experience with machine learning
algorithms. We focus on application of the algorithms rather than
theory. So, readers should read about the theory online or from other
sources if appropriate. The reader should also be willing to spend a lot
of time working through the code examples because they are pretty
deep. But, the effort will pay off because the examples are intended to
help the reader tackle complex problems.
The book is organized into eight chapters. Chapter 1 introduces the
topic of machine learning, Anaconda, and Scikit-Learn. Chapters 2 and 3
introduce algorithmic classification. Chapter 2 classifies simple data
sets and Chapter 3 classifies complex ones. Chapter 4 introduces
predictive modeling with regression. Chapters 5 and 6 introduce
classification tuning. Chapter 5 tunes simple data sets and Chapter 6
tunes complex ones. Chapter 7 introduces predictive modeling
regression tuning. Chapter 8 puts all knowledge together to review and
present findings in a holistic manner.
Download this book’s example data by clicking the Download
source code button found on the book’s catalog page at
https://www.apress.com/us/book/9781484253724​.
Table of Contents
Chapter 1:​Introduction to Scikit-Learn
Machine Learning
Anaconda
Scikit-Learn
Data Sets
Characterize Data
Simple Classification Data
Complex Classification Data
Regression Data
Feature Scaling
Dimensionality Reduction
Chapter 2:​Classification from Simple Training Sets
Simple Data Sets
Classifying Wine Data
Classifying Digits
Classifying Bank Data
Classifying make_​moons
Chapter 3:​Classification from Complex Training Sets
Complex Data Sets
Classifying fetch_​20newsgroups
Classifying MNIST
Classifying fetch_​lfw_​people
Chapter 4:​Predictive Modeling Through Regression
Regression Data Sets
Regressing tips
Regressing boston
Regressing wine data
Chapter 5:​Scikit-Learn Classifier Tuning from Simple Training
Sets
Tuning Data Sets
Tuning Iris Data
Tuning Digits Data
Tuning Bank Data
Tuning Wine Data
Chapter 6:​Scikit-Learn Classifier Tuning from Complex Training
Sets
Tuning Data Sets
Tuning fetch_​1fw_​people
Tuning MNIST
Tuning fetch_​20newsgroups
Chapter 7:​Scikit-Learn Regression Tuning
Tuning Data Sets
Tuning tips
Tuning boston
Tuning wine
Chapter 8:​Putting It All Together
The Journey
Value and Cost
MNIST Value and Cost
Explaining MNIST to Money People
Explaining Output to Money People
Explaining the Confusion Matrix to Money People
Explaining Visualizations to Money People
Value and Cost
fetch_​lfw_​people Value and Cost
Explaining fetch_​lfw_​people to Money People
Explaining Output to Money People
Explaining Visualizations to Money People
Value and Cost
fetch_​20newsgroups Value and Cost
Explaining fetch_​20newsgroups to Money People
Explaining Output to Money People
Explaining the Confusion Matrix to Money People
Value and Cost
Index
About the Author and About the Technical
Reviewer

About the Author


David Paper
is a professor at Utah State University in
the Management Information Systems
department. He is the author of two
books –Web Programming for Business:
PHP Object-Oriented Programming with
Oracle andData Science Fundamentals for
Python and MongoDB . He has over
70 publications in refereed journals such
asOrganizational Research Methods
,Communications of the ACM, Information
& Management ,Information Resource
Management Journal ,Communications of
the AIS ,Journal of Information
Technology Case and Application
Research , andLong Range Planning . He
has also served on several editorial
boards in various capacities, including
associate editor. Besides growing up in family businesses, Dr. Paper has
worked for Texas Instruments, DLS, Inc., and the Phoenix Small
Business Administration. He has performed IS consulting work for IBM,
AT&T, Octel, Utah Department of Transportation, and the Space
Dynamics Laboratory. Dr. Paper’s teaching and research interests
include data science, machine learning, process reengineering, object-
oriented programming, and change management.

About the Technical Reviewer


Jojo Moolayil
is an artificial intelligence, deep learning,
machine learning, and decision science
professional and published author of
three books:Smarter Decisions – The
Intersection of Internet of Things and
Decision Science ,Learn Keras for Deep
Neural Networks , andApplied Supervised
Learning with R . He has worked with
industry leaders on several high-impact
and critical data science and machine
learning projects across multiple
verticals. He is currently associated with
Amazon Web Services as a research
scientist – AI.
Jojo was born and raised in Pune,
India, and graduated from the University
of Pune with a major in Information
Technology Engineering. He started his
career with Mu Sigma Inc., the world’s largest pure-play analytics
provider, and worked with the leaders of many Fortune 50 clients. He
later worked with Flutura – an IoT analytics start-up – and GE, the
pioneer and leader in Industrial AI.
He currently resides in Vancouver, BC. Apart from authoring books
on deep learning, decision science, and IoT, Jojo has also been a
technical reviewer for various books on the same subject with Apress
and Packt publications. He is an active Data Science tutor and maintains
a blog at http://blog.jojomoolayil.com .
Jojo’s personal web site: www.jojomoolayil.com
Business e-mail:mail@jojomoolayil.com
© David Paper 2020
D. Paper, Hands-on Scikit-Learn for Machine Learning Applications
https://doi.org/10.1007/978-1-4842-5373-1_1

1. Introduction to Scikit-Learn
David Paper1

(1) Logan, UT, USA

Scikit-Learn is a Python library that provides simple and efficient tools for implementing
supervised and unsupervised machine learning algorithms. The library is accessible to everyone
because it is open source and commercially usable. It is built on NumPY, SciPy, and matplolib
libraries, which means it is reliable, robust, and core to the Python language.
Scikit-Learn is focused on data modeling rather than data loading, cleansing, munging or
manipulating. It is also very easy to use and relatively clean of programming bugs.

Machine Learning
Machine learning is getting computers to program themselves. We use algorithms to make this
happen. An algorithm is a set of rules used to calculate or problem solve with a computer.
Machine learning advocates create, study, and apply algorithms to improve performance on
data-driven tasks. They use tools and technology to answer questions about data by training a
machine how to learn.
The goal is to build robust algorithms that can manipulate input data to predict an output
while continually updating outputs as new data becomes available. Any information or data sent
to a computer is considered input. Data produced by a computer is considered output.
In the machine learning community, input data is referred to as the feature set and output data
is referred to as the target. The feature set is also referred to as the feature space. Sample data is
typically referred to as training data. Once the algorithm is trained with sample data, it can make
predictions on new data. New data is typically referred to as test data.
Machine learning is divided into two main areas: supervised and unsupervised learning. Since
machine learning typically focuses on prediction based on known properties learned from
training data, our focus is on supervised learning.
Supervised learning is when the data set contains both inputs (or the feature set) and desired
outputs (or targets). That is, we know the properties of the data. The goal is to make predictions.
This ability to supervise algorithm training is a big part of why machine learning has become so
popular.
To classify or regress new data, we must train on data with known outcomes. We classify data
by organizing it into relevant categories. We regress data by finding the relationship between
feature set data and target data.
With unsupervised learning, the data set contains only inputs but no desired outputs (or
targets). The goal is to explore the data and find some structure or way to organize it. Although
not the focus of the book, we will explore a few unsupervised learning scenarios.

Anaconda
You can use any Python installation, but I recommend installing Python with Anaconda for several
reasons. First, it has over 15 million users. Second, Anaconda allows easy installation of the
desired version of Python. Third, it preinstalls many useful libraries for machine learning
including Scikit-Learn. Follow this link to see the Anaconda package lists for your operating
system and Python version: https://docs.anaconda.com/anaconda/packages/pkg-
docs/. Fourth, it includes several very popular editors including IDLE, Spyder, and Jupyter
Notebooks. Fifth, Anaconda is reliable and well-maintained and removes compatibility
bottlenecks.
You can easily download and install Anaconda with this link:
https://www.anaconda.com/download/. You can update with this link:
https://docs.anaconda.com/anaconda/install/update-version/. Just open
Anaconda and follow instructions. I recommend updating to the current version.

Scikit-Learn
Python’s Scikit-Learn is one of the most popular machine learning libraries. It is built on Python
libraries NumPy, SciPy, and Matplotlib. The library is well-documented, open source,
commercially usable, and a great vehicle to get started with machine learning. It is also very
reliable and well-maintained, and its vast collection of algorithms can be easily incorporated into
your projects. Scikit-Learn is focused on modeling data rather than loading, manipulating,
visualizing, and summarizing data. For such activities, other libraries such as NumPy, pandas,
Matplotlib, and seaborn are covered as encountered. The Scikit-Learn library is imported into a
Python script as sklearn.

Data Sets
A great way to understand machine learning application is by working through Python data-
driven code examples. We use either Scikit-Learn, UCI Machine Learning, or seaborn data sets for
all examples. The Scikit-Learn data sets package embeds some small data sets for getting started
and helpers to fetch larger data sets commonly used in the machine learning library to benchmark
algorithms on data from the world at large. The UCI Machine Learning Repository maintains 468
data sets to serve the machine learning community. Seaborn provides an API on top of Matplotlib
that offers simplicity when working with plot styles, color defaults, and high-level functions for
common statistical plot types that facilitate visualization. It also integrates nicely with Pandas
DataFrame functionality.
We chose the data sets for our examples because the machine learning community uses them
for learning, exploring, benchmarking, and validating, so we can compare our results to others
while learning how to apply machine learning algorithms.
Our data sets are categorized as either classification or regression data. Classification data
complexity ranges from simple to relatively complex. Simple classification data sets include
load_iris, load_wine, bank.csv, and load_digits. Complex classification data sets include
fetch_20newsgroups, MNIST, and fetch_1fw_people. Regression data sets include tips, redwine.csv,
whitewine.csv, and load_boston.

Characterize Data
Before working with algorithms, it is best to understand the data characterization. Each data set
was carefully chosen to help you gain experience with the most common aspects of machine
learning. We begin by describing the characteristics of each data set to better understand its
composition and purpose. Data sets are organized by classification and regression data.
Classification data is further organized by complexity. That is, we begin with simple
classification data sets that are not complex so that the reader can focus on the machine learning
content rather than on the data. We then move onto more complex data sets.

Simple Classification Data


Classification is a machine learning technique for predicting the class upon which a dependent
variable belongs. A class is a discrete response. In machine learning, a dependent variable is
typically referred to as the target. A class is predicted based upon the independent variables of a
data set. Independent variables are typically referred to as the feature set or feature space. Feature
space is the collection of features used to characterize the data.
Simple data sets are those with a limited number of features. Such a data set is referred to as
one with a low-dimensional feature space.

Iris Data
The first data set we characterize is load_iris, which consists of Iris flower data. Iris is a
multivariate data set consisting of 50 samples from each of three species of iris (Iris setosa, Iris
virginica, and Iris versicolor). Each sample contains four features, namely, length and width of
sepals and petals in centimeters. Iris is a typical test case for machine learning classification. It is
also one of the best known data sets in the data science literature, which means you can test your
results against many other verifiable examples.
The first code example shown in Listing 1-1 loads Iris data, displays its keys, shape of the
feature set and target, feature and target names, a slice from the DESCR key, and feature
importance (from most to least).

from sklearn import datasets


from sklearn.ensemble import RandomForestClassifier

if __name__ == "__main__":
br = '\n'
iris = datasets.load_iris()
keys = iris.keys()
print (keys, br)
X = iris.data
y = iris.target
print ('features shape:', X.shape)
print ('target shape:', y.shape, br)
features = iris.feature_names
targets = iris.target_names
print ('feature set:')
print (features, br)
print ('targets:')
print (targets, br)
print (iris.DESCR[525:900], br)
rnd_clf = RandomForestClassifier(random_state=0,
n_estimators=100)
rnd_clf.fit(X, y)
rnd_name = rnd_clf.__class__.__name__
feature_importances = rnd_clf.feature_importances_
importance = sorted(zip(feature_importances, features),
reverse=True)
print ('most important features' + ' (' + rnd_name + '):')
[print (row) for i, row in enumerate(importance)]
Listing 1-1 Characterize the Iris data set
Go ahead and execute the code from Listing 1-1. Remember that you can find the example
from the book’s example download. You don’t need to type the example by hand. It’s easier to
access the example download and copy/paste.
Your output from executing Listing 1-1 should resemble the following:

dict_keys(['data', 'target', 'target_names', 'DESCR',


'feature_names', 'filename'])

features shape: (150, 4)


target shape: (150,)

feature set:
['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal
width (cm)']

targets:
['setosa' 'versicolor' 'virginica']

============== ==== ==== ======= ===== ====================


Min Max Mean SD Class Correlation
============== ==== ==== ======= ===== ====================
sepal length: 4.3 7.9 5.84 0.83 0.7826
sepal width: 2.0 4.4 3.05 0.43 -0.4194
petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)
petal width:

most important features (RandomForestClassifier):


(0.4604447396171521, 'petal length (cm)')
(0.4241162651271012, 'petal width (cm)')
(0.09090795402103086, 'sepal length (cm)')
(0.024531041234715754, 'sepal width (cm)')

The code begins by importing datasets and RandomForestClassifier packages.


RandomForestClassifier is an ensemble learning method that constructs a multitude of decision
trees at training time and outputs the class that is the mode of the classes.
In this example, we are only using it to return feature importance. The main block begins by
loading data and displaying its characteristics. Loading feature set data into variable X and target
data into variable y is convention in the machine learning community.
The code concludes by training RandomForestClassifier on the pandas data, so it can return
feature importance. When actually modeling data, we convert pandas data to NumPy for optimum
performance. Keep in mind that the keys are available because the data set is embedded in Scikit-
Learn.
Notice that we only took a small slice from DESCR, which holds a lot of information about the
data set. I always recommend displaying at least the shape of the original data set before
embarking on any machine learning experiment.

Tip RandomForestClassifier is a powerful machine learning algorithm that not only models
training data, but returns feature importance.

Wine Data
The next data set we characterize is load_wine. The load_wine data set consists of 178 data
elements. Each element has thirteen features that describe three target classes. It is considered a
classic in the machine learning community and offers an easy multi-classification data set.
The next code example shown in Listing 1-2 loads wine data and displays its keys, shape of the
feature set and target, feature and target names, a slice from the DESCR key, and feature
importance (from most to least).

from sklearn.datasets import load_wine


from sklearn.ensemble import RandomForestClassifier

if __name__ == "__main__":
br = '\n'
data = load_wine()
keys = data.keys()
print (keys, br)
X, y = data.data, data.target
print ('features:', X.shape)
print ('targets', y.shape, br)
print (X[0], br)
features = data.feature_names
targets = data.target_names
print ('feature set:')
print (features, br)
print ('targets:')
print (targets, br)
rnd_clf = RandomForestClassifier(random_state=0,
n_estimators=100)
rnd_clf.fit(X, y)
rnd_name = rnd_clf.__class__.__name__
feature_importances = rnd_clf.feature_importances_
importance = sorted(zip(feature_importances, features),
reverse=True)
n = 6
print (n, 'most important features' + ' (' + rnd_name + '):')
[print (row) for i, row in enumerate(importance) if i < n]
Listing 1-2 Characterize load_wine

After executing code from Listing 1-2, your output should resemble the following:

dict_keys(['data', 'target', 'target_names', 'DESCR',


'feature_names'])

features: (178, 13)


targets (178,)

[1.423e+01 1.710e+00 2.430e+00 1.560e+01 1.270e+02 2.800e+00


3.060e+00
2.800e-01 2.290e+00 5.640e+00 1.040e+00 3.920e+00 1.065e+03]

feature set:
['alcohol', 'malic_acid', 'ash', 'alcalinity_of_ash', 'magnesium',
'total_phenols', 'flavanoids', 'nonflavanoid_phenols',
'proanthocyanins', 'color_intensity', 'hue',
'od280/od315_of_diluted_wines', 'proline']

targets:
['class_0' 'class_1' 'class_2']

6 most important features (RandomForestClassifier):


(0.19399882779940295, 'proline')
(0.16095401215681593, 'flavanoids')
(0.1452667364559143, 'color_intensity')
(0.11070045042456281, 'alcohol')
(0.1097465262717493, 'od280/od315_of_diluted_wines')
(0.08968972021098301, 'hue')

Tip To create (instantiate) a machine learning algorithm (model), just assign it to a variable
(e.g., model = algorithm()). To train based on the model, just fit it to the data (e.g., model.fit(X,
y)).

The code begins by importing load_wine and RandomForestClassifier. The main block displays
keys, loads data into X and y, displays the first vector from feature set X, displays shapes, and
displays feature set and target information. The code concludes by training X with
RandomForestClassifier, so we can display the six most important features. Notice that we display
the first vector from feature set X to verify that all features are numeric.

Bank Data
The next code example shown in Listing 1-3 works with bank data. The bank.csv data set is
composed of direct marketing campaigns from a Portuguese banking institution. The target is
described by whether a client will subscribe (yes/no) to a term deposit (target label y). It consists
of 41188 data elements with 20 features for each element. A 10% random sample of 4119 data
elements is also available from this site for more computationally expensive algorithms such as
svm and KNeighborsClassifier.

import pandas as pd

if __name__ == "__main__":
br = '\n'
f = 'data/bank.csv'
bank = pd.read_csv(f)
features = list(bank)
print (features, br)
X = bank.drop(['y'], axis=1).values
y = bank['y'].values
print (X.shape, y.shape, br)
print (bank[['job', 'education', 'age', 'housing',
'marital', 'duration']].head())
Listing 1-3 Characterize bank data
After executing code from Listing 1-3, your output should resemble the following:

['age', 'job', 'marital', 'education', 'default', 'housing', 'loan',


'contact', 'month', 'day_of_week', 'duration', 'campaign', 'pdays',
'previous', 'poutcome', 'emp.var.rate', 'cons.price.idx',
'cons.conf.idx', 'euribor3m', 'nr.employed', 'y']

(41188, 20) (41188,)

job education age housing marital duration


0 housemaid basic.4y 56 no married 261
1 services high.school 57 no married 149
2 services high.school 37 yes married 226
3 admin. basic.6y 40 no married 151
4 services high.school 56 no married 307

The code example begins by importing the pandas package. The main block loads bank data
from a CSV file into a Pandas DataFrame and displays the column names (or features). To retrieve
column names from pandas, all we need to do is make the DataFrame a list and assign the result
to a variable. Next, feature set X and target y are created. Finally, X and y shapes are displayed as
well as a few choice features.

Digits Data
The final code example in this subsection is load_digits. The load_digits data set consists of 1797 8
× 8 handwritten images. Each image is represented by 64 pixels (based on an 8 × 8 matrix), which
make up the feature set. Ten targets are predicted represented by digits zero to nine.
Listing 1-4 contains the code that characterizes load_digits.

import numpy as np
from sklearn.datasets import load_digits
import matplotlib.pyplot as plt

if __name__ == "__main__":
br = '\n'
digits = load_digits()
print (digits.keys(), br)
print ('2D shape of digits data:', digits.images.shape, br)
X = digits.data
y = digits.target
print ('X shape (8x8 flattened to 64 pixels):', end=' ')
print (X.shape)
print ('y shape:', end=' ')
print (y.shape, br)
i = 500
print ('vector (flattened matrix) of "feature" image:')
print (X[i], br)
print ('matrix (transformed vector) of a "feature" image:')
X_i = np.array(X[i]).reshape(8, 8)
print (X_i, br)
print ('target:', y[i], br)
print ('original "digits" image matrix:')
print (digits.images[i])
plt.figure(1, figsize=(3, 3))
plt.title('reshaped flattened vector')
plt.imshow(X_i, cmap="gray", interpolation="gaussian")
plt.figure(2, figsize=(3, 3))
plt.title('original images dataset')
plt.imshow(digits.images[i], cmap="gray",
interpolation='gaussian')
plt.show()
Listing 1-4 Characterize load_digits
After executing code from Listing 1-4, your output should resemble the following:

dict_keys(['data', 'target', 'target_names', 'images', 'DESCR'])

2D shape of digits data: (1797, 8, 8)

X shape (8x8 flattened to 64 pixels): (1797, 64)


y shape: (1797,)

vector (flattened matrix) of "feature" image:


[ 0. 0. 3. 10. 14. 3. 0. 0. 0. 8. 16. 11. 10.
13. 0. 0. 0. 7.
14. 0. 1. 15. 2. 0. 0. 2. 16. 9. 16. 16. 1. 0. 0. 0. 12.
16.
15. 15. 2. 0. 0. 0. 12. 10. 0. 8. 8. 0. 0. 0. 9.
12. 4. 7.
12. 0. 0. 0. 2. 11. 16. 16. 9. 0.]

matrix (transformed vector) of a "feature" image:


[[ 0. 0. 3. 10. 14. 3. 0. 0.]
[ 0. 8. 16. 11. 10. 13. 0. 0.]
[ 0. 7. 14. 0. 1. 15. 2. 0.]
[ 0. 2. 16. 9. 16. 16. 1. 0.]
[ 0. 0. 12. 16. 15. 15. 2. 0.]
[ 0. 0. 12. 10. 0. 8. 8. 0.]
[ 0. 0. 9. 12. 4. 7. 12. 0.]
[ 0. 0. 2. 11. 16. 16. 9. 0.]]

target: 8

original "digits" image matrix:


[[ 0. 0. 3. 10. 14. 3. 0. 0.]
[ 0. 8. 16. 11. 10. 13. 0. 0.]
[ 0. 7. 14. 0. 1. 15. 2. 0.]
[ 0. 2. 16. 9. 16. 16. 1. 0.]
[ 0. 0. 12. 16. 15. 15. 2. 0.]
[ 0. 0. 12. 10. 0. 8. 8. 0.]
[ 0. 0. 9. 12. 4. 7. 12. 0.]
[ 0. 0. 2. 11. 16. 16. 9. 0.]]
Listing 1-4 also displays Figures 1-1 and 1-2. Figure 1-1 is a reshaped flattened vector of the
500th image in the data set. Each data element in feature set X is represented as a flattened vector
of 64 pixels because Scikit-Learn cannot recognize an 8 × 8 image matrix, so we must reshape the
500th vector to an 8 × 8 image matrix to visualize. Figure 1-2 is the 500th image taken directly
from the images data set that is available when we load the data into variable digits.

Figure 1-1 Reshaped flattened vector of the 500th data element

Figure 1-2 Original image matrix of the 500th data element

The code begins by importing numpy, load_digits, and matplotlib packages. The main block
places load_digits into the digits variable and displays its keys: data, target, target_names, images,
and DESCR. It continues by displaying the two-dimensional (2D) shape of images contained in
images. Data in images are represented by 1797 8 × 8 matrices. Next, feature data (represented as
vectors) are placed in X and target data in y.
A feature vector is one that contains information about an object’s important characteristics.
Data in data are represented by 1797 64-pixel feature vectors. A simple feature representation of
an image is the raw intensity value of each pixel. So, an 8 × 8 image is represented by 64 pixels.
Machine learning algorithms process feature data as vectors, so each element in data must be a
one-dimensional (1D) vector representation of its 2D image matrix.

Tip Feature data must be composed of vectors to work with machine learning algorithm.

The code continues by displaying the feature vector of the 500th image. Next, the 500th feature
vector is transformed from its flattened 1D vector shape into a 2D image matrix and displayed
with the NumPy reshape function. The code continues by displaying the target value y of the
500th image. Next, the 500th image matrix is displayed by referencing images.
The reason we transformed the image from its 1D flattened vector state to the 2D image
matrix is that most data sets don’t include an images object like load_data. So, to visualize and
process data with machine learning algorithms, we must be able to manually flatten images and
transform flattened images back to their original 2D matrix shape.
The code concludes by visualizing the 500th image in two ways. First, we use the flattened
vector X_i. Second, we reference images. While machine learning algorithms require feature
vectors, function imshow requires 2D image matrices to visualize.

Complex Classification Data


Now let’s work with more complex data sets. Complex data sets are those with a very high
number of features. Such a data set is referred to as one with a high-dimensional feature space.

Newsgroup Data
The first data set we characterize is fetch_20newsgroups, which consists of approximately 18000
posts on 20 topics. Data is split into train-test subsets. The split is based on messages posted
before and after a specific date.
Listing 1-5 contains the code that characterizes fetch_20newsgroups.

from sklearn.datasets import fetch_20newsgroups

if __name__ == "__main__":
br = '\n'
train = fetch_20newsgroups(subset='train')
test = fetch_20newsgroups(subset='test')
print ('data:')
print (train.target.shape, 'shape of train data')
print (test.target.shape, 'shape of test data', br)
targets = test.target_names
print (targets, br)
categories = ['rec.autos', 'rec.motorcycles', 'sci.space',
'sci.med']
train = fetch_20newsgroups(subset='train',
categories=categories)
test = fetch_20newsgroups(subset='test',
categories=categories)
print ('data subset:')
print (train.target.shape, 'shape of train data')
print (test.target.shape, 'shape of test data', br)
targets = train.target_names
print (targets)
Listing 1-5 Characterize fetch_20newsgroups
After executing code from Listing 1-5, your output should resemble the following:

data:
(11314,) shape of train data
(7532,) shape of test data

['alt.atheism', 'comp.graphics', 'comp.os.ms-windows.misc',


'comp.sys.ibm.pc.hardware', 'comp.sys.mac.hardware',
'comp.windows.x', 'misc.forsale', 'rec.autos', 'rec.motorcycles',
'rec.sport.baseball', 'rec.sport.hockey', 'sci.crypt',
'sci.electronics', 'sci.med', 'sci.space', 'soc.religion.christian',
'talk.politics.guns', 'talk.politics.mideast', 'talk.politics.misc',
'talk.religion.misc']

data subset:
(2379,) shape of train data
(1584,) shape of test data

['rec.autos', 'rec.motorcycles', 'sci.med', 'sci.space']

The code begins by importing fetch_20newsgroups. The main block begins by loading train
and test data and displaying their shapes. Training data consists of 11314 postings, while test
data consists of 7532 postings. The code continues by displaying target names and categories.
Next, train and test data are created from a subset of categories. The code concludes by displaying
shapes and target names of the subset.

MNIST Data
The next data set we characterize is MNIST. MNIST (Modified National Institute of Standards and
Technology) is a large database of handwritten digits commonly used for training and testing in
the machine learning community and other industrial image processing applications. MNIST
contains 70000 examples of handwritten digit images labeled from 0 to 9 of size 28 × 28. Each
target (or label) is stored as a digit value. The feature set is a matrix of 70000 28 × 28 images
automatically flattened to 784 pixels each. So, each of the 70000 data elements is a vector of
length 784. The target set is a vector of 70000 digit values.
Listing 1-6 contains the code that characterizes MNIST.

import numpy as np
from random import randint
import matplotlib.pyplot as plt

def find_image(data, labels, d):


for i, row in enumerate(labels):
if d == row:
target = row
X_pixels = np.array(data[i])
return (target, X_pixels)

if __name__ == "__main__":
br = '\n'
X = np.load('data/X_mnist.npy')
y = np.load('data/y_mnist.npy')
target = np.load('data/mnist_targets.npy')
print ('labels (targets):')
print (target, br)
print ('feature set shape:')
print (X.shape, br)
print ('target set shape:')
print (y.shape, br)
indx = randint(0, y.shape[0]-1)
target = y[indx]
X_pixels = np.array(X[indx])
print ('the feature image consists of', len(X_pixels),
'pixels')
X_image = X_pixels.reshape(28, 28)
plt.figure(1, figsize=(3, 3))
title = 'image @ indx ' + str(indx) + ' is digit ' \
+ str(int(target))
plt.title(title)
plt.imshow(X_image, cmap="gray")
digit = 7
target, X_pixels = find_image(X, y, digit)
X_image = X_pixels.reshape(28, 28)
plt.figure(2, figsize=(3, 3))
title = 'find first ' + str(int(target)) + ' in dataset'
plt.title(title)
plt.imshow(X_image, cmap="gray")
plt.show()
Listing 1-6 Characterize MNIST
After executing code from Listing 1-6, your output should resemble the following:

labels (targets):
[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]

feature set shape:


(70000, 784)

target set shape:


(70000,)

the feature image consists of 784 pixels

Listing 1-6 also displays Figures 1-3 and 1-4. Figure 1-3 is the reshaped image of digit 1 at
index 6969. Figure 1-4 is the first image of digit 7 in the data set.
Figure 1-3 Reshaped flattened vector of image at index 6969

Figure 1-4 Image of first digit 7 in the data set


The code begins by importing randint and other requisite packages. Function find_image
locates the first occurrence of an image. The main block loads data from NumPy files into feature
set X, target y, and target. Variable target holds target labels. It continues by displaying the shape
of X and y. Feature set X consists of 70000 784-pixel vectors, so each image consists of 28 × 28
pixels.
Target y consists of 70000 labels. Next, a random integer between 0 and 69999 is generated,
so we can display a random image from the data set. The random integer in our case is 6969. The
image at index 6969 is digit 1. The size of the image is displayed to verify that it is 784 pixels. We
then reshape vector 6969 to a 28 × 28 matrix, so we can visualize with function imshow. The code
concludes by finding the first digit 7 and displaying it.
Faces Data
The final data set characterized in this subsection is fetch_1fw_people. The fetch_1fw_people data
set is used for classifying labeled faces. It contains 1288 face images and seven targets. Each
image is represented by a 50 × 37 matrix of pixels, so the feature set has 1850 features (based on
a 50 × 37 matrix). In all, the data consists of 1288 labeled faces composed of 1850 pixels each
predicting seven targets.
Listing 1-7 contains the code that characterizes fetch_1fw_people.

import numpy as np
import matplotlib.pyplot as plt

if __name__ == "__main__":
br = '\n'
X = np.load('data/X_faces.npy')
y = np.load('data/y_faces.npy')
targets = np.load('data/faces_targets.npy')
print ('shape of feature and target data:')
print (X.shape)
print (y.shape, br)
print ('target faces:')
print (targets)
X_i = np.array(X[0]).reshape(50, 37)
image_name = targets[y[0]]
fig, ax = plt.subplots()
image = ax.imshow(X_i, cmap="bone")
plt.title(image_name)
plt.show()
Listing 1-7 Characterize fetch_1fw_people

After executing code from Listing 1-7, your output should resemble the following:

shape of feature and target data:


(1288, 1850)
(1288,)

target faces:
['Ariel Sharon' 'Colin Powell' 'Donald Rumsfeld' 'George W Bush'
'Gerhard Schroeder' 'Hugo Chavez' 'Tony Blair']

Listing 1-7 also displays Figure 1-5. Figure 1-5 is the reshaped image of the first data element
in the data set.
Figure 1-5 Reshaped image of the first data element in the data set
The code begins by importing requisite packages. The main block loads data into X, y, and
targets from NumPy files. The code continues by printing shapes of X and y. X contains 1288
1850-pixel vectors and y contains 1288 target values. Target labels are then displayed. The code
concludes by reshaping the first feature vector to a 50 × 37 image and displaying it with function
imshow.

Regression Data
We now change gears away from classification and move into regression. Regression is a machine
learning technique for predicting a numerical value based on the independent variables (or
feature set) of a data set. That is, we are measuring the impact of the feature set on a numerical
output. The first data set we characterize for regression is tips.

Tips Data
The tips data set is integrated with the seaborn library. It consists of food server tips in
restaurants and related factors including tip, price of meal, and time of day. Specifically, features
include total_bill (price of meal), tip (gratuity), sex (male or female), smoker (yes or no), day
(Thursday, Friday, Saturday, or Sunday), time (day or night), and size of the party. Features are
coded as follows: total_bill (US dollars), tip (US dollars), sex (0=male, 1=female), smoker (0=no,
1=yes), day (3=Thur, 4=Fri, 5= Sat, 6=Sun). Tips data is represented by 244 elements with six
features predicting one target. The target being tips received from customers.
Listing 1-8 characterizes tips data.

import numpy as np, pandas as pd, seaborn as sns

if __name__ == "__main__":
br = '\n'
sns.set(color_codes=True)
tips = sns.load_dataset('tips')
print (tips.head(), br)
X = tips.drop(['tip'], axis=1).values
y = tips['tip'].values
print (X.shape, y.shape)
Listing 1-8 Characterize the tips data set
After executing code from Listing 1-8, your output should resemble the following:

total_bill tip sex smoker day time size


0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

(244, 6) (244,)

The code begins by loading tips as a Pandas DataFrame, displaying the first five records,
converting data to NumPy, and displaying the feature set and target shapes. Seaborn data is
automatically loaded as a Pandas DataFrame. We couldn’t get feature importance because
RandomForestClassifier expects numeric data. It takes a great deal of data wrangling to get the
data set into this form. We will transform categorical data to numeric in later chapters.

Red and White Wine


The next two data sets we characterize are redwine.csv and whitewine.csv. Data sets redwine.csv
and whitewine.csv relate to red and white wine quality, respectively. Both wines are composed of
variants of the Portuguese Vinho Verde wine.
The feature set consists of eleven attributes. The input attributes are based on objective tests
like pH (acidity or basicity of a substance) and alcohol (percent by volume). Output quality is
based on sensory data reported as the median of at least three wine expert evaluations. Each
expert graded wine quality on a scale from 0 (very bad) to 10 (very excellent). The red wine data
set has 1599 instances while the white wine data set has 4898.
Listing 1-9 characterizes redwine.csv.

import pandas as pd
from sklearn.ensemble import RandomForestRegressor

if __name__ == "__main__":
br = '\n'
f = 'data/redwine.csv'
red_wine = pd.read_csv(f)
X = red_wine.drop(['quality'], axis=1)
y = red_wine['quality']
print (X.shape)
print (y.shape, br)
features = list(X)
rfr = RandomForestRegressor(random_state=0,
n_estimators=100)
rfr_name = rfr.__class__.__name__
rfr.fit(X, y)
feature_importances = rfr.feature_importances_
importance = sorted(zip(feature_importances, features),
reverse=True)
n = 3
print (n, 'most important features' + ' (' + rfr_name + '):')
[print (row) for i, row in enumerate(importance) if i < n]
for row in importance:
print (row)
print ()
print (red_wine[['alcohol', 'sulphates', 'volatile acidity',
'total sulfur dioxide', 'quality']]. head())
Listing 1-9 Characterize redwine
After executing code from Listing 1-9, your output should resemble the following:

(1599, 11)
(1599,)

3 most important features (RandomForestRegressor):


(0.27432500255956216, 'alcohol')
(0.13700073893077233, 'sulphates')
(0.13053941311188708, 'volatile acidity')
(0.27432500255956216, 'alcohol')
(0.13700073893077233, 'sulphates')
(0.13053941311188708, 'volatile acidity')
(0.08068199773601588, 'total sulfur dioxide')
(0.06294612644261727, 'chlorides')
(0.057730976351602854, 'pH')
(0.055499749756166, 'residual sugar')
(0.05198192402458334, 'density')
(0.05114079873500658, 'fixed acidity')
(0.049730883807319035, 'free sulfur dioxide')
(0.04842238854446754, 'citric acid')

alcohol sulphates volatile acidity total sulfur dioxide quality


0 9.4 0.56 0.70 34.0 5.0
1 9.8 0.68 0.88 67.0 5.0
2 9.8 0.65 0.76 54.0 5.0
3 9.8 0.58 0.28 60.0 6.0
4 9.4 0.56 0.70 34.0 5.0

The code example begins by loading pandas and RandomForestRegressor packages. The main
block loads redwine.csv into a Pandas DataFrame. It then displays feature and target shapes. The
code concludes by training pandas data with RandomForestRegressor, displaying the three most
important features, and displaying the first five records from the data set.
RandomForestRegressor is also an ensemble algorithm, but it is used when the target is numeric
or continuous.
Tip Always hard-code random_state (e.g., random_state=0) for algorithms that use this
parameter to stabilize results.

The white wine example follows the exact same logic, but output differs in terms of data set size
and feature importance.
Listing 1-10 characterizes whitewine.csv.

import numpy as np, pandas as pd


from sklearn.ensemble import RandomForestRegressor

if __name__ == "__main__":
br = '\n'
f = 'data/whitewine.csv'
white_wine = pd.read_csv(f)
X = white_wine.drop(['quality'], axis=1)
y = white_wine['quality']
print (X.shape)
print (y.shape, br)
features = list(X)
rfr = RandomForestRegressor(random_state=0,
n_estimators=100)
rfr_name = rfr.__class__.__name__
rfr.fit(X, y)
feature_importances = rfr.feature_importances_
importance = sorted(zip(feature_importances, features),
reverse=True)
n = 3
print (n, 'most important features' + ' (' + rfr_name + '):')
[print (row) for i, row in enumerate(importance) if i < n]
print ()
print (white_wine[['alcohol', 'sulphates',
'volatile acidity',
'total sulfur dioxide',
'quality']]. head())
Listing 1-10 Characterize whitewine

After executing code from Listing 1-10, your output should resemble the following:

(4898, 11)
(4898,)

3 most important features (RandomForestRegressor):


(0.24186185906056268, 'alcohol')
(0.1251626059551235, 'volatile acidity')
(0.11524332271725685, 'free sulfur dioxide')

alcohol sulphates volatile acidity total sulfur dioxide quality


0 8.8 0.45 0.27 170.0 6.0
1 9.5 0.49 0.30 132.0 6.0
2 10.1 0.44 0.28 97.0 6.0
Another Random Scribd Document
with Unrelated Content
Besides Kief, Izyaslav was prince also in Novgorod, hence the road
from the Baltic to the Greeks was at his command.

Sviatoslav, the second son, received Chernigoff with Ryazan, Murom,


and Tmutarakan, beyond the Sea of Azoff. Vsevolod, the third son,
received Pereyaslavl, Suzdal and Bailo-Ozero; the fourth son,
Vyacheslav, got Smolensk, and the fifth, Igor, Volynia with its capital,
Vladimir. Rostislav, son of Vladimir, Yaroslav’s eldest son, who died
before his father, received from his uncles Rostoff, situated in the
middle of Vsevolod’s territory.

In this division of Russia the best principality, Kief, went to the eldest
son; the second in value, Chernigoff, to the second son, and so on.
The idea was to give each prince a place whose income
corresponded to his rank in the scale of seniority. Kief, besides its
superior income, carried with it the sovereignty of Russia.

Let us follow the working of this system. In 1057, three years after
Yaroslav’s death, died the fourth brother, Vyacheslav of Smolensk,
leaving one son. Igor of Volynia was transferred to Smolensk by his
brothers, and Rostislav, the nephew, was [25]moved from Rostoff to
Volynia. In 1060 Igor died in Smolensk, leaving sons also. The
remaining three brothers gave Smolensk neither to Igor’s sons, nor
to Rostislav, to whom, by the established order, it would belong.

Rostislav, enraged at his uncles, found daring spirits in Novgorod to


help him, among others Vyshata, son of Ostromir, the posadnik. With
these men he set out for Tmutarakan to find warriors and win by the
sword that which, as he thought, belonged to him.

In 1058 the four surviving brothers freed their uncle Sudislav from
prison, where Yaroslav, his brother, had kept him for eighteen years.
They took from him an oath to act in no way against them. Old and
childless, he entered a monastery, and died five years later.
Rostislav now took Tmutarakan from Glaib, son of Sviatoslav.
Sviatoslav hurried to help his son, and, as Rostislav did not resist his
uncle, Glaib was put back into power very promptly. No sooner was
Sviatoslav at home, however, than Glaib was driven out a second
time by Rostislav, who now settled down firmly and with a purpose.
He began at once to extend his dominion along the Caucasus, and
was rapidly gaining power to use against his uncles, when the
Greeks of the Chersonese poisoned him, and Glaib took his old place
again unhindered.

The three sons of Yaroslav were rid now of their nephew, but they
had a cousin who began to give them much trouble. This cousin was
Vseslav of Polotsk, grandson of Izyaslav, the eldest brother of
Yaroslav the Lawgiver. This Vseslav was known to be desperate in
battle, and swift beyond any man in marching. People believed him
born through enchantment, they thought him a real devil’s son, who
could turn to a gray wolf and race in one night from the Caucasus to
Novgorod. This so called “wizard,” excluded from the sovereign
circle, now began war in defense of rights which to him, the great-
grandson of Vladimir the Apostle, might indeed seem well founded.

In 1065 the wizard attacked Pskoff, meeting with no success, but the
following year he entered Novgorod, captured many people, took
down the great bell of Sophia, seized church ornaments and hurried
away. “Immense was the misery of that day,” states the chronicler.
Izyaslav and his brothers pursued Vseslav during terrible cold, for
the time was midwinter. On the road [26]they halted at Minsk. The
people had shut themselves up in the stronghold; so they stormed
the stronghold and captured it, cutting down all defenders, sparing
only women and children as captives.

They followed Vseslav till early in March, when they overtook him,
and notwithstanding a blinding snow-storm, there was a terrible
battle. Many fell on both sides. Vseslav was defeated, but he
escaped, as he always did, because of his swiftness and “magic.”

The following summer, Izyaslav invited the “evil wizard” to a council


of peace and kissed the cross not to harm him. Vseslav, with his two
sons, passed over the Dnieper, but when he entered Izyaslav’s tent
he was seized, though a wizard, and imprisoned; his sons were
imprisoned also.

The Prince of Kief and his brothers had rest now from relatives. But
some great calamity was coming, every one felt it; there were
portents on all sides. A bloody star appeared in the sky and
remained a whole month there; the sun was as pale as the moon; a
deformed fish had been caught, enormous and dreadful to look at.

While all men were convinced that some terror was approaching,
and were waiting in fear to see what it might be, the Polovtsi, a new
scourge, appeared. They had conquered the Petchenegs and were
now ready to harass Russia. Kazars, Torks and Petchenegs had
preceded them in this office, but the Polovtsi were Russia’s direst
foes thus far.

In 1055 the Polovtsi had crossed the boundary of Pereyaslavl, but


made peace and then vanished. In 1059 Vsevolod attacked a certain
Tork force, which he crushed. In 1060 a “countless host” was led
against those Tork opponents, who, informed of the movement,
hurried off to the steppe, but were followed. The princes killed many
and seized numbers more of them. The captives were settled in
towns to do service. Those Torks who succeeded in escaping died in
the steppe from frost, hunger and hardship. The Torks were now
finished, as were also the Petchenegs, but the Polovtsi succeeded
both, as attackers of Russia.
In 1061 these people appeared in large numbers. Vsevolod met
them immediately, but he was vanquished. They took what they
pleased and rushed off to the steppe again. In 1068 a still greater
host came. The three Russian princes met this host, and [27]fought
bravely, but were badly defeated and fled, Izyaslav with his brother
Vsevolod to Kief; and Sviatoslav to Chernigoff.

All men in Kief were enraged at Izyaslav. Some demanded arms, and
others a prince who would lead them successfully against the
Polovtsi. They rushed to the prison, freed Vseslav the wizard, and
made him Grand Prince immediately. Izyaslav, to save his life,
hastened westward to Poland. The Polovtsi advanced to Chernigoff,
where Sviatoslav met the plundering host and crushed it.

Seven months after his flight, Izyaslav appeared before Kief with a
numerous army commanded by Boleslav the Bold, King of Poland.
Vseslav went forth to meet him, and it is told of him that, since he
could hope for no favor from Vsevolod or Sviatoslav against Izyaslav,
their brother, the wizard became a gray wolf in the night-time and
vanished. In fact he fled. The army, deserted by its leader, returned
to Kief and sent the following message to Sviatoslav and Vsevolod:
“Unless ye save Kief from the Poles, we will burn it and go to the
land of the Greeks.” “We will warn our brother,” replied Sviatoslav,
“we will not permit him to enter the city with large forces.”

Izyaslav, warned by his brothers, came with only a part of the army,
was received and took his place as of old in the capital. As soon as
he left the Kief army, Vseslav hurried off to Polotsk and took
possession of that city.

Once well reinstated in Kief, Izyaslav attacked Vseslav, expelled him


from Polotsk, and placed there Mystislav, his own son. When that
son died he sent another one, Sviatopolk. Vseslav, meanwhile, went
to the Chuds (Fins), assembled a large force among them, and
attacked Novgorod, but he was again unsuccessful. Fresh warriors,
however, flocked to the wizard, who drove Sviatopolk from Polotsk,
which he held now successfully, and with firmness.

Izyaslav, having failed to subdue the wizard, decided to act alone,


and negotiate with him. He asked no aid from his brothers; he could
not well do so, for Sviatoslav the Strong was unfriendly, was in
reality plotting against Izyaslav, working to make himself master of
Kief at the earliest moment. Dissatisfied Kief men, and victims of
Izyaslav’s anger, found refuge with Sviatoslav, who turned now to
Vsevolod, his brother, and said: “Izyaslav [28]is plotting with the
wizard against us. Unless we expel him from Kief at once, he will
drive us both from our places.” The two brothers took action and
Izyaslav was forced to leave Kief for the second time.

Sviatoslav became Grand Prince and gave Chernigoff to Vsevolod.


Izyaslav now went to Poland. He gave immense presents to Boleslav
the Bold and to magnates, who did naught to assist him, but in the
end told him that he would better go elsewhere. He journeyed then
to Mainz and asked aid of Henry IV, the same Emperor who went to
Canossa. He gave presents to Henry and begged help against
Sviatoslav and Vsevolod. Henry, pleased by this recognition of his
power by a Grand Prince of Russia, sent an embassy straightway to
Kief to demand reinstatement for Izyaslav.

The Polish king and Henry were enemies at this time, hence
Sviatoslav made a treaty at once with the king, and sent Oleg, his
own son, with Monomach, son of Vsevolod, to assist him. Henry’s
efforts were vain, so Izyaslav’s son visited Rome to beg aid of
Gregory, the seventh of that name, the strong Pope who forced
Henry IV to stand thinly clad in the cold at Canossa.

The Russian prince declared that his father was ready to recognize
papal supremacy, if Gregory would only restore Kief to him. The
Pope wrote at once to the Polish king, touching the gifts which he
had taken from Izyaslav before sending him out of the country.

At this juncture Henry’s ally, the Bohemian king, Vratislav, heard that
two Russian princes were coming with warriors to attack him. He
asked peace of Boleslav, and obtained it for one thousand grievens
in silver. Boleslav then directed Oleg and Monomach to return, as
peace had been concluded. They replied that they could not go back
without shame, unless they won honor. Hence they advanced to get
honor. During four months they “went through” Vratislav’s land—to
“go through” means to ravage. Vratislav then gave them a thousand
grievens in silver for peace. They made peace, and returned home
with the money—and with honor.

The Polish king, angered by Oleg and Monomach, and roused by


Pope Gregory, promised to help Izyaslav, and began an advance on
Kief. Meanwhile Sviatoslav died, and Vsevolod set out with [29]forces
to meet Boleslav, but upon reaching Volynia he made peace, yielding
in favor of Izyaslav, who became Grand Prince for the third time, and
Vsevolod returned to Chernigoff. There was trouble on all sides,
however.

In 1076, during winter, Monomach hastened to Novgorod to help


Glaib against Vseslav the wizard, who was raiding and would give no
rest at any time unless that which he claimed was assured him.
Some months later Monomach was joined by his father, Vsevolod,
and they marched against Vseslav, taking with them Polovtsi
warriors, employed now for the first time in conflicts between
princes. They made an attack, but could not crush Vseslav; he was
too swift in his movements. They could lay waste to the country, but
could not conquer the wizard, or stop him. They could only watch
and then ward off the blows which he struck at one point or another.
But from the east still greater troubles were approaching. Vladimir,
Sviatoslav, Vyacheslav and Igor, four sons of Yaroslav, were now
dead, all leaving sons to whom their uncles would give no land. After
Sviatoslav’s death in 1076, and when Vsevolod had gone to meet
Izyaslav and yield Kief to him, Boris, a son of Vyacheslav, seized the
throne of Chernigoff, but retained it only eight days. Then he sped
away to Tmutarakan, where Roman, son of Sviatoslav, was ruler.
There were five of those sons of Sviatoslav, who held good lands
while their father was Grand Prince, but after his death they were
driven from the lands by Izyaslav, their uncle. Glaib was forced to
leave Novgorod and lost his life in the north among Fins. Oleg,
driven from Volynia, turned first to Vsevolod, his uncle, but when he
could get no assistance from him he went to Tmutarakan, in search
of men to aid him. Meanwhile, Izyaslav and Vsevolod gave all
disposable lands to their own sons.

Two years later, 1078, Oleg and his cousin Boris led an army of
Polovtsi and others to Chernigoff, where they attacked Vsevolod and
defeated him. Vsevolod turned then to Izyaslav for assistance, and
the two princes, with Yaropolk and Monomach, their sons, marched
against Oleg and his cousin. Boris was killed in the front of the
battle, and a spear went through the body of Izyaslav, the Grand
Prince. Though these two princes fell, the battle continued till Oleg’s
forces were broken and he was swept from [30]the field, escaping
with great difficulty. Thus one son and one grandson of Yaroslav fell
in this desperate struggle between uncles and nephews (October,
1078).

Now Vsevolod, the last son of Yaroslav the Lawgiver, became Grand
Prince, and the difficulties before him were enormous.

As already stated, Yaroslav the Lawgiver had six sons: Vladimir,


Izyaslav, Sviatoslav, Vyacheslav, Igor and Vsevolod. Vladimir, the
eldest son, had died before his father’s death, and had left one son,
Rostislav, poisoned afterward in Tmutarakan by the Greeks of
Chersonese. Rostislav had three sons: Rurik, Volodar and Vassilko.
Rurik died early, Volodar and Vassilko lived long and caused much
trouble.

Vyacheslav, the fourth son of the Lawgiver, died Prince of Smolensk,


leaving one son, Boris, who fell, as we have seen, on the battle-field
with Izyaslav, his uncle. Igor, the fifth son, had died young, leaving
one son, David. Vsevolod, the sixth son, was now Prince of Russia.
Of Sviatoslav’s sons, four were living, Oleg, Roman, David and
Yaroslav. Seven descendants of Yaroslav the Lawgiver were
excluded, besides Vseslav, the wizard of Polotsk, who demanded
equal rights with the sons of Yaroslav, and would not give peace till
he got them.

On assuming power in Kief, Vsevolod gave Chernigoff to his son


Monomach, and to Yaropolk, son of Izyaslav, he gave Volynia. He
gave nothing to any of the dissatisfied princes. This conduct roused
Oleg, whose father had been Grand Prince in Kief with the aid and
consent of Vsevolod, given either by constraint or freely. So in 1079
Oleg sent his brother, Roman, with an army of Polovtsi to war
against Vsevolod, who met him, but made peace with the Polovtsi by
giving value in hand without fighting. As Roman had nothing to give
them, save a promise of plunder for which they must fight, the
Polovtsi dropped Roman’s cause and killed him. Then they went
home, seized Oleg and gave him to the Greeks of the Chersonese,
who sent him in fetters to Rhodes in the Archipelago. Ratibor was
sent by Vsevolod as posadnik to Tmutarakan, and he ruled there till
David, son of Igor, with Vassilko and Volodar, sons of Rostislav, came
the following year, drove him out of Tmutarakan and governed in
their own way. Oleg, who had fled from his exile, appeared a year
later, confined [31]the three princes, and put those Polovtsi to death
who slew Roman. Later on he freed the princes, who had now to
seek for lands in other places.

In 1084 Rostislav’s son’s, Vassilko and Volodar, disappeared from


Volynia, where they had been living with Yaropolk. Disappeared, but
returned with an army and drove away Yaropolk. Monomach now, at
command of his father, marched against those two princes, expelled
them and reinstated Yaropolk after much fighting and effort.

David, son of Igor, used means of another sort. He remained for a


time in Tmutarakan, then he went with warriors to the mouth of the
Dnieper, stopped all merchants trading with Tsargrad and took their
wares from them. This put an end to commerce with the Byzantine
Empire. Vsevolod’s treasury suffered immediately and he was
obliged to come to terms. He gave David a part of Volynia, and
commerce with Tsargrad was free again.

Yaropolk, deeply offended by this gift to David, which decreased his


own lands, began to enlist men and make ready for warfare.
Vsevolod, upon learning of this, sent his son, Vladimir Monomach, to
attack Yaropolk, but that prince had fled to Poland, leaving wife,
mother and treasures in Lutsk. An attack was made upon Lutsk,
which surrendered to Monomach, who captured Yaropolk’s family
with attendants and treasures and established David, son of Igor, as
ruler of all Volynia.

At this time Galitch was won, as it seems, by the sons of Rostislav.


They seized it from the Polish king, who was friendly with Yaropolk.

The following year, 1086, Yaropolk came back from Poland, made
peace with Monomach and was again seated in Volynia. Still his
lands could not have been of great use to him, since soon after his
coming he set out for Zvenigorod. He was slain on the road by a
man named Neradets, who escaped and took refuge with Rurik, son
of Rostislav, in Galitch.

That same year Vsevolod moved against Volodar and Vassilko, but in
the end made peace with them. After that there was rest for a time
in Volynia. But there was sharp trouble with Vseslav the wizard, who
at Vsevolod’s accession had “scorched” Smolensk, that is burned it,
all save the stronghold. Monomach [32]hunted him swiftly with men
doubly mounted, 6 but the wizard escaped. A second hunt followed,
by men from Chernigoff and Polovtsi allies. On the way they took
Minsk by surprise, and left not a man or beast in the city. [33]

1 The tomb of Askold is still shown near Kief. ↑


2 The city of the Tsar, or Cæsar, that is Constantinople, so called for the first
Christian Emperor, Constantine. ↑
3 Olga was the mother of Sviatoslav and thus the grandmother of Vladimir. ↑
4 Ruins of this city still exist near Sevastopol. Among the ruins is a church said to
be the one in which Vladimir received baptism. ↑
5 The present Galicia. ↑
6 Men riding one horse and leading another. ↑
[Contents]
CHAPTER II
VLADIMIR MONOMACH
In 1093 Vsevolod died at the age of sixty-four. His successor was
Sviatopolk, son of Izyaslav, a weak and worthless man. Then came
trouble and turmoil. “Those were days,” an old song says, “when
strife was sown, when it grew as grain in the field grows, when
men’s lives were shortened by princes’ struggles, when the cry of
the earth-tiller was heard only rarely, but often the scream of the
crows wrangling over corpses.” Monomach, the bravest and ablest of
all the descendants of Yaroslav, might have taken the Kief throne
had he wished, since the Kief people begged him to do so, but he
feared civil war and refused, saying: “Sviatopolk’s father was older
than my father; he reigned first in Kief.”

Sviatopolk, greedy and cruel, showed his character quickly. Envoys


from the Polovtsi came to sell peace to him. He cast them into
prison. When the Polovtsi heard of this insult they made war with
the utmost vigor.

Sviatopolk then freed the envoys and asked for peace, but could not
get it. He began at once to prepare for war on a small scale, but at
last took advice and asked aid of Monomach, who came, bringing
with him his brother. The three princes with their combined forces
attacked the Polovtsi, though Monomach urged peace, since the
enemy outnumbered them notably. The Russians were beaten in a
savage encounter and Rostislav, Monomach’s brother, was drowned
while crossing a river; Monomach himself had a narrow escape when
struggling to save him. Elated with triumph, the Polovtsi hastened
toward Kief, ravaging all before them. Sviatopolk, who had taken
refuge in the capital, summoned fresh warriors and went out to
meet the enemy a second time, but was again defeated and fled
back to Kief with but two attendants. [34]

As Sviatopolk now wished greatly for peace, he gave what the


Polovtsi asked, and took the Khan’s daughter in marriage.

Oleg, son of Sviatoslav of Chernigoff, one of the most resolute and


active men of the eleventh century, came also with peace to sell,
leading in a new army of Polovtsi. The crushing defeats which his
cousins had suffered prepared the way for him. He laid siege to
Chernigoff, harried the surrounding country and burned churches
and villages. For eight days his Polovtsi worked at the stronghold,
then Monomach sent a message to Oleg declaring that to stop
bloodshed and ruin he would march from the city. Peace was made
on that basis, and Oleg became master of Chernigoff.

Pereyaslavl was now Monomach’s capital, and continued to be so


during a time of sore trial and waiting. Pereyaslavl was the place
which the Polovtsi struck first of all, when marching against Russia.
Monomach lived three years in this exposed capital, where he
suffered through lack of means and from ceaseless attacks of the
Polovtsi. In 1095 two Khans, Itlar and Kitan, came to Pereyaslavl to
sell peace, that is to take treasure for a promise of peace, and then
break the promise.

Itlar went with his men to the stronghold to pass the night there and
was lodged at the house of Ratibor, a distinguished boyar.

Kitan remained between the outer wall and the second one, and
Monomach gave Sviatoslav, his son, to Kitan as hostage for the
safety of Itlar.

A man by the name of Slavata, who had come that day on some
mission from Sviatopolk in Kief, persuaded Ratibor to get consent
from Monomach to kill those Polovtsi. “How could I permit such a
deed?” demanded Monomach; “I have given my oath to Itlar:” “The
Polovtsi give oaths to thee, and then slay and ruin us on all sides.
That they will do this time also.” Monomach yielded after much
persuasion, and that night men were sent out who stole away
Sviatoslav and then killed Kitan with his attendants. Itlar, at Ratibor’s
house, knew nothing of what had happened. Next morning Ratibor’s
men climbed to the top of the house in which Itlar was lodging,
opened the roof and killed the Polovtsi warriors with arrows.
Sviatopolk and Monomach moved at once to the steppe against the
Polovtsi and sent to Oleg for aid in the struggle. Oleg went, but held
aloof through [35]suspicion. The two princes were successful. The
Polovtsi, taken unawares, were badly defeated. The princes seized
men, cattle, horses and camels, and returned home with rich booty.

Oleg’s conduct had angered Sviatopolk and Monomach seriously.


“Thou art unwilling to join us against the vile enemy,” said they. “In
thy house Itlar’s son is now living; give him to us, or else kill him.”
Oleg would not yield to his cousins. Soon after they sent this
message: “Come to Kief and take counsel, so that we may defend
Russia together.” “I will not let priests and common men judge me,”
replied Oleg. This answer enraged Kief people, and Sviatopolk and
Monomach declared war against Oleg without another question.
“Thou wilt not help us to crush pagans,” said they, “or meet us in
council. Thou art plotting to strengthen the enemy. Let God judge
between us.” 1

The two princes now marched on Chernigoff. Oleg fled thence to


Starodub and shut himself in there. The princes laid siege to the
place, and during thirty-three days they made vigorous onsets, but
the defense was most resolute. At last the besieged were exhausted,
and Oleg was obliged to beg for peace. “Go to David, thy brother,”
replied the princes, “and come with him to Kief. Kief is the mother
city. In Kief ruled our ancestors. Let us meet there and settle all
questions.” Oleg kissed the cross in assent and set out for Smolensk
to find David, but upon arriving at that city the people would not
allow him to enter, so he turned and went back toward Ryazan.

Since Oleg and David did not come to Kief to make peace and take
counsel, the two princes marched on Smolensk. David now made
peace with them, on what terms is unknown to us, while Oleg, with
his own men and some warriors sent him by David in secret,
advanced against Murom to expel Izyaslav, son of Monomach.
Izyaslav, having a numerous force, went out to meet Oleg. “Go to
Rostoff, which belonged to thy father,” said Izyaslav, “but leave my
father’s portion.” “I wish to be here,” replied Oleg. Izyaslav now gave
battle. A fierce struggle followed, and Izyaslav fell in the fight before
the walls of Murom. The town then received Oleg, who hurried on
straightway to Suzdal, which also surrendered. Of the citizens some
he held captive while others were sent to various places in his own
land, [36]but he seized all of their property. He appeared next in front
of Rostoff, which surrendered at once, and he appointed men to
collect taxes there.

Oleg held now all lands connected with Murom. At this juncture
there came to him an envoy from Mystislav, prince in Novgorod, with
this message: “Leave Suzdal and Murom. Take not another man’s
province. I will make peace between thee and my father, even
though thou hast slain Izyaslav, my brother.”

Oleg would not listen. After such a victory he had no desire for
peace. He planned to take Novgorod, he had even sent forward his
brother, Yaroslav, and was going to assist him. Mystislav sent men,
who seized Oleg’s tax-gatherers. In view of this, Yaroslav warned
Oleg to guard himself carefully, that forces were advancing from
Novgorod. Oleg turned back to Rostoff, but Mystislav followed him.
He then left Rostoff for Suzdal; his enemy hurried straight after him.
Oleg burned Suzdal and fled to Murom. Mystislav reached Suzdal
and halted. From Suzdal he sent an envoy again to make peace, if
possible.

Oleg, doubtful of victory through force, now sought it through


strategy. He sent back words of seeming friendliness, and was
watchful.

Mystislav, thinking peace near, quartered most of his warriors at


some distance in villages. While eating at midday, news was brought
in that the enemy was advancing rapidly. Oleg had thought that a
sudden feint would put his nephew to flight, but Mystislav held his
ground firmly. He quickly called together all his men, and when Oleg
was drawing near Suzdal, an army was ready for action in front of
him. For four days were the two princes facing each other; neither
one saw his way to begin the hard trial. Meanwhile Monomach was
hurrying on reinforcements to Mystislav. These were Polovtsi
commanded by another son, Vyacheslav. On the fifth day Oleg
moved against Suzdal, and Mystislav, having placed the Polovtsi in
ambush to attack at the critical moment, marched out to meet him.

The battle began, and Mystislav with his Novgorod men was bearing
down heavily on the enemy, when the Polovtsi, with Monomach’s
banner above them, suddenly rushed at the flank of Oleg’s army.
Panic fell on the warriors at sight of that banner; [37]they thought
that Monomach was attacking in person, and they fled from the field
in disorder.

Oleg escaped to Murom, where he left his brother, Yaroslav, and


then marched with all speed to Ryazan. Mystislav hastened to
Murom, made peace with the people and freed the men seized by
Oleg some time earlier, then he pursued Oleg farther. Oleg, learning
that Mystislav was approaching, left Ryazan. Mystislav came to terms
with the people of Ryazan, as he had with those of Murom. He now
sent a second letter to Oleg, urging him to make peace with his
cousins. Oleg made a favorable promise, and Mystislav wrote to
Monomach on behalf of Oleg, who was his godfather. Because of this
letter Monomach, anxious to put an end to the dispute between the
princes, sent a mild, but firm message to Oleg. The result was a
meeting of the princes in 1097 at Lubetch, a place east of the
Dnieper on the land of Chernigoff.

Seated on the same carpet, they agreed that in order to put an end
to civil war, each prince, or group of princes, should receive the land
held by his, or their father. Hence Sviatopolk received Kief with
Turoff; to Vladimir went all that Vsevolod, his father, had held,—
Smolensk with Rostoff and its settlements. Novgorod fell to
Mystislav, who had conquered Oleg; Sviatoslav’s sons, Oleg, David,
and Yaroslav, received the lands of Chernigoff. There now remained
the izgoi, or orphans, the excluded princes: David, son of Igor, with
Vassilko and Volodar, sons of Rostislav. To David was given Volynia,
or all that was left of it after the paring of land from that province.
Peremysl fell to Volodar, and Terebovl to Vassilko.

When everything was thus amicably settled, the princes kissed the
cross, and declared that if any one of them should raise hands on
another all the rest would oppose that man, and the holy cross be
against him. After that they kissed one another and parted.

This meeting at Lubetch fixed succession to lands east of the


Dnieper by giving what the father had held to the sons of Sviatoslav.
But west of that river were, as we shall find, fruitful causes of
trouble. In Polotsk was Vseslav, the restless wizard, unrecognized as
yet, and dissatisfied. In Volynia was David, son of Igor; next to him
were the sons of Rostislav, who had some land which David looked
on as a part of Volynia. Vassilko, Prince of Terebovl, [38]was
renowned for his activity and enterprise. He had led Polovtsi into
Poland and was planning new exploits. Warriors from various tribes
were coming even then to serve under him. David, perfidious and
grasping, but no warrior, was in ceaseless dread of Vassilko. Before
the council at Lubetch was ended, Turijak, Vassili, and Lazar, three
men of David’s escort, had persuaded their master that Monomach
and Vassilko had formed a plan and were ready for action against
him. Vassilko, they said, was to take Volynia, David’s land, while
Monomach would seize Kief from Sviatopolk. This tale threatened
David with loss of rule, and death or exile. He knew well what
wandering and seeking for power meant, so on the way back to Kief
he explained this tale to Sviatopolk, and added: “Unless we seize
Vassilko at once, thou wilt not stay in Kief, nor I in Volynia.” Since
Sviatopolk was doubtful as to the truth of this statement, David
developed his reasons for making it: “He killed thy brother Yaropolk,
and is now plotting against both of us; he is at one with Monomach.”

Sviatopolk was willing to have the deed done, but wished to make
David entirely responsible for it. “If thou art speaking the truth,” said
he, “God Himself will be witness on thy side. If untruth, He will
judge thee.”

When Vassilko reached Kief he was invited by Sviatopolk to the feast


of his name’s day, but he excused himself, saying that his men had
gone ahead and he must overtake them. On hearing this, David sent
word to Vassilko as follows: “Offend not thy elder brother, remain for
the feast.” Vassilko refused even this request. David turned then to
Sviatopolk, with these words: “Here in thy capital he dares to
disregard thee. What will the man do in his own land? He will take
Pinsk and other towns, thou wilt think of my words then. Send men,
seize Vassilko, and give him to me; I will care for him.”
Sviatopolk yielded and sent an invitation to Vassilko to visit him at
his home: “If thou wilt not stay for my festival,” said he, “visit me
this morning, and sit awhile with David and me.”

Vassilko consented and was on the way when a servant who met
him gave warning: “Go not, O prince,” said he; “they will seize thee.”
“God’s will be done,” replied Vassilko and making the sign of the
cross, he rode on. Upon his arrival Sviatopolk came to the door of
his palace, and greeted him with great [39]cordiality and kindness.
Then David appeared, and Vassilko was invited to breakfast with his
two kinsmen. Presently Sviatopolk withdrew, as if to give orders, and
upon some pretext David followed him. The next moment men
rushed into the room, seized Vassilko and put him in double fetters.

Sviatopolk now sought the advice of Kief boyars and the clergy. The
boyars answered evasively; the clergy took the side of Vassilko, and
begged the Kief prince to free him. Sviatopolk seemed to waver.
“This is all David’s work,” declared he, “I have no part in it.” David
interfered at once, saying: “If thou set him free, we shall not remain
princes.” “He is in thy care then,” replied Sviatopolk, and Vassilko
was given up to David, who straightway had his eyes put out.

Monomach wept when he heard of the tragedy. “Never before,” cried


he, “has such a deed as this been done in the midst of us.” And at
once he sent to Sviatoslav’s sons, Oleg and David, for aid in
chastising the criminal. They came promptly, with forces to help him.
The three princes then sent this query to Sviatopolk: “Why commit
such iniquity; why cast a knife between princes? Why put thy
brother’s eyes out? If he had offended, why not accuse him before
us, we would have punished him if guilty. But tell us now what his
fault was, what did he do to thee?”

“David told me,” replied Sviatopolk, “that Vassilko slew Yaropolk, my


brother, that he was preparing to kill me, that Monomach would take
Kief and Vassilko Volynia. I had to care for my own life. Besides, it
was David, not I, who blinded Vassilko. David took him and on the
way home put his eyes out.”

“Thou canst not lay thy own sins on David. Not in his land, but in
thine, was the deed done,” retorted the envoys, and they left him.

Next day, when the three princes were marching on Sviatopolk, he


prepared to flee from his capital, but Kief men interposed and sent
his stepmother to Monomach. With her went Nikolai the
metropolitan, to beg in the name of the city not to make war upon
Sviatopolk. They presented such reasons that Monomach was
moved, and he sent this injunction: “Since David alone did this deed,
as thou sayest, do thou, Sviatopolk, move against David, and either
seize the man captive, or drive him out of his province.” Sviatopolk
declared himself ready to do this. [40]

Vassilko was meanwhile imprisoned by David, who took every town


that he could during the winter and set out the next spring before
Easter to seize all the lands that remained to his captive. He was
met on the boundary, however, by Volodar, who was ready for battle,
hence David took refuge in Bugsk. Volodar moved on that place
without waiting, and sent this question to David: “Why hast thou
done so much evil, and wilt not repent of it? See what immense
harm thou hast wrought already.”

David laid the guilt upon Sviatopolk. “Was it I who did the deed?”
asked he. “Was it done in my capital? I feared to be treated as was
thy brother. I was not free; I was at their mercy.” “God knows which
man of you is guilty,” said Volodar. “Give me my brother and I will
make peace with thee.” David was glad to be free of Vassilko, so
peace was declared, and they parted. That peace, however, was not
lasting, for David would not yield the towns which he had taken after
blinding Vassilko, hence the two brothers attacked him at Vsevolod.
But David escaped, shut himself in at Vladimir, and waited.

Vsevolod was stormed and burned down. As the people fled from
the blazing city, Vassilko commanded Volodar to kill them. Thus he
avenged his own wrongs upon innocent people.

Next the two brothers hastened to Vladimir. “We have come,”


declared they to the citizens, “not against you, but to find Turijak,
Vassili, and Lazar, those men who lied foully to David. Through
listening to them he has done dreadful evil; yield those three up to
us. If ye protect them, we must attack you.” The citizens counseled
together and declared then to David: “Yield these three men; for
thee we are ready to battle, but not for them.” “They are not here,”
replied David. He had sent those attendants to Lutsk to save them.
The people forced him to bring back Vassili and Lazar; Turijak had
fled to Kief and thus saved himself. Peace was made, and next
morning Vassili and Lazar were hanged on two gibbets, in front of
Vladimir.

Sviatopolk had promised to march against David and expel him, but
all this time he was idle; he set out only after a year, and then he
moved not directly, but to Brest on the boundary, where he made a
Polish alliance. He feared to attack single-handed and acted only
when David was beaten by Volodar and Vassilko; even then he
wished the Poles to assist him. He also made [41]an alliance with
Volodar and Vassilko, and kissed the cross to them.

David, too, went to Brest to get Polish aid, and gave fifty gold
grievens 2 to King Vladislav Herman as a present. “Help me!”
implored David. “Sviatopolk is in Brest,” said the king, “I will
reconcile thee with him.” Vladislav, however, soon discovered by
experience that the friendship of Sviatopolk brought a greater return
to him than did friendship with David. The Kief prince made richer
gifts, and to Vladislav’s son he gave his daughter in marriage. In
view of these facts, the king informed David that he had failed in
discussions with Sviatopolk. “Go home,” said he; “I will send aid if
thy cousin attacks thee.”

David went home and waited a long time. Sviatopolk laid siege to
Vladimir. David held out, hoping for Polish assistance, which came
not. At last he yielded, and the two princes made peace. David
marched out, and Sviatopolk, when he had entered Vladimir in
triumph, began to think of Volodar and Vassilko. “They are on lands
which belonged to my father,” said he, and he marched against the
two brothers, forgetting that he had kissed the cross to them
recently. He found it most difficult, however, to deal with those
princes. When he advanced to invade their lands, Volodar and
Vassilko met him promptly on the boundary. Before the battle, which
followed immediately, Vassilko held up the cross which Sviatopolk
had kissed, and cried out to him: “See what thou didst kiss to prove
thy good faith to me. Thou hast robbed me of eyesight, and now
thou art trying to kill me. Let this holy cross be between us.”

The ensuing battle was savage. Sviatopolk was forced from the field
and withdrew to Vladimir, where he put his son, Mystislav, in charge,
and sent another son, Yaroslav, to Hungary to find aid against
Volodar and Vassilko, he himself going to Kief in the meantime.

At Yaroslav’s call, the Hungarian king, Koloman, came with an army


and two bishops and laid siege at once to Peremysl, where Volodar
had fixed himself. David came back from Poland, where he had
begged aid without finding it. Their common danger at this time
brought him and his victim together, and, leaving his wife in
Volodar’s care, he set out to find Polovtsi allies. He met Bonyak, the
famous Polovtsi Khan, who returned with him, bringing [42]a strong
force of warriors. They attacked and drove out the Hungarians, and
punished them severely. Yaroslav, son of Sviatopolk, who had
brought the Hungarians to Russia, fled now to the Poles, and David,
making use of his victory with promptness, marched on Vladimir
when he was not expected, seized the suburbs and laid siege to the
fortress without delay.

Mystislav, placed in command, as we have seen, by Sviatopolk, his


father, defended the city successfully till misfortune befell him. He
was standing one day on the wall behind a wooden curtain when an
arrow flew in through a crevice and killed him. His death was
concealed from the people for three days. When they learned of it,
they said straightway: “If we surrender now, Sviatopolk will destroy
us.” So the chief men sent to Kief, saying: “Thy son is slain, we are
dying of hunger. If thou come not, the people will yield to the
enemy.”

Sviatopolk sent his voevoda, Putyata, with forces which halted at


Lutsk, where Sviatoslav, son of David of Chernigoff, had warriors. At
this juncture envoys from David, son of Rurik, who was besieging
Vladimir, had audience with Sviatoslav, who had just sworn
friendship to them. But when Putyata appeared, this same Sviatoslav
was frightened. He seized David’s envoys, and went himself with his
warriors to help Putyata, instead of helping David. These two allies
arrived before Vladimir one midday, and attacked David. The
Vladimir men, seeing this from the walls of the city, made a sally and
David was badly defeated. He fled and Putyata and his ally marched
into Vladimir, where they established one Vassili as lieutenant of
Sviatopolk. After that the allies departed for Lutsk, and Putyata went
to Kief.

Meanwhile David fled quickly toward the steppe land to find Polovtsi.
Again he met Bonyak, who returned with him, and they captured
Lutsk and Vladimir, which David now occupied. Then he sent his
nephew, Mystislav, to the mouth of the Dnieper to seize merchants,
and thus force the Grand Prince to sue for peace as he had done
formerly—Sviatopolk, by nature weak and vacillating, had shown
that he was not the man to punish David, who was stronger now
than he had ever been before.

In 1100 a new meeting of princes was arranged to assemble at


Vititchevo. At this meeting the following decision was made known
to David: “We will not let thee have Vladimir, because [43]thou hast
cast a knife wickedly between us. We do not exclude thee, or punish
thee further. Thou canst take Bugsk with Ostrog. Sviatopolk gives
thee Dubno and Chartorisk, also Dorogobuj. In addition, Monomach
gives thee two hundred grievens, Oleg and David two hundred
more.”

To Volodar the princes sent the following message: “Take thy


brother, Vassilko, and possess Peremysl. If thou wilt not keep thy
brother, let him come to us, we will support him.”

Volodar and Vassilko would not comply with this, and each remained
in the place which belonged to him. When the princes wished to
constrain the two brothers, Monomach would not consent to it; he
insisted on the Lubetch agreement.

The two meetings, the first at Lubetch, the second at Vititchevo,


ended that struggle which had raged half a century. The strong
princes became stronger, the izgoi (orphans) and their descendants
were excluded. Volodar and Vassilko were the only izgoi who
retained a province. The descendants of Vyacheslav, son of Yaroslav,
lost their places in the first generation; those of Igor, his brother, in
the second. Later on they reappear as petty princes of small places
without independent significance. With full and equal rights appear
only the descendants of the three elder sons of Yaroslav, Izyaslav,
Sviatoslav and Vsevolod. Of these, the sons of Sviatoslav saved
themselves only after a bitter and bloody struggle, thanks also to the
moderation of Monomach, and his son Mystislav.

The division of land between the descendants of these three sons of


Yaroslav the Lawgiver was unequal. Monomach, through his superior
personality and favoring fortune, received a much larger portion
than his brothers. He received Pereyaslavl, Novgorod, Smolensk and
Rostoff. Sviatopolk received Volynia, but Novgorod, connected
always so closely with Kief, did not fall to him. The sons of
Sviatoslav, Oleg and his brothers, received nothing beyond the land
which their father had held.

Sviatopolk was greatly dissatisfied that Novgorod did not remain with
his house. As he could not take it from Monomach without
compensation, he gave Volynia in return for it. But when Mystislav,
Monomach’s son, was recalled to give place to a son of Sviatopolk,
the men of Novgorod revolted, and sent envoys to Kief with this
message: “Novgorod wishes neither Sviatopolk [44]nor his
descendants. If Sviatopolk’s son has two heads, let him come to us.”
Sviatopolk had to live without Novgorod.

Monomach, now free to act against steppe tribes, urged Sviatopolk


to help him. “Let us join our forces,” said he, “and march in the
spring against these enemies.” Sviatopolk turned to his warriors for
counsel. They were unwilling to move, and answered that war
during spring months took men from their labor. “Let us meet in
some place, and consult with the warriors,” was Sviatopolk’s answer
to Monomach. They met at Dolobsk, above Kief, on the bank of the
Dnieper. “Begin, brother, thou art the elder,” said Monomach; “tell
what we are to do in our Russia.” “Begin thou, that is better,”
answered Sviatopolk. “How am I to speak,” replied Monomach, “thy
warriors will oppose, and say that I wish to ruin earth-tillers and
their labor, though I wonder why they are so tender of earth-tillers,
forgetting how Polovtsi come in the spring-time, strike down each
man in his furrow, take his wife, take his children, seize his horse,
and burn his granary.” “True,” said the warriors. “Thou art right, they
do much evil.” “I am ready to go!” exclaimed Sviatopolk. And he rose
and proclaimed the expedition. “Thou hast done a great deed, O my
brother,” said Monomach.

The two princes sent at once to the sons of Sviatoslav, saying: “Let
us march against the Polovtsi, we shall either fall in the struggle, or
survive it.” David promised aid, but Oleg would not go. His health
was too frail, he said. Four other princes joined willingly in making
war on the steppe foes of Russia.

The Polovtsi learned what was coming, and met in council. Some
were in favor of buying peace, but the younger men called loudly for
war, and their side won the mastery.

A force was sent out to reconnoitre. The princes met this force, cut
down every man in it, advanced on the main army quickly and struck
it. A fierce struggle followed. Twenty Polovtsi chiefs were killed, and
a Khan named Beldug was captured. Beldug, when brought to
Sviatopolk, offered much ransom for his life in gold, silver, cattle,
horses and camels. Sviatopolk sent him to Monomach for judgment.
“How often hast thou sworn not to war with us,” said Monomach to
the Khan, “but still thou attack. Why not teach thy sons what an
oath is? How much Christian blood hast thou shed? But now thy own
blood be on [45]thee, not on our heads.” With that, he gave a sign to
his men, and Beldug was cut to pieces.

Immense booty was taken, and the princes went home rejoicing,
and with great glory. The terrible Bonyak was alive yet, however, and
made his power felt very keenly.
In 1106 Sviatopolk sent three voevodas against Polovtsi, whom they
defeated, and from whom they recovered much booty. In 1107, near
Pereyaslavl, Bonyak seized large herds of horses. Somewhat later he
appeared with other Khans and encamped at the Sula River near
Lubni. Sviatopolk, Monomach, and Oleg, with four other princes,
discovered his camping-ground, and, stealing up to it, made an
attack with great outcry. The Polovtsi had no time to defend
themselves. Those who could seized their beasts, mounted and fled;
those who could not mount rushed off on foot, if they were able.
The princes pursued them to the river Horol, slaying all whom they
could reach with their sabres.

Despite these successes, Oleg and David in that same year held a
meeting with two Khans, whose daughters they took as wives for
two of their sons.

In 1110 an expedition undertaken by Sviatopolk, Monomach and


David came to naught, but in 1111 they set out on the second
Monday in Lent, and on Friday before Passion Week they met the
Polovtsi in large force beyond the Don River, and crushed them. It
was not till the following Monday, however, that they found the main
host of the enemy. When the two armies met, there was a roar like
thunder, as the chronicler describes it, and the battle was merciless.
Both sides were equal and balanced each other till David and
Monomach, with two regiments, rushed furiously at the enemy’s
center and pierced it. At this the Russians dashed forward with
renewed strength, broke the Polovtsi and, cutting and slashing,
pursued them to the steppes.

This was the greatest victory won up to that time over Polovtsi. The
profit of the exploit was enormous, and the fame of it extended
through Europe. It went both to Rome and to Tsargrad. Though all
the princes helped Monomach, they could not of themselves have
conceived such a feat or have accomplished it, hence to him the
chief glory was due, and was given. For him and for the whole land
and people there was great benefit in conquering the Polovtsi. For
him, because those tribes were ever ready to [46]harass and plunder,
and doubly ready to help any prince in his projects.

To landless princes, or those who had quarrels, the Polovtsi were


ready aids, but they were the terror of all who tilled land or lived by
labor. To a great chief like Monomach they were enemies nearly
always, for principally through them civil war and disorder were
possible. A prince without land or position might find among Polovtsi
at all times men ready to go with him and take their reward in
plundering the country and enslaving as many people as they could
lay hands on.

It was difficult in those days to be a Grand Prince ruling wisely and


with justice. Such a man had to get the throne of Kief first, and then
hold it; he had to satisfy, or eliminate, the unreasoning and unruly;
he had to crush or terrorize the Polovtsi; he had, by victory, a show
of power, or a daring front, to ward off his western neighbors. When
these deeds were all accomplished he might begin to work for
wealth and order. We can understand easily the desire of Monomach
to crush the Polovtsi, and his joy at having tamed them, at least for
a season.

In 1113 Sviatopolk died, and Monomach succeeded him, but he took


the highest office only after a hesitation which we may believe to
have been shown to make men express themselves with the utmost
emphasis. Sviatoslav was older than Monomach’s father, but
Sviatoslav, though he had been prince in Kief, was prince by
expelling Izyaslav unjustly, and, though Sviatoslav had ceased to live
before Izyaslav was reinstated, and therefore died in office, he might
be considered as not having been in Kief at any time; his sons in this
event could have no real claim. In every case the people would
receive no man except Monomach, and he became Grand Prince by
acclamation.

Though the sons of Sviatoslav made no demands in public, they


cherished plans in secret, as was shown somewhat later, and very
clearly. But trouble came immediately from other princes. Glaib of
Minsk, a son of Vseslav, that swift moving wizard, so well known to
us, ravaged lands in Monomach’s possessions, and when asked to
cease made sharp reproaches. Because of this, the Grand Prince, in
1116, marched against Minsk with his sons, and others. The young
princes seized various towns, and Monomach resolved to capture
Minsk at every hazard, hence [47]he fixed his camp before it, and
had a house built in haste, for headquarters. When Glaib saw this
house, he begged for peace straightway, and it was granted him.
Somewhat later he rebelled again, and in 1120 was brought to Kief,
where he died that same season.

The next scene of trouble was Volynia. Sviatopolk, the last Grand
Prince, had cherished good feeling toward Monomach, and had
caused Yaroslav, his son, to marry the daughter of Mystislav of
Novgorod, son of Monomach. Sometime later, however, Monomach
laid siege to Vladimir, Yaroslav’s capital. After fighting two months,
that prince asked for peace, and Monomach granted it on condition
that Yaroslav would come to him whenever summoned. The attack
on Yaroslav had been made because, in connection with Boleslav of
Poland, who had married his sister, he was acting in Galitch against
Volodar and Vassilko. Monomach had remonstrated without effect,
and then moved on Yaroslav, with the result we have just seen.
Before going on this expedition, the Grand Prince had recalled
Mystislav from Novgorod, and installed him in Bailgorod, so that in
case of need he might have that son near him. Yaroslav, who,
because his father had been Grand Prince, wished to succeed
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like