Leveraging similarity in statistical learning