fit_predict()
noun
say it: “FIT prih-DIKT” /ˈfɪt prɪˈdɪkt/
In scikit-learn, the method that trains a model on some rows and returns its answers for those same rows in one step.
What does fit_predict() do?
fit_predict() fits a model on some rows and hands back its answers for those same rows, in one call. On KMeans
it learns the clusters and returns each row's cluster number: the same as fit() followed by reading labels_.
from sklearn.cluster import KMeans
visits = [[1, 30], [2, 28], [1, 32], [6, 5], [7, 6], [6, 4]] # visits a week, dollars a visit
print(KMeans(n_clusters=2, random_state=0).fit_predict(visits)) # [1 1 1 0 0 0]
In a sentence
- “fit_predict() gave each of the 500 customers a cluster number.”
- “She used fit_predict() instead of calling fit() and then reading labels_.”
Level: Journeyman · More Python terms at this level
Updated