turicreate.nearest_neighbor_classifier.NearestNeighborClassifier.classify — Turi Create API 6.4.1 documentation (original) (raw)

NearestNeighborClassifier. classify(dataset, max_neighbors=10, radius=None, verbose=True)

Return the predicted class for each observation in dataset. This prediction is made based on the closest neighbors stored in the nearest neighbors classifier model.

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. verbose : bool, optional If True, print progress updates. max_neighbors : int, optional Maximum number of neighbors to consider for each point. radius : float, optional Maximum distance from each point to a neighbor in the reference dataset.
Returns: out : SFrame An SFrame with model predictions. The first column is the most likely class according to the model, and the second column is the predicted probability for that class.

Notes

Examples

sf_train = turicreate.SFrame({'species': ['cat', 'dog', 'fossa', 'dog'], ... 'height': [9, 25, 20, 23], ... 'weight': [13, 28, 33, 22]}) ... sf_new = turicreate.SFrame({'height': [26, 19], ... 'weight': [25, 35]}) ... m = turicreate.nearest_neighbor_classifier.create(sf, target='species') ystar = m.classify(sf_new, max_neighbors=2) print ystar +-------+-------------+ | class | probability | +-------+-------------+ | dog | 1.0 | | fossa | 0.5 | +-------+-------------+