The past decade has witnessed a widespread adoption of IoT devices and services in various applications such as intelligent transportation systems. It is crucial for IoT applications to select high-quality services to boost their reliability and efficiency. The prediction for Quality of Service (QoS) can be used to address this issue. Although a number of QoS prediction approaches have been proposed, their performance may be limited in the IoT environment where context features can significantly impact QoS predictions. Based on the historical QoS records of services, this paper proposes a collaborative QoS prediction approach using self-attention representation and deep factorization machine. The approach first leverages the global and local contextual information of services and users to learn personalized representations. Then, based on the personalized representations, it utilizes a deep factorization machine to make QoS predictions. Extensive experiments conducted on a real-world dataset show that the proposed QoS prediction approach significantly outperforms the other state-of-the-art approaches in terms of prediction accuracy.