Yu Garden is located very centrally in downtown Shanghai. The garden complex itself is an interesting sight, and the area around it is also teeming with fantastic street foods and souvenir shops that make for a good way to spend a late afternoon and evening
Like most attractions in central Shanghai, the best way to get to Yu Garden is by metro:
The closest stop to it is in fact the Yuyuan Garden Station (豫园), located on metro line 10. The station is three blocks west of Yu Garden so you will need to walk for a bit after you get out of the metro station. I've written here about how to use the metro system in Shanghai.
The subway fare should be no more than 3-4RMB from most places in central Shanghai ($0.5USD) so it's extremely cheap. The other main benefit of taking the subway is that it's wicked fast, much better than sitting through the Shanghai traffic. The downside is how packed the subway cars can be in the rush hours of 7:30am-9am and 4:30-7pm
When you get to the station, use Exit 3 to get out of the subway station
When you get to the ground level, cross the street to the east and keep walking east for 3 blocks to get to Yu Garden. The walk should take no more than 10 minutes
the opening hours of Yu Garden is 8:45am to 4:45pm, well within the operating hours of the subway system, so you should have no issues using the metro to get to it. However, if for whatever reason you want to visit it before 6am or after 11pm (the hours of the Shanghai metro system), you will need to take a taxi to get there.
Taking a taxi there is pretty easy. Just tell the driver to go to Yuyuan (pronounced like "Yu-Yuen", written as "豫园"), and all taxi drivers know exactly where it is. They will not be able to drop you off at the entrance, however, because all the streets around it are pedestrians only. You will have to walk for a few minutes to get to the entrance which is located here
Taxi fare should be 15-25 RMB ($2-$3.5USD) from most places in central Shanghai, and 25-50 RMB ($3.5-$7USD) from other areas farther away