fix a bug in train_model function