Optimize K with elbow method