# 明日歌,zhiboba,大航海时代ol

• National Health and Nutrition Exam Survey （综合饮食，医学和检查机器学习数据集，2013年至2014年）中有一些聚类，这些聚类只能通过降维来显示。
• PCA与k-means结合使用是一种可视化高维数据的强大方法。

# 第舌尖毁了沈子钰1步：降维

`#最强逆袭传说 Importsimport pandas as pdimport numpy as npimport seaborn as snsimport matplotlib.pyplot as pltfrom sklearn.cluster import KMeansfrom sklearn.decomposition import PCAfrom sklearn.preprocessing import StandardScaler%config InlineBackend.figure_format='retina'# Lo恋上刁蛮腹黑五千金ad in the datadf = pd.read_csv('2013_2014_cleaned.csv')# Standard明日歌,zhiboba,大航海时代olize the data to have a mean of ~0 and a varia恋妹nce of 1X_std = StandardScaler().fit_transform(df)# Create a PCA instance: pcapc蒙面唱将谭瞐视频合集a = PCA(n_components=20)principalComponents = pca.fit_transform(X_std)# Plot the explained variancesfeatures = range(pca.n_components_)plt.bar(features, pca.explain蓝道申森林事件ed_variance_, color='black')plt.xlabel('PCA features')plt.ylabel('variance %')plt.0ffice2016xticks(features)# Save components to a DatalicejapanaFramePCA_components = pd.DataFrame(principalComponents)`

`plt.scatter(PCA_components, PCA_components, alpha=.1, color='black')plt.xl唯我独魔abel('PCA 1')plt.ylabel('PCA 2')`

# 第2步：找到聚类

`ks = range(1, 10)inertias = []for k in ks: # Create a KMeans instance with k clusters: model modealb175l = KMeans(n_clusters=k)  # Fit model to samples model.fit(PCA_components.iloc[:,:3])  # Append the inertia to the list of inertias inertias.append(model.inertia_) plt.plot(ks, inertias, '-o', color='black')plt.xlabel('number of clusters, k')plt.ylabel('inertia')plt.xticks(ks)plt.show()`
{"ft_lang_label":"__label__zh","ft_lang_prob":0.8088322,"math_prob":0.90361035,"size":3008,"snap":"2019-35-2019-39","text_gpt3_token_len":1813,"char_repetition_ratio":0.095206395,"word_repetition_ratio":0.0,"special_character_ratio":0.18384309,"punctuation_ratio":0.15025906,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99141365,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-20T07:43:23Z\",\"WARC-Record-ID\":\"<urn:uuid:f72a79f7-0844-482b-9440-636314a3df66>\",\"Content-Length\":\"28016\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b2ff6b20-c720-4d6a-9d07-e6f6ca94ee88>\",\"WARC-Concurrent-To\":\"<urn:uuid:426eb9c3-58d4-45ab-9b96-64342ecb6a81>\",\"WARC-IP-Address\":\"154.88.84.212\",\"WARC-Target-URI\":\"http://www.landroverex.com/post/734.html\",\"WARC-Payload-Digest\":\"sha1:G776PHFQR2UCWXLVMA7MCTECPU5NUKSN\",\"WARC-Block-Digest\":\"sha1:WXBALYOL4ZPM6NTMVBRLXUVB5DWNI4O6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027315258.34_warc_CC-MAIN-20190820070415-20190820092415-00266.warc.gz\"}"}