Recovering design patterns applied in a system can help refactoring the system. Machine learning algorithms have been successfully applied in mining data patterns. However, one of the main obstacles of applying them for design pattern detection is the difficulty of collecting training examples. Unlike other applications, a design pattern instance typically includes a group of classes with certain relationships. Thus, the possible combinations of the group of classes can be enormous which results in huge training sets making the application of machine learning algorithms impracticable. In this paper, we propose an innovative method using matrix transformations to cluster the training examples. Our method can significantly reduce the size of training examples, thus making it possible to be efficiently applied in machine learning algorithm.