Advanced Data Analytics Using Python: With Architectural Patterns, Text and Image Classification, and Optimization Techniques [2nd Edition] Sayan Mukhopadhyay All Chapters Instant Download
Advanced Data Analytics Using Python: With Architectural Patterns, Text and Image Classification, and Optimization Techniques [2nd Edition] Sayan Mukhopadhyay All Chapters Instant Download
com
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmeta.com/product/advanced-analytics-with-transact-sql-
exploring-hidden-patterns-and-rules-in-your-data-1st-edition-dejan-
sarka/
ebookmeta.com
https://ebookmeta.com/product/advanced-analytics-with-transact-sql-
exploring-hidden-patterns-and-rules-in-your-data-1st-edition-dejan-
sarka-2/
ebookmeta.com
https://ebookmeta.com/product/international-business-fourth-edition-
yadong-luo/
ebookmeta.com
Services Liberalization in ASEAN Foreign Direct Investment
in Logistics 1st Edition Tham Siew Yean
https://ebookmeta.com/product/services-liberalization-in-asean-
foreign-direct-investment-in-logistics-1st-edition-tham-siew-yean/
ebookmeta.com
https://ebookmeta.com/product/entranced-guardian-academy-1-1st-
edition-jessica-sorensen/
ebookmeta.com
https://ebookmeta.com/product/chocolate-truffles-and-trouble-pacific-
cove-cozy-mystery-03-samantha-silver-et-el/
ebookmeta.com
https://ebookmeta.com/product/eloquent-javascript-3rd-edition-a-
modern-introduction-to-programming-marijn-haverbeke/
ebookmeta.com
Advanced Data
Analytics Using
Python
With Architectural Patterns,
Text and Image Classification,
and Optimization Techniques
Second Edition
Sayan Mukhopadhyay
Pratip Samanta
Advanced Data Analytics Using Python: With Architectural Patterns, Text
and Image Classification, and Optimization Techniques
v
Table of Contents
Normal Forms�����������������������������������������������������������������������������������������������������31
First Normal Form�����������������������������������������������������������������������������������������31
Second Normal Form�������������������������������������������������������������������������������������32
Third Normal Form����������������������������������������������������������������������������������������33
Elasticsearch�������������������������������������������������������������������������������������������������������35
Connection Layer API�������������������������������������������������������������������������������������38
Neo4j Python Driver��������������������������������������������������������������������������������������������39
neo4j-rest-client�������������������������������������������������������������������������������������������������39
In-Memory Database������������������������������������������������������������������������������������������40
MongoDB (Python Edition)����������������������������������������������������������������������������������40
Import Data into the Collection����������������������������������������������������������������������41
Create a Connection Using pymongo�������������������������������������������������������������42
Access Database Objects������������������������������������������������������������������������������42
Insert Data�����������������������������������������������������������������������������������������������������43
Update Data���������������������������������������������������������������������������������������������������43
Remove Data�������������������������������������������������������������������������������������������������43
Cloud Databases�������������������������������������������������������������������������������������������������43
Pandas����������������������������������������������������������������������������������������������������������������44
ETL with Python (Unstructured Data)������������������������������������������������������������������45
Email Parsing�������������������������������������������������������������������������������������������������45
Topical Crawling��������������������������������������������������������������������������������������������48
Summary������������������������������������������������������������������������������������������������������������52
vi
Table of Contents
Semi-Supervised Learning���������������������������������������������������������������������������������65
Decision Tree�������������������������������������������������������������������������������������������������������66
Which Attribute Comes First?������������������������������������������������������������������������66
Random Forest Classifier������������������������������������������������������������������������������68
Naïve Bayes Classifier�����������������������������������������������������������������������������������������68
Support Vector Machine��������������������������������������������������������������������������������������69
Nearest Neighbor Classifier��������������������������������������������������������������������������������71
Sentiment Analysis���������������������������������������������������������������������������������������������71
Image Recognition����������������������������������������������������������������������������������������������73
Regression with Python���������������������������������������������������������������������������������74
Least Square Estimation��������������������������������������������������������������������������������75
Logistic Regression���������������������������������������������������������������������������������������76
Classification and Regression�����������������������������������������������������������������������������76
Intentionally Bias the Model to Over-Fit or Under-Fit������������������������������������������77
Dealing with Categorical Data�����������������������������������������������������������������������������78
Summary������������������������������������������������������������������������������������������������������������79
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
Index�������������������������������������������������������������������������������������������������243
x
About the Authors
Sayan Mukhopadhyay has more than 13 years
of industry experience and has been associated
with companies such as Credit Suisse, PayPal,
CA Technologies, CSC, and Mphasis. He has
a deep understanding of applications for
data analysis in domains such as investment
banking, online payments, online advertising,
IT infrastructure, and retail. His area of
expertise is in applying high-performance
computing in distributed and data-driven
environments such as real-time analysis, high-
frequency trading, and so on.
He earned his engineering degree in electronics and instrumentation
from Jadavpur University and his master’s degree in research in
computational and data science from IISc in Bangalore.
xi
About the Technical Reviewer
Joos Korstanje is a data scientist with more
than five years of industry experience in
developing machine learning tools, of which a
large part is forecasting models. He currently
works at Disneyland Paris where he develops
machine learning for a variety of tools.
xiii
Acknowledgments
Thanks to Labonic Chakraborty (Ripa) and Soumili Chakraborty.
xv
Introduction
We are living in the data science/artificial intelligence era. To thrive in
this environment, where data drives decision-making in everything from
business to government to sports and entertainment, you need the skills
to manage and analyze huge amounts of data. Together we can use this
data to make the world better for everyone. In fact, humans have yet to find
everything we can do using this data. So, let us explore!
Our objective for this book is to empower you to become a leader
in this data-transformed era. With this book you will learn the skills to
develop AI applications and make a difference in the world.
This book is intended for advanced user, because we have incorporated
some advanced analytics topics. Important machine learning models and
deep learning models are explained with coding exercises and real-world
examples.
All the source code used in this book is available for download at
https://github.com/apress/advanced-data-analytics-python-2e.
Happy reading!
xvii
CHAPTER 1
OOP in Python
In this section, we explain some features of object-oriented programming
(OOP) in a Python context.
The most basic element of any modern application is an object. To
a programmer or architect, the world is a collection of objects. Objects
consist of two types of members: attributes and methods. Members can be
private, public, or protected. Classes are data types of objects. Every object
is an instance of a class. A class can be inherited in child classes. Two
classes can be associated using composition.
Python has no keywords for public, private, or protected, so
encapsulation (hiding a member from the outside world) is not implicit in
Python. Like C++, it supports multilevel and multiple inheritance. Like Java,
it has an abstract keyword. Classes and methods both can be abstract.
© Sayan Mukhopadhyay, Pratip Samanta 2023 1
S. Mukhopadhyay and P. Samanta, Advanced Data Analytics Using Python,
https://doi.org/10.1007/978-1-4842-8005-8_1
Other documents randomly have
different content
and perhaps he had waited only until he should be firm in power in
order to throw off the tutelage of Talleyrand; but the moment had
arrived when his tastes coincided with policy. A second failure at St.
Domingo would destroy his own credit, and disgust both the army
and the public. Abandonment of the island was equally hazardous;
for it required the abandonment of French traditions and a
confession of failure. Retirement from St. Domingo was impossible,
except under cover of some new enterprise; and as Europe stood,
no other enterprise remained for France to undertake which would
not lead her armies across the Rhine or the Pyrenees. For this
undertaking Bonaparte was not yet ready; but even had he been so,
it would have offered no excuse for abandoning the colonies. The
ocean would still have been open, and St. Domingo within easy
reach.
Only one resource remained. Bonaparte told no one his plans;
but he was not a man to hesitate when decision was needed. From
the day when news of Leclerc’s death arrived, during the first week
of January, 1803, the First Consul brooded over the means of
abandoning St. Domingo without appearing to desert intentionally a
policy dear to France. Talleyrand and Decrès were allowed to go on
as before; they gave instructions to Bernadotte, and hurried the
preparations of Victor, whom the ice and snow of Holland and the
slowness of the workmen held motionless; they prepared a
reinforcement of fifteen thousand men for Rochambeau, and
Bonaparte gave all the necessary orders for hastening the departure
of both expeditions. As late as February 5, he wrote to Decrès that
fifteen thousand men had been, or were about to be, sent to St.
Domingo, and that fifteen thousand more must be ready to sail by
the middle of August.[14] Yet his policy of abandoning the colonial
system had been already decided; for on January 30 the “Moniteur”
produced Sebastiani’s famous Report on the military condition of the
East,—a publication which could have no other object than to alarm
England.[15]
Livingston was quick to see the change of policy; but although he
understood as much as was known to any one, he could not count
with certainty on the result.[16] Not even Joseph and Lucien knew
what was in their brother’s mind. Talleyrand seems to have been
elaborately deceived; even as late as February 19 he was allowed to
instruct General Beurnonville, the French ambassador at Madrid, to
express “the warm satisfaction which the last acts of sovereignty
exercised by the King of Spain in Louisiana have given to the First
Consul.”[17] The last act of sovereignty exercised by Spain in
Louisiana had been the closure of the Mississippi. Before
Beurnonville could obey this order, Godoy, hastening to anticipate
possible interference from France, promised Pinckney, February 28,
that the entrepôt should be restored. King Charles’s order of
restitution bore date March 1, 1803; Beurnonville’s note, urging the
King to sustain Morales, bore date March 4, and March 10 Don
Pedro Cevallos replied to Talleyrand’s congratulation in a tone so
evasive as to show that Godoy was again deceiving the First Consul.
[18] Cevallos did not say that the right of deposit had ten days before
been restored; he contented himself with mentioning the reasons
alleged by Morales for his act, adding at the close the empty
assurance that “in every way his Majesty prizes highly the applause
of the French government.” In January, only a few weeks before,
Godoy had told Beurnonville, with unconcealed satisfaction, that
Bonaparte should not have Florida,—although without Florida the
town of New Orleans was supposed to be of little value. In February
he snatched away what he could of New Orleans by replacing the
Americans in all their privileges there.
Livingston plied the French officials with arguments and
memorials; but he might have spared himself the trouble, for
Bonaparte’s policy was already fixed. The First Consul acted with the
rapidity which marked all his great measures. England at once took
Sebastiani’s Report as a warning, and began to arm. February 20
Bonaparte sent to the Corps Législatif his Annual Report, or
Message, which spoke of Great Britain in language that could not be
disregarded; finally, March 12, Livingston saw a melodramatic
spectacle which transfixed him with surprise and excitement.[19] The
scene was at Madame Bonaparte’s drawing-room; the actors were
Bonaparte and Lord Whitworth, the British ambassador. “I find, my
Lord, your nation want war again!” said the First Consul. “No, sir,”
replied Whitworth; “we are very desirous of peace.” “I must either
have Malta or war!” rejoined Bonaparte. Livingston received these
words from Lord Whitworth himself on the spot; and returning at
once to his cabinet, wrote to warn Madison. Within a few days the
alarm spread through Europe, and the affairs of St. Domingo were
forgotten.
Bonaparte loved long-prepared transformation-scenes. Such a
scene he was preparing, and the early days of April, 1803, found the
actors eagerly waiting it. All the struggles and passions of the last
two years were crowded into the explosion of April. At St. Domingo,
horror followed fast on horror. Rochambeau, shut in Port au Prince,
—drunken, reckless, surrounded by worthless men and by women
more abandoned still, wallowing in the dregs of the former English
occupation and of a half-civilized negro empire,—waged as he best
could a guerrilla war, hanging, shooting, drowning, burning all the
negroes he could catch; hunting them with fifteen hundred
bloodhounds bought in Jamaica for something more than one
hundred dollars each; wasting money, squandering men; while
Dessalines and Christophe massacred every white being within their
reach. To complete Bonaparte’s work, from which he wished to turn
the world’s attention, high among the Jura Mountains, where the ice
and snow had not yet relaxed their grip upon the desolate little
Fortress and its sunless casemate, in which for months nothing but
Toussaint’s cough had been heard, Commander Amiot wrote a brief
military Report to the Minister of Marine:[20] “On the 17th [April 7], at
half-past eleven o’clock of the morning, on taking him his food, I
found him dead, seated on his chair near his fire.” According to
Tavernier, doctor of medicine and chirurgien of Pontarlier, who
performed the autopsy, pleuro-pneumonia was the cause of
Toussaint’s death.
Toussaint never knew that St. Domingo had successfully resisted
the whole power of France, and that had he been truer to himself
and his color he might have worn the crown that became the
plaything of Christophe and Dessalines; but even when shivering in
the frosts of the Jura, his last moments would have glowed with
gratified revenge, had he known that at the same instant Bonaparte
was turning into a path which the negroes of St. Domingo had driven
him to take, and which was to lead him to parallel at St. Helena the
fate of Toussaint himself at the Château de Joux. In these days of
passion, men had little time for thought; and the last subject on
which Bonaparte thereafter cared to fix his mind was the fate of
Toussaint and Leclerc. That the “miserable negro,” as Bonaparte
called him, should have been forgotten so soon was not surprising;
but the prejudice of race alone blinded the American people to the
debt they owed to the desperate courage of five hundred thousand
Haytian negroes who would not be enslaved.
If this debt was due chiefly to the negroes, it was also in a degree
due to Godoy and to Spain. In the new shifting of scenes, Godoy
suddenly found himself, like Toussaint eighteen months before, face
to face with Bonaparte bent on revenge. No one knew better than
Godoy the dangers that hung over him and his country. Aware of his
perils, he tried, as in 1795, to conciliate the United States by a
course offensive to France. Not only did he restore the entrepôt at
New Orleans, but he also admitted the claims for damages sustained
by American citizens from Spanish subjects in the late war, and
through Don Pedro Cevallos negotiated with Pinckney a convention
which provided for a settlement of these claims.[21] Although he
refused to recognize in this convention the spoliations made by
Frenchmen within Spanish jurisdiction, and insisted that these were
in their nature claims against France which Spain was not morally
bound to admit, he consented to insert an article copied from the
expunged Article II. of the treaty of Morfontaine, reserving to the
United States the right to press these demands at a future time.
So well pleased was Jefferson with the conduct of Spain and the
Spanish ministers, that not a complaint was made of ill treatment;
and even the conduct of Morales did not shake the President’s faith
in the friendliness of King Charles. No doubt he mistook the motives
of this friendliness, for Spain had no other object than to protect her
colonies and commerce on the Gulf of Mexico, and hoped to prevent
attack by conciliation; while Madison imagined that Spain might be
induced by money to part with her colonies and admit the United
States to the Gulf. In this hope he instructed Pinckney,[22] in case he
should find that Louisiana had not been retroceded to France, to
offer a guaranty of Spanish territory west of the Mississippi as part of
the consideration for New Orleans and the Floridas. The offer was
made with a degree of cordiality very unlike the similar offer to
France, and was pressed by Pinckney so zealously that at last
Cevallos evaded his earnestness by a civil equivocation.
“The system adopted by his Majesty,” said he,[23] “not to
dispossess himself of any portion of his States, deprives him of the
pleasure of assenting to the cessions which the United States wish to
obtain by purchase.... The United States can address themselves to
the French government to negotiate the acquisition of territories which
may suit their interest.”
Cevallos knew that Bonaparte had bound himself formally never
to alienate Louisiana, and in referring Pinckney to France he
supposed himself safe. Pinckney, on the other hand, prided himself
on having helped to prevent France from gaining Florida as well as
Louisiana, and was anxious to secure West Florida for his own
credit; while he had no idea that Louisiana could be obtained at all.
Yet nearly a week before this note was written Louisiana had
become American property. So completely was Godoy deceived, that
when April arrived and he saw Spain again about to be dragged into
unknown perils, he never divined that he was to be struck in
America; his anxieties rose from fear that Spain might be dragged
into a new war in Europe, in subservience to France. He could
expect to escape such a war only by a quarrel with Napoleon, and
he knew that a war with Napoleon was a desperate resource.
In London statesmanship had an easier game, and played it at
first simply and coolly. Rufus King watched it with anxious eyes. He
wished to escape from the duty of expressing a diplomatic policy
which he might not approve, to a Government which had other and
heavier tasks than that of listening to his advice or warnings. The
British Ministry behaved well to America; for their advices from
Thornton led them to hope that the United States would, if properly
supported, seize Louisiana and accept war with Bonaparte. “If you
can obtain Louisiana,—well!” said Addington to Rufus King;[24] “if
not, we ought to prevent its going into the hands of France.”
CHAPTER II.
Monroe arrived in sight of the French coast April 7, 1803; but
while he was still on the ocean, Bonaparte without reference to him
or his mission, opened his mind to Talleyrand in regard to ceding
Louisiana to the United States. The First Consul a few days
afterward repeated to his Finance Minister, Barbé Marbois,[25] a part
of the conversation with Talleyrand; and his words implied that
Talleyrand opposed Bonaparte’s scheme, less because it sacrificed
Louisiana than because its true object was not a war with England,
but conquest of Germany. “He alone knows my intentions,” said
Bonaparte to Marbois. “If I attended to his advice, France would
confine her ambition to the left bank of the Rhine, and would make
war only to protect the weak States and to prevent any
dismemberment of her possessions; but he also admits that the
cession of Louisiana is not a dismemberment of France.” In reality,
the cession of Louisiana meant the overthrow of Talleyrand’s
influence and the failure of those hopes which had led to the
coalition of the 18th Brumaire.
Easter Sunday, April 10, 1803, arrived, and Monroe was leaving
Havre for Paris, when Bonaparte, after the religious ceremonies of
the day at St. Cloud, called to him two of his ministers, of whom
Barbé Marbois was one.[26] He wished to explain his intention of
selling Louisiana to the United States; and he did so in his peculiar
way. He began by expressing the fear that England would seize
Louisiana as her first act of war. “I think of ceding it to the United
States. I can scarcely say that I cede it to them, for it is not yet in our
possession. If, however, I leave the least time to our enemies, I shall
only transmit an empty title to those republicans whose friendship I
seek. They ask of me only one town in Louisiana; but I already
consider the colony as entirely lost; and it appears to me that in the
hands of this growing Power it will be more useful to the policy, and
even to the commerce, of France than if I should attempt to keep it.”
To this appeal the two ministers replied by giving two opposite
opinions. Marbois favored the cession, as the First Consul probably
expected him to do; for Marbois was a republican who had learned
republicanism in the United States, and whose attachment to that
country was secured by marriage to an American wife. His
colleague, with equal decision, opposed the scheme. Their
arguments were waste of breath. The First Consul said no more, and
dismissed them; but the next morning, Monday, April 11, at
daybreak, summoning Marbois, he made a short oration of the kind
for which he was so famous:[27]—
“Irresolution and deliberation are no longer in season; I renounce
Louisiana. It is not only New Orleans that I cede; it is the whole
colony, without reserve. I know the price of what I abandon. I have
proved the importance I attach to this province, since my first
diplomatic act with Spain had the object of recovering it. I renounce it
with the greatest regret; to attempt obstinately to retain it would be
folly. I direct you to negotiate the affair. Have an interview this very day
with Mr. Livingston.”
The order so peremptorily given was instantly carried out; but not
by Marbois. Talleyrand, in an interview a few hours afterward,
startled Livingston with the new offer.[28]
“M. Talleyrand asked me this day, when pressing the subject,
whether we wished to have the whole of Louisiana. I told him no; that
our wishes extended only to New Orleans and the Floridas; that the
policy of France, however, should dictate (as I had shown in an official
note) to give us the country above the River Arkansas, in order to
place a barrier between them and Canada. He said that if they gave
New Orleans the rest would be of little value, and that he would wish
to know ‘what we would give for the whole.’ I told him it was a subject I
had not thought of, but that I supposed we should not object to twenty
millions [francs], provided our citizens were paid. He told me that this
was too low an offer, and that he would be glad if I would reflect upon
it and tell him to-morrow. I told him that as Mr. Monroe would be in
town in two days, I would delay my further offer until I had the
pleasure of introducing him. He added that he did not speak from
authority, but that the idea had struck him.”
The suddenness of Bonaparte’s change disconcerted Livingston.
For months he had wearied the First Consul with written and verbal
arguments, remonstrances, threats,—all intended to prove that there
was nothing grasping or ambitious in the American character; that
France should invite the Americans to protect Louisiana from the
Canadians; that the United States cared nothing for Louisiana, but
wanted only West Florida and New Orleans,—“barren sands and
sunken marshes,” he said; “a small town built of wood; ... about
seven thousand souls;” a territory important to the United States
because it contained “the mouths of some of their rivers,” but a mere
drain of resources to France.[29] To this rhapsody, repeated day after
day for weeks and months, Talleyrand had listened with his
imperturbable silence, the stillness of a sceptical mind into which
such professions fell meaningless; until he suddenly looked into
Livingston’s face and asked: “What will you give for the whole?”
Naturally Livingston for a moment lost countenance.
The next day, Tuesday, April 12, Livingston, partly recovered from
his surprise, hung about Talleyrand persistently, for his chance of
reaping alone the fruit of his labors vanished with every minute that
passed. Monroe had reached St. Germain late Monday night, and at
one o’clock Tuesday afternoon descended from his postchaise at the
door of his Paris hotel.[30] From the moment of his arrival he was
sure to seize public attention at home and abroad. Livingston used
the interval to make one more effort with Talleyrand:[31]—
“He then thought proper to declare that his proposition was only
personal, but still requested me to make an offer; and upon my
declining to do so, as I expected Mr. Monroe the next day, he
shrugged up his shoulders and changed the conversation. Not willing,
however, to lose sight of it, I told him I had been long endeavoring to
bring him to some point, but unfortunately without effect; and with that
view had written him a note which contained that request.... He told
me he would answer my note, but that he must do it evasively,
because Louisiana was not theirs. I smiled at this assertion, and told
him that I had seen the treaty recognizing it.... He still persisted that
they had it in contemplation to obtain it, but had it not.”
An hour or two afterward came a note from Monroe announcing
that he would wait upon Livingston in the evening. The two American
ministers passed the next day together,[32] examining papers and
preparing to act whenever Monroe could be officially presented.
They entertained a party at dinner that afternoon in Livingston’s
apartments, and while sitting at table Livingston saw Barbé Marbois
strolling in the garden outside. Livingston sent to invite Marbois to
join the party at table. While coffee was served, Marbois came in and
entered into conversation with Livingston, who began at once to tell
him of Talleyrand’s “extraordinary conduct.” Marbois hinted that he
knew something of the matter, and that Livingston had better come
to his house as soon as the dinner company departed. The moment
Monroe took leave, Livingston acted on Marbois’s hint, and in a
midnight conversation the bargain was practically made. Marbois
told a story, largely of his own invention, in regard to the First
Consul’s conduct on Easter Sunday, three days before. Bonaparte
mentioned fifty million francs as his price for Louisiana; but as
Marbois reported the offer to Livingston, Bonaparte said: “Well! you
have charge of the Treasury. Let them give you one hundred millions
of francs, and pay their own claims, and take the whole country.” The
American claims were estimated at about twenty-five millions, and
therefore Marbois’s price amounted to at least one hundred and
twenty-five million francs.
Yet twenty-four or twenty-five million dollars for the whole west
bank of the Mississippi, from the Lake of the Woods to the Gulf of
Mexico, and indefinitely westward, was not an extortionate price,
especially since New Orleans was thrown into the bargain, and
indirect political advantages which could not be valued at less than
the cost of a war, whatever it might be. Five million dollars were to be
paid in America to American citizens, so that less than twenty
millions would come to France. Livingston could hardly have been
blamed for closing with Marbois on the spot, especially as his
instructions warranted him in offering ten millions for New Orleans
and the Floridas alone; but Livingston still professed that he did not
want the west bank. “I told him that the United States were anxious
to preserve peace with France; that for that reason they wished to
remove them to the west side of the Mississippi; that we would be
perfectly satisfied with New Orleans and the Floridas, and had no
disposition to extend across the river; that of course we would not
give any great sum for the purchase.... He then pressed me to name
the sum.” After a little more fencing, Marbois dropped at once from
one hundred millions to sixty, with estimated claims to the amount of
twenty millions more. “I told him that it was vain to ask anything that
was so greatly beyond our means; that true policy would dictate to
the First Consul not to press such a demand; that he must know it
would render the present government unpopular.” The conversation
closed by Livingston’s departure at midnight with a final protest: “I
told him that I would consult Mr. Monroe, but that neither he nor I
could accede to his ideas on the subject.” Then he went home; and
sitting down to his desk wrote a long despatch to Madison, to record
that without Monroe’s help he had won Louisiana. The letter closed
with some reflections:—
“As to the quantum, I have yet made up no opinion. The field open
to us is infinitely larger than our instructions contemplated, the
revenue increasing, and the land more than adequate to sink the
capital, should we even go the sum proposed by Marbois,—nay, I
persuade myself that the whole sum may be raised by the sale of the
territory west of the Mississippi, with the right of sovereignty, to some
Power in Europe whose vicinity we should not fear. I speak now
without reflection and without having seen Mr. Monroe, as it was
midnight when I left the Treasury Office, and it is now near three
o’clock. It is so very important that you should be apprised that a
negotiation is actually opened, even before Mr. Monroe has been
presented, in order to calm the tumult which the news of war will
renew, that I have lost no time in communicating it. We shall do all we
can to cheapen the purchase; but my present sentiment is that we
shall buy.”