Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to obtain the optimal Contour coefficient by python

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces python how to obtain the optimal profile coefficient, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

If you want the best point, you should choose the highest point.

1. By setting different k values to test and calculate the contour coefficient, the best contour coefficient corresponding to the best k value can be obtained.

2. You can also draw, observe and select the highest. However, in order to prevent the fitting phenomenon, the best k value can also be selected through the elbow.

Example

From sklearn.cluster import KMeansfrom sklearn.preprocessing import MaxAbsScaler # Decimal Calibration Standardization from sklearn.preprocessing import MinMaxScaler # deviation Standardization from sklearn.preprocessing import StandardScaler # Standard deviation Standardization # Evaluation Index-Contour coefficient from sklearn.metrics import silhouetee_score # due to clustering algorithm, the data may have dimensions and need to be standardized Before using the algorithm # instantiate sca = MaxAbsScaler () sca = MinMaxScaler () sca = StandardScaler () # fit sca.fit (training set feature) # process data X_train = sca.transform (training set feature) # instantiate km = KMeans () # Parameter: # n_clusters=3, that is, three random clustering centers, the minimum value is clustering init, the cluster center initialization method, the default k-means++# max_iter The maximum number of iterations is 3000.If you can't converge later, you can try to increase the number of iterations # random_state=1, random seed. The default is None # fitting km.fit (training set characteristics) # View the cluster center print ('clustering center:', km.cluster_centers_) # View the prediction results # you can directly enter the training set You can also pass in a custom two-dimensional array y_pred = km.predict (training set characteristics) print ('categories of the whole data:', y_pred) # View the sum of squares of SSE--- errors # take the inverse operation by default In most cases, the negative value [- inf, 0] # the smaller the absolute value, the better score = km.score (X_train, y_pred) print ('SSE', score) # Evaluation Index-Contour Factor (- 1,1), the bigger the better print (' Contour Factor:', silhouetee_score (X_train, y_pred)) Thank you for reading this article carefully. I hope the article "how to get the optimal profile coefficient of python" shared by the editor is helpful to everyone. At the same time, I also hope that you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report