  Machine learning is a powerful tool in finding hidden data patterns for
quantum information processing. Here, we introduce this method into the optical
readout of electron-spin states in diamond via single-photon collection and
demonstrate improved readout precision at room temperature. The traditional
method of summing photon counts in a time gate loses all the timing information
crudely. We find that changing the gate width can only optimize the contrast or
the state variance, not both. In comparison, machine learning adaptively learns
from time-resolved fluorescence data, and offers the optimal data processing
model that elaborately weights each time bin to maximize the extracted
information. It is shown that our method can repair the processing result from
imperfect data, reducing 7% in spin readout error while optimizing the
contrast. Note that these improvements only involve recording photon time
traces and consume no additional experimental time, they are thus robust and
free. Our machine learning method implies a wide range of applications in
precision measurement and optical detection of states.
