How to Score on a new Data Set

落爺英雄遲暮 提交于 2020-01-07 01:21:13

问题


We have built models in R for Clustering. We now want the equation of the model to be deployed for the new customers whom we want to Cluster. In SAS, the Cluster node used to provide a Clustering SAS code where we only had to to plug the new input variables. Is there a way to do that in R? How can we export the Cluster equation?

An example of the same is as below using the standard iris dataset.

irisnew <- iris
library("cluster", lib.loc="~/R/win-library/3.2")
(kc <- kmeans(irisnew, 3)) 

K-means clustering with 3 clusters of sizes 62, 38, 50

Cluster means:
  Sepal.Length Sepal.Width Petal.Length Petal.Width
1     5.901613    2.748387     4.393548    1.433871
2     6.850000    3.073684     5.742105    2.071053
3     5.006000    3.428000     1.462000    0.246000

Clustering vector:
  [1] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
 [39] 3 3 3 3 3 3 3 3 3 3 3 3 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 [77] 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 2 2 1 2 2 2 2 2 2 1
[115] 1 2 2 2 2 1 2 1 2 1 2 2 1 1 2 2 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 1

Within cluster sum of squares by cluster:
[1] 39.82097 23.87947 15.15100
 (between_SS / total_SS =  88.4 %)

Now that the Cluster is defined, i have a new dataset for petals that I need to classify according to the above clustering rules. My Question is how do i export the rules do that? Typically the rules are defined as

x = a1 * Sepal.Length + a2 * Sepal.Width +a3 * Petal.Length + a4 * Petal.Width + b
Then if x between z1 and z2 then Cluster1
else if x between z3 and z4 then Cluster2
else if x between z5 and z6 then Cluster3
else Cluster4

Thanks, Manish


回答1:


For Generic Models Use - predict.glm(glm.model, newdata = newdf))

For clustering Use - Simple approach to assigning clusters for new data after k-means clustering



来源:https://stackoverflow.com/questions/30023059/how-to-score-on-a-new-data-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!