  Galactic cosmic rays are mostly made up of energetic nuclei, with less than
$1\%$ of electrons (and positrons). Precise measurement of the electron and
positron component requires a very efficient method to reject the nuclei
background, mainly protons. In this work, we develop an unsupervised machine
learning method to identify electrons and positrons from cosmic ray protons for
the Dark Matter Particle Explorer (DAMPE) experiment. Compared with the
supervised learning method used in the DAMPE experiment, this unsupervised
method relies solely on real data except for the background estimation process.
As a result, it could effectively reduce the uncertainties from simulations.
For three energy ranges of electrons and positrons, 80--128 GeV, 350--700 GeV,
and 2--5 TeV, the residual background fractions in the electron sample are
found to be about (0.45 $\pm$ 0.02)$\%$, (0.52 $\pm$ 0.04)$\%$, and (10.55
$\pm$ 1.80)$\%$, and the background rejection power is about (6.21 $\pm$ 0.03)
$\times$ $10^4$, (9.03 $\pm$ 0.05) $\times$ $10^4$, and (3.06 $\pm$ 0.32)
$\times$ $10^4$, respectively. This method gives a higher background rejection
power in all energy ranges than the traditional morphological parameterization
method and reaches comparable background rejection performance compared with
supervised machine learning~methods.
