Near-infrared (NIR) spectral-based classification of Aspergillus ochraceous contamination in the Robusta green coffee bean was investigated. Six different learning algorithms, including linear discriminant analysis (LDA), support vector machine (SVM), k-nearest neighbors (KNN), decision tree (Tree), Naive Bayes (NB), and quadratic discriminant analysis (QDA), were applied for the investigating purpose. Four classes of fungal contamination on coffee beans, non-fungal contaminated beans on day 1 and day 3 (NCB-D1 and NCB-D3) and fungal contaminated beans on day 1 and day 3 (CB-D1 and CB-D3), were set for the classification intention. Based on the 6 learning algorithms, the Tree approach was optimal, displaying a training accuracy of 97.5%. As proven by the testing dataset, the classification accuracy of the Tree was also at 97.5%. With this number, the Tree could correctly classify 100% between the contaminated and non-contaminated coffee beans. These findings exhibit the potential of the NIR spectroscopy accompanied by machine learning for the early detection of fungal contamination in green coffee beans.