Inference¶
Contents
A PredictSession
provides access to making prediction
from saved models. Predictions for a single point are stored
in the Prediction
.
PredictSession¶
-
class
smurff.
PredictSession
(root_file)¶ Session for making predictions using a model generated using a
TrainSession
.A
PredictSession
can be made directly from aTrainSession
>>> predict_session = train_session.makePredictSession()
or from a root file
>>> predict_session = PredictSession("root.ini")
-
predict
(coords_or_sideinfo=None)¶ Generate predictions on coords_or_sideinfo. Parameters specify coordinates of sideinfo/features for each dimension. :param operands: A combination of coordindates in the matrix/tensor and/or features you want to use
to make predictions. len(coords) should be equal to number of dimensions in the sample. Each element coords can be a:
- int : a single element in this dimension is selected. For example, a single row or column in a matrix.
slice
: a slice is selected in this dimension. For example, a number of rows or columns in a matrix.- None : all elements in this dimension are selected. For example, all rows or columns in a matrix.
numpy.ndarray
: 2D numpy array used as dense sideinfo. Each row vector is used as side-info.scipy.sparse.spmatrix
: sparse matrix used as sideinfo. Each row vector is used as side-info.
Returns: A numpy.ndarray
of shape [ N x T1 x T2 x … ] where N is the number of samples in this PredictSession and T1 x T2 x … has the same numer of dimensions as the train data.Return type: numpy.ndarray
-
predict_all
()¶ Computes the full prediction matrix/tensor.
Returns: A numpy.ndarray
of shape [ N x T1 x T2 x … ] where N is the number of samples in this PredictSession and T1 x T2 x … is the shape of the train data.Return type: numpy.ndarray
-
predict_one
(coords_or_sideinfo, value=nan)¶ Computes prediction for one point in the matrix/tensor
Parameters: - coords_or_sideinfo (tuple of coordinates and/or feature vectors) –
- value (float, optional) – The true value for this point
Returns: The prediction
Return type:
-
predict_some
(test_matrix)¶ Computes prediction for all elements in a sparse test matrix
Parameters: test_matrix (scipy sparse matrix) – Coordinates and true values to make predictions for Returns: list of Prediction
objects.Return type: list
-
Prediction¶
-
class
smurff.
Prediction
(coords, val, pred_1sample=nan, pred_avg=nan, var=nan, nsamples=-1)¶ Stores predictions for a single point in the matrix/tensor
-
coords
¶ Position of this prediction in the train matrix/tensor
Type: shape
-
val
¶ True value or “nan” if no true value is known
Type: float
-
nsamples
¶ Number of samples collected to make this prediction
Type: int
-
pred_1sample
¶ Predicted value using only the last sample
Type: float
-
pred_avg
¶ Predicted value using the average prediction across all samples
Type: float
-
var
¶ Variance amongst predictions across all samples
Type: float
-
pred_all
¶ List of predictions, one for each sample
Type: list
-
static
fromTestMatrix
(test_matrix)¶ Creates a list of predictions from a scipy sparse matrix”
Parameters: test_matrix (scipy sparse matrix) – Returns: List of Prediction
. Only the coordinate and true value is filled.Return type: list
-