The invention belongs to the field of artificial intelligence machine learning, and discloses a domain generalization and domain self-adaption method based on data expansion consistency, which comprises the following steps: S1, according to task requirements, designing a prediction model p theta (y | x) based on a deep neural network, theta being a model parameter, and model output being conditional probability distribution of marking y under the condition of a given sample x; S2, constructing a data expander according to task characteristics, converting the sample, and keeping the core content of the sample unchanged, so as to keep the real mark of the converted sample unchanged; S3, constructing a multi-task loss function consisting of supervised loss and data expansion consistency lossby utilizing the original training sample and the expanded sample, and training to obtain p theta * (y | x); and S4, applying the trained model p theta * (y | x) to a target field test sample for prediction. The domain generalization and domain adaptive learning method is simple, universal and good in performance, and the technical problem of domain offset can be better solved.