Assign Model


When performing unsupervised experiments such as Clustering, Anomaly Detection or Natural Language Processing you are often interested in the labelsĀ generated by model, for e.g. cluster identification to which a datapoint belong to is a label in Clustering experiment. Similarly, which observation is an outlier is a binary label in Anomaly Detection experiments and which topic document pertains to is a label in Natural Language Processing experiment. This can be achieved in PyCaret using assign_model function which takes a trained model object as a single parameter.

This function is only available inĀ pycaret.clustering, pycaret.anomaly and pycaret.nlp modules.

 

Clustering Example

 

Code
# Importing dataset
from pycaret.datasets import get_data
jewellery = get_data('jewellery')

# Importing module and initializing setup
from pycaret.clustering import *
clu1 = setup(data = jewellery)

# create a model
kmeans = create_model('kmeans')

# Assign label
kmeans_results = assign_model(kmeans)

 

Output

Anomaly Detection Example

 

Code
# Importing dataset
from pycaret.datasets import get_data
anomalies = get_data('anomalies')

# Importing module and initializing setup
from pycaret.anomaly import *
ano1 = setup(data = anomalies)

# create a model
iforest = create_model('iforest')

# Assign label
iforest_results = assign_model(iforest)

 

Output

Natural Language Processing Example

 

Code
# Importing dataset
from pycaret.datasets import get_data
kiva = get_data('kiva')

# Importing module and initializing setup
from pycaret.nlp import *
nlp1 = setup(data = kiva, target = 'en')

# create a model
lda = create_model('lda')

# Assign label
lda_results = assign_model(lda)

 

Output

Try this next