1. A method for controlling an electrical machine in a drivetrain of a motor vehicle, the electrical machine being used as a drive unit for the motor vehicle, the method comprising: determining, with a pilot control unit, a pilot control torque as a function of a predefined target torque of the electrical machine, the pilot control unit having a transfer function that corresponds to an oscillation component of a transfer function, ascertained in model-supported fashion for the overall drivetrain, that describes a dependence of a rotation speed of the electrical machine on a torque with which the electrical machine is operated as a function of (i) a moment of inertia of the electrical machine in the drivetrain of the motor vehicle and (ii) a moment of inertia of the motor vehicle; determining a corrected target torque for the electrical machine by superimposing the pilot control torque on the predefined target torque; and controlling the electrical machine as a function of the corrected target torque.