简体   繁体   中英

How can I find the data point in my PCA plot in python?

I made this PCA plot in python and I want to know the name or index of each point how can I find a way?

def pca_arrows_2d(df, pca) :

    feature_vectors = pca.components_.T

    # échelle des flèches
    arrow_size, text_pos = 7.0, 8.0,

    # projections des vecteurs de caractéristiques
    for i, v in enumerate(feature_vectors):
        plt.arrow(0, 0, arrow_size*v[0], arrow_size*v[1], 
                  head_width=0.2, head_length=0.2, linewidth=2, color='red', alpha = 0.5)
        plt.text(v[0]*text_pos, v[1]*text_pos, df.columns[i], color='grey', 
                 ha='center', va='center', fontsize=18)

sns.pairplot(x_vars=[0], y_vars=[1], data=df_pca, hue="classes", height=10)
pca_arrows_2d(X, pca)

主成分分析

Use visualization package plotly to create plots. You can move cursors around the plot and see the data and points. Plotly helps you to find the data and identify the data points in the visualization and its very simple to use.

You can also refer this:

How can I find the data point in my PCA plot in r?

I hope this helps and this is what you wanted?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM