Stoning a person to death will of course stop that person from committing rape again. But it will not stop the crime of rape. The only way to prevent rape is as you say through education. That is a hard task as many believe rape is sexually motivated whereas in truth it is about power. Although I don't deny sexual frustrations have a place to play in most cases.
Such punishment should be carried out in public so that it prevent others from committing such crime. But as I said the punishment is the last thing we should think of. Islam plants in hearts of people love of Allah : the most merciful loving creator , hope for eternal happiness in Janna and fear of hell. This combination of love, hope and fear is meant to create a living sensitive conscience that love to do all that is good and reject all that is evil. Quran instructs believers to have piety , lowers gaze , and dress modestly. Islam encourages marriage and Allah rewards the mother and father for caring for their families. No nudity is allowed in Islam . A muslem should not watch what is Haram (forbidden in Islam ). Purity of hearts is the essence of Islam since pure hearts are close to Allah subhanahu wa taaala , while small and big sins make a veil between the creature and his creator. I know that nowadays the media is free from any morality , it kills modesty inside hearts of people and enhance lusts and desires . They call it freedom , while it is actually locking people inside their own desires and making them slaves to materialism values . Faith teaches us how to rise and guide our own selves to a straight path, and make our souls fly to a higher domains.