0 Daumen
256 Aufrufe

Ich möchte die Verteilungen von zwei Variablen beschreiben. dachte, dass ich entweder Box-Plots verwenden würde, die sowohl die x-als auch die yAchse überspannen, oder Verteilungsfunktionen. Ich wurde gerne:

bivariate_pca.png

Aber es is ein bivariate PCA Oder:

 distributions_34_0.png



Also tat ich es:

def plot_mean(columns_x, columns_y):
    try:
        plt.axis([-1, 1, -1, 1])   
        plt.grid(True)
        plt.xlabel(columns_x)
        plt.ylabel(columns_y)
        # We get all parties from df_parties_means
        for party in df_parties_means['Party']:
                # we get the probability distribution function
                party_x = df_parties_means.loc[
                    ((df_parties_means['Question'] == columns_x) & (df_parties_means['Party'] == party)), 'Mean']
                party_y = df_parties_means.loc[
                    ((df_parties_means['Question'] == columns_y) & (df_parties_means['Party'] == party)), 'Mean']
                # we plot the party related to the questions
                plt.scatter(party_x.values[0], party_y.values[0],
                        alpha=0.4, edgecolors='w',label = party)
                plt.text(party_x.values[0], party_y.values[0], party, fontsize=10)
        # We plot the people preferences
        plt.scatter(df_features[columns_x].mean( skipna = True), df_features[columns_y].mean( skipna = True),
            alpha=0.4, edgecolors='w')
        f, ax = plt.subplots(figsize=(6, 6))
       
        # plot the density function for the people preferences
        sns.kdeplot(df_features[columns_x], df_features[columns_y], ax=ax)
        sns.rugplot(df_features[columns_x], color="g", ax=ax)
        sns.rugplot(df_features[columns_y], vertical=True, ax=ax);
        plt.title('Perceptual map',y=1.05)
        plt.show()
    except Exception as e:
        print(len(party_x))
        print(len(party_y))
        print("columns_x: ", columns_x)
        print("columns_y: ", columns_y)
       
import itertools
   
pairs = list(itertools.combinations(df_features.columns, 2))

[plot_mean(pair[0],pair[1]) for pair in pairs]


Aber ich erhielt:

perceptual_map.jpg

distribution.jpg


 

Avatar von

Ein anderes Problem?

Stell deine Frage

Willkommen bei der Stacklounge! Stell deine Frage einfach und kostenlos

x
Made by a lovely community