[Python] Does TSNE or PCA change the row order of dataframe?

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I am using TSNE or PCA for dimensionality reduction to 2 features. My original dataframe has Date as index. After fit_transform() using either tsne or PCA, I am wondering if it will change the row order. or does it involve random sampling in TSNE or PCA? I like to include the Date information back to transformed array so need to make sure the row order remains the same after fit_transform().


    if 'tsne' in pca_method.lower():

    Xemb = TSNE(n_components=2, init='pca', perplexity=perplexity, max_iter=max_iter).fit_transform(df_1.values)
    print('shape of Xemb=',Xemb.shape)
    xMin, xMax = np.min(Xemb, axis=0), np.max(Xemb, axis=0)
    Xemb = (Xemb - xMin) / (xMax - xMin)
    pca=None
    elif 'pca' in pca_method.lower():
    pca = PCA(n_components=2)
    Xemb = pca.fit_transform(df_1.values)

    #put the date back to dateframe for plotting purpose

    df_pca=pd.DataFrame({'Date':df_1.index,'PCA_1':Xemb[:,0],'PCA_2':Xemb[:,1],}).set_index('Date')

    Continue reading...

Compartilhe esta Página