turicreate.activity_classifier.ActivityClassifier.predict

ActivityClassifier.predict(dataset, output_type='class', output_frequency='per_row')

Return predictions for dataset, using the trained activity classifier. Predictions can be generated as class labels, or as a probability vector with probabilities for each class.

The activity classifier generates a single prediction for each prediction_window rows in dataset, per session_id. The number of these predictions is smaller than the length of dataset. By default, when output_frequency='per_row', each prediction is repeated prediction_window to return a prediction for each row of dataset. Use output_frequency=per_window to get the unreplicated predictions.

Parameters:
dataset : SFrame

Dataset of new observations. Must include columns with the same names as the features used for model training, but does not require a target column. Additional columns are ignored.

output_type : {‘class’, ‘probability_vector’}, optional

Form of each prediction which is one of:

  • ‘probability_vector’: Prediction probability associated with each class as a vector. The probability of the first class (sorted alphanumerically by name of the class in the training set) is in position 0 of the vector, the second in position 1 and so on.
  • ‘class’: Class prediction. This returns the class with maximum probability.
output_frequency : {‘per_row’, ‘per_window’}, optional

The frequency of the predictions which is one of:

  • ‘per_window’: Return a single prediction for each prediction_window rows in dataset per session_id.
  • ‘per_row’: Convenience option to make sure the number of predictions match the number of rows in the dataset. Each prediction from the model is repeated prediction_window times during that window.
Returns:
out : SArray | SFrame

If output_frequency is ‘per_row’ return an SArray with predictions for each row in dataset. If output_frequency is ‘per_window’ return an SFrame with predictions for prediction_window rows in dataset.

See also

create, evaluate, classify

Examples

# One prediction per row
>>> probability_predictions = model.predict(
...     data, output_type='probability_vector', output_frequency='per_row')[:4]
>>> probability_predictions

dtype: array
Rows: 4
[array('d', [0.01857384294271469, 0.0348394550383091, 0.026018327102065086]),
 array('d', [0.01857384294271469, 0.0348394550383091, 0.026018327102065086]),
 array('d', [0.01857384294271469, 0.0348394550383091, 0.026018327102065086]),
 array('d', [0.01857384294271469, 0.0348394550383091, 0.026018327102065086])]

# One prediction per window
>>> class_predictions = model.predict(
...     data, output_type='class', output_frequency='per_window')
>>> class_predictions

+---------------+------------+-----+
| prediction_id | session_id |class|
+---------------+------------+-----+
|       0       |     3      |  5  |
|       1       |     3      |  5  |
|       2       |     3      |  5  |
|       3       |     3      |  5  |
|       4       |     3      |  5  |
|       5       |     3      |  5  |
|       6       |     3      |  5  |
|       7       |     3      |  4  |
|       8       |     3      |  4  |
|       9       |     3      |  4  |
|      ...      |    ...     | ... |
+---------------+------------+-----+