Martin Canning scored the winner as Hamilton held off a spirited Dunfermline side to secure a 3-2 victory at East End Park.