Predictor
Predictor
#
Base class. Implements all low-level functionality.
Parameters:
-
path
(str
, default:None
) –Directory location to store all outputs. Defaults to None. If None, a new unique time-stamped directory is chosen.
-
name
(str
, default:None
) –Name of the subdirectory inside
path
where the model will be saved. The final model directory will beos.path.join(path, name)
. If None, defaults to the model's class name:self.__class__.__name__
.
Source code in src/qtt/predictors/predictor.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
is_fit: bool
property
#
Returns True if the model has been fit.
fit(X, y, verbosity=2, **kwargs)
#
Fit model to predict values in y based on X.
Models should not override the fit
method, but instead override the _fit
method which has the same arguments.
Parameters:
-
X
(DataFrame
) –The training data features.
-
y
(ArrayLike
) –The training data ground truth labels.
-
verbosity
(int), default = 2
, default:2
) –Verbosity levels range from 0 to 4 and control how much information is printed. Higher levels correspond to more detailed print statements (you can set verbosity = 0 to suppress warnings). verbosity 4: logs every training iteration, and logs the most detailed information. verbosity 3: logs training iterations periodically, and logs more detailed information. verbosity 2: logs only important information. verbosity 1: logs only warnings and exceptions. verbosity 0: logs only exceptions.
-
**kwargs
–Any additional fit arguments a model supports.
Source code in src/qtt/predictors/predictor.py
load(path, reset_paths=True, verbose=True)
classmethod
#
Loads the model from disk to memory.
Parameters:
-
path
(str
) –Path to the saved model, minus the file name. This should generally be a directory path ending with a '/' character (or appropriate path separator value depending on OS). The model file is typically located in os.path.join(path, cls.model_file_name).
-
reset_paths
(bool
, default:True
) –Whether to reset the self.path value of the loaded model to be equal to path. It is highly recommended to keep this value as True unless accessing the original self.path value is important. If False, the actual valid path and self.path may differ, leading to strange behaviour and potential exceptions if the model needs to load any other files at a later time.
-
verbose
(bool
, default:True
) –Whether to log the location of the loaded file.
Returns:
-
model
(Predictor
) –Loaded model object.
Source code in src/qtt/predictors/predictor.py
predict(**kwargs)
#
Predicts the output for the given input data.
New predictors should override this method with their custom prediction logic.
preprocess(**kwargs)
#
reset_path(path=None)
#
Reset the path of the model.
Parameters:
-
path
(str
, default:None
) –Directory location to store all outputs. If None, a new unique time-stamped directory is chosen.
Source code in src/qtt/predictors/predictor.py
save(path=None, verbose=True)
#
Saves the model to disk.
Parameters:
-
path
(str
, default:None
) –Path to the saved model, minus the file name. This should generally be a directory path ending with a '/' character (or appropriate path separator value depending on OS). If None, self.path is used. The final model file is typically saved to os.path.join(path, self.model_file_name).
-
verbose
(bool
, default:True
) –Whether to log the location of the saved file.
Returns:
-
path
(str
) –Path to the saved model, minus the file name. Use this value to load the model from disk via cls.load(path), cls being the class of the model object, such as
model = PerfPredictor.load(path)