(self, name, path, overwrite=True, compress=3, locked_timeout=2)
return self
Save the model to disk at the specified path.
        If the model already exists and overwrite=False, throw an exception.
        If overwrite=True, replace any existing file with the same name at the path.
        If the model is found to be locked, wait 'locked_timeout' seconds and try again before quitting.
Save the model to disk at the specified path.
        If the model already exists and overwrite=False, throw an exception.
        If overwrite=True, replace any existing file with the same name at the path.
        If the model is found to be locked, wait 'locked_timeout' seconds and try again before quitting.
Save the model to disk at the specified path . If the model already exists and overwrite = False throw an exception . If overwrite = True replace any existing file with the same name at the path . If the model is found to be locked wait locked_timeout seconds and try again before quitting .
def save(self, name, path, overwrite=True, compress=3, locked_timeout=2):
        """
        Save the model to disk at the specified path.
        If the model already exists and overwrite=False, throw an exception.
        If overwrite=True, replace any existing file with the same name at the path.
        If the model is found to be locked, wait 'locked_timeout' seconds and try again before quitting.
        """
        
        # Create string for path and file name
        f = path + name + '.joblib'

        # Create a path for the lock file
        f_lock = f + '.lock'
                
        # Create the directory if required
        try:
            Path(path).mkdir(parents=True, exist_ok=False) 
        except FileExistsError:
            pass
        
        # If the file exists and overwriting is not allowed, raise an exception
        if Path(f).exists() and not overwrite:
            raise FileExistsError("The specified model name already exists: {0}.".format(name + '.joblib')\
                                  +"\nPass overwrite=True if it is ok to overwrite.")
        # Check if the file is currently locked
        elif Path(f_lock).exists():
            # Wait a few seconds and check again
            time.sleep(locked_timeout)
            # If the file is still locked raise an exception
            if Path(f_lock).exists():
                raise TimeoutError("The specified model is locked. If you believe this to be wrong, please delete file {0}".format(f_lock))
        else:
            # Update properties
            self.name = name
            self.state = 'saved'
            self.state_timestamp = time.time()

            # Keras models are excluded from the joblib file as they are saved to a special HDF5 file in _sklearn.py
            try:
                if self.using_keras:
                    # Get the trained keras model from the pipeline's estimator
                    keras_model = self.pipe.named_steps['estimator'].model
                    # Save the keras model architecture and weights to disk
                    keras_model.save(path + name + '.h5', overwrite=overwrite)
                                        
                    # The Keras estimator is excluded from the model saved to the joblib file
                    self.pipe.named_steps['estimator'].model = None
            except AttributeError:
                pass
            
            # Create the lock file
            joblib.dump(f_lock, filename=Path(f_lock), compress=compress)

            try:
                # Store this instance to file
                joblib.dump(self, filename=Path(f), compress=compress)
            finally:
                # Delete the lock file
                Path(f_lock).unlink()
                
        return self
def save ( self , name , path , overwrite = True , compress = 3 , locked_timeout = 2 ) : # Create string for path and file name f = path + name + '.joblib' # Create a path for the lock file f_lock = f + '.lock' # Create the directory if required try : Path ( path ) . mkdir ( parents = True , exist_ok = False ) except FileExistsError : pass # If the file exists and overwriting is not allowed, raise an exception if Path ( f ) . exists ( ) and not overwrite : raise FileExistsError ( "The specified model name already exists: {0}." . format ( name + '.joblib' ) + "\nPass overwrite=True if it is ok to overwrite." ) # Check if the file is currently locked elif Path ( f_lock ) . exists ( ) : # Wait a few seconds and check again time . sleep ( locked_timeout ) # If the file is still locked raise an exception if Path ( f_lock ) . exists ( ) : raise TimeoutError ( "The specified model is locked. If you believe this to be wrong, please delete file {0}" . format ( f_lock ) ) else : # Update properties self . name = name self . state = 'saved' self . state_timestamp = time . time ( ) # Keras models are excluded from the joblib file as they are saved to a special HDF5 file in _sklearn.py try : if self . using_keras : # Get the trained keras model from the pipeline's estimator keras_model = self . pipe . named_steps [ 'estimator' ] . model # Save the keras model architecture and weights to disk keras_model . save ( path + name + '.h5' , overwrite = overwrite ) # The Keras estimator is excluded from the model saved to the joblib file self . pipe . named_steps [ 'estimator' ] . model = None except AttributeError : pass # Create the lock file joblib . dump ( f_lock , filename = Path ( f_lock ) , compress = compress ) try : # Store this instance to file joblib . dump ( self , filename = Path ( f ) , compress = compress ) finally : # Delete the lock file Path ( f_lock ) . unlink ( ) return self