A data compression method uses a template. In the template, the template optimizing is performed by an artificial intelligent technique (such as a genetic algorithm). The artificial intelligent techniqiue is applied to segments defined by diving input data into uniform segment units. The compression method contributes to enhancing the prediction accuracy. The data is compressed using the results of optimization, and a database is updated to improve the compression efficiency and speed of the subsequent processings. By updating a database by using an optimized template, a template for improving the prediction accuracy is obtained quickly without applying any artificial intelligent technique.