Tumor infiltration, known to associate with various cancer initiations and progressions, is a promising therapeutic target for aggressive cutaneous melanoma. Then, the relative infiltration of 24 kinds of immune cells in melanoma was assessed by a single sample gene set enrichment analysis (ssGSEA) program from a public database. The multiple machine learning algorithms were applied to evaluate the efficiency of immune cells in diagnosing and predicting the prognosis of melanoma. In comparison with the expression of immune cell in tumor and normal control, we built the immune diagnostic models in training dataset, which can accurately classify melanoma patients from normal (LR AUC = 0.965, RF AUC = 0.99, SVM AUC = 0.963, LASSO AUC = 0.964, and NNET AUC = 0.989). These diagnostic models were also validated in three outside datasets and suggested over 90% AUC to distinguish melanomas from normal patients. Moreover, we also developed a robust immune cell biomarker that could estimate the prognosis of melanoma. This biomarker was also further validated in internal and external datasets. Following that, we created a nomogram with a composition of risk score and clinical parameters, which had high accuracies in predicting survival over three and five years. The nomogram's decision curve revealed a bigger net benefit than the tumor stage. Furthermore, a risk score system was used to categorize melanoma patients into high- and low-risk subgroups. The high-risk group has a significantly lower life expectancy than the low-risk subgroup. Finally, we observed that complement, epithelial-mesenchymal transition, and inflammatory response were significantly activated in the high-risk group. Therefore, the findings provide new insights for understanding the tumor infiltration relevant to clinical applications as a diagnostic or prognostic biomarker for melanoma.