Obtaining cost matrix from datasets