Stroke has become a major disease that seriously threatens human health due to its high incidence and disability rates. Most patients undergo upper limb motor dysfunction after stroke, which significantly impairs the ability of stroke survivors in their activities of daily living (ADL). Robots provide an optional solution for stroke rehabilitation by attending therapy in the hospital and the community, however, the rehabilitation robot still has difficulty in providing needed assistance interactively like human clinicians in conventional therapy. For safe and rehabilitation training, a human-robot interaction space reshaping method was proposed based on the recovery states of patients. According to different recovery states, we designed seven experimental protocols suitable for distinguishing rehabilitation training sessions. To achieve assist-as-needed (AAN) control, a PSO-SVM classification model and an LSTM-KF regression model were introduced to recognize the motor ability of patients with electromyography (EMG) and kinematic data, and a region controller for interaction space shaping was studied. Ten groups of offline and online experiments and corresponding data processing were conducted, and the machine learning and AAN control results were presented, which ensured the effective and the safe upper limb rehabilitation training. To discuss the human-robot interaction in different training stages and sessions, we defined a quantified assistance level index that characterizes the rehabilitation needs by considering the engagement of the patients and had the potential to apply in clinical upper limb rehabilitation training.