CoolFace
Apppublic

Juliabelloni/weather-forecasting

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
saving_loading.cpython-312.pyc40 linesDownload Raw Back to __pycache__
1�

2�3g���L�ddlZddlZddlmZd	dededefd�Zd	dededefd�Zy)4�N)�
BaseEstimator�model�5model_name�	pollutantc���tjjtjjtj���}|d|�d|�d�z}t	j6||�y)a�7    Saves a given machine learning model to a specified file location.8 9    This function saves a scikit-learn model (or any compatible model) to a 10    `.joblib` file. The file is named based on the provided model name and pollutant.11    The saved model can be loaded later for predictions or further training.12 13    Args:14        model: The machine learning model to be saved (e.g., RandomForestRegressor).15        model_name (str): The name to use when saving the model file.16        pollutant (str, optional): The pollutant associated with the model, used to 17                                   differentiate models. Defaults to "NO2".18    19    Returns:20        None21    �/ML4IProject/src/models/�_�.joblibN)�os�path�dirname�getcwd�joblib�dump)rrr�root�	file_paths     �Zc:\Users\Lisa\Documents\2024-2025\ML for industry\ML4IProject\src\models\saving_loading.py�22save_modelrsQ��"�7�7�?�?�2�7�7�?�?�2�9�9�;�7�8�D��2�:�,�a�	�{�'�R�R�I�23�K�K��y�!��returnc���tjjtjjtj���}|d|�d|�d�z}t	j24|�}|S)aj25    Loads a scikit-learn model from a specified file location.26 27    This function loads a previously saved scikit-learn model from a `.joblib` file.28    The file is identified based on the provided model name and pollutant type.29 30    Args:31        model_name (str): The name of the model file to be loaded (without the extension).32        pollutant (str, optional): The pollutant associated with the model, used to 33                                   construct the file name. Defaults to "NO2".34    35    Returns:36        loaded_model (BaseEstimator): The loaded scikit-learn model (e.g., RandomForestRegressor).37 38    rr	r39)rrr
rr�load)rrrr�loaded_models     r�40load_modelrsW�� �7�7�?�?�2�7�7�?�?�2�9�9�;�7�8�D��2�:�,�a�	�{�'�R�R�I��;�;�y�)�L��r)�NO2)rr�sklearn.baser�strrr�rr�<module>rsB��	�
�&�"�m�"��"��"�*�3��3���r