Publishing datasets plays an essential role in open data research and
promoting transparency of government agencies. However, such data publication
might reveal users' private information. One of the most sensitive sources of
data is spatiotemporal trajectory datasets. Unfortunately, merely removing
unique identifiers cannot preserve the privacy of users. Adversaries may know
parts of the trajectories or be able to link the published dataset to other
sources for the purpose of user identification. Therefore, it is crucial to
apply privacy preserving techniques before the publication of spatiotemporal
trajectory datasets. In this paper, we propose a robust framework for the
anonymization of spatiotemporal trajectory datasets termed as machine learning
based anonymization (MLA). By introducing a new formulation of the problem, we
are able to apply machine learning algorithms for clustering the trajectories
and propose to use $k$-means algorithm for this purpose. A variation of
$k$-means algorithm is also proposed to preserve the privacy in overly
sensitive datasets. Moreover, we improve the alignment process by considering
multiple sequence alignment as part of the MLA. The framework and all the
proposed algorithms are applied to TDrive and Geolife location datasets. The
experimental results indicate a significantly higher utility of datasets by
anonymization based on MLA framework.