admin管理员组

文章数量:1122832

I’m working on a PCA loading plot and, based on the literature for my data, I expected IAF and B to fall within the smaller ellipse (less important variables). However, they are not; instead, RedEdge appears there.

I followed this guide: .html

What might I be doing wrong? My goal is to correctly place less important variables within the smaller ellipse. Any guidance would be appreciated!

variaveis_instrumentais = dados[['B', 'G', 'R', 'RedEdge', 'NIR', 'NDVI', 'NDRE', 
                                 'GNDVI', 'MPRI', 'SAVI', 'IAF', 'VARI']]
scaler = StandardScaler()
variaveis_instrumentais_normalizadas = scaler.fit_transform(variaveis_instrumentais)

pca = PCA(n_components=2)  
pca.fit(variaveis_instrumentais_normalizadas)

loadings = pcaponents_.T * np.sqrt(pca.explained_variance_)

importantes = []
nao_importantes = []

for i, var in enumerate(variaveis_instrumentais.columns):
    dist = np.sqrt(loadings[i, 0]**2 + loadings[i, 1]**2)  # Distância da origem
    if dist > 0.8: 
        importantes.append((var, loadings[i, 0], loadings[i, 1]))
    else:
        nao_importantes.append((var, loadings[i, 0], loadings[i, 1]))

for var, x, y in importantes:
    plt.scatter(x, y, color='g')  
    plt.text(x, y, var, color='g', fontsize=12)  

for var, x, y in nao_importantes:
    plt.scatter(x, y, color='b') 
    plt.text(x, y, var, color='b', fontsize=12)  

ellipse_outer = Ellipse((0, 0), width=2.0, height=1.5, edgecolor='black', fill=False, linestyle='--')
ellipse_inner = Ellipse((0, 0), width=1.4, height=1.0, edgecolor='black', fill=False, linestyle='-')
plt.gca().add_artist(ellipse_outer)
plt.gca().add_artist(ellipse_inner)

The result was:

The expected result:

本文标签: pythonIssues in Visualizing Variable Importance in PCA Loading PlotsStack Overflow