Here's an example of how you can export the K-means model from Modeler and import it into Python using pmml-sklearn
:
- Export the K-means model from IBM SPSS Modeler as a PMML file.
- Install the
pmml-sklearn
library using pip install pmml-sklearn
.
- Load the PMML file and use it to create the K-means model in Python.
from sklearn_pmml import sklearn2pmml
from sklearn_pmml.convert import estimator_to_pmml
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3, init='k-means++', random_state=0)
kmeans.fit(data)
pmml_file = "kmeans_model.pmml"
sklearn2pmml(kmeans, pmml_file, with_repr=True)
from sklearn_pmml import PMMLPipeline
pipeline = PMMLPipeline.from_pmml(pmml_file)
labels = pipeline.predict(data)
centers = pipeline.named_steps['kmeans'].cluster_centers_
Hope this helps !
------------------------------
Youssef Sbai Idrissi
Software Engineer
------------------------------
Original Message:
Sent: Thu December 15, 2022 03:05 PM
From: Eduardo García
Subject: K-means PMML model to Python
I first created a K means model in Modeler and then I created a model in Python with Scikit learn library. So when I compared the results of both models they were different, the question is ¿is there anyway to use de PMML exportation of the model in Python? or ¿How can I replicate the model of K means from Moderler in Python?
------------------------------
Eduardo García
------------------------------
#SPSSModeler