The prediction of extreme greenhouse temperatures to which crops are susceptible is essential in the field of greenhouse planting. It can help avoid heat or freezing damage and economic losses. Therefore, it's important to develop models that can predict them accurately. Due to the lack of extreme temperature data in datasets, it is challenging for models to accurately predict it. In this paper, we propose an improved loss function, which is suitable for a variety of machine learning models. By increasing the weight of extreme temperature samples and reducing the possibility of misjudging extreme temperature as normal, the proposed loss function can enhance the prediction results in extreme situations. To verify the effectiveness of the proposed method, we implement the improved loss function in LightGBM, long short-term memory, and artificial neural network and conduct experiments on a real-world greenhouse dataset. The results show that the performance of models with the improved loss function is enhanced compared to the original models in extreme cases. The improved models can be used to guarantee the timely judgment of extreme temperatures in agricultural greenhouses, thereby preventing unnecessary losses caused by incorrect predictions.