+1 Daumen
393 Aufrufe

Ich habe eine Funktion, die ein Array und einen Datenrahmen als Eingabe verwendet. Ich fuhre Ahnlichkeitsberechnungen zwischen den Elementen in dieser Tabelle und dene im Datenrahmen durch. Ich mochte die Ergebnisse in Spalten fur jedes der Elemente im Datenrahmen speichern.

 

   def compute_similarity(references, target):

        # I want to create as many rows as there are references and fill them with the results
        # arccos based text similarity (Yang et al. 2019; Cer et al. 2019)
        for row in target.iterrows():
            for reference in references:
                sim = 1 - np.arccos(
                result = sklearn.metrics.pairwise.cosine_similarity(row,
                                                                    reference))/np.pi
            # place the result in the column "reference"


Zum Beispiel mit references:

 
   array(['Agriculture, farming and environment',
          'Accountancy], dtype=object)



Y der Datenrahmen Target:

    0                                      Chef de projet
    1                                            ASSUREUR
    2                                FONCTIONNAIRE D'ÉTAT
    3                                      cadre supérieur
    4                                        fonctionnaire
    5                                        CDB Retraite
    6                                          professeur
    7                                      Chef de projet
    8                                          مدير  شركة


Ich mochte:

 
     new_professionactuelle Agriculture, farming and environment Accountancy, banking and finance
    0 Chef de projet         2.205516                             -0.989579
    1 ASSUREUR             -0.982828                             0.826499
    2 FONCTIONNAIRE D'ÉTAT -0.163224                             0.206288
    3 cadre supérieur     -0.272837                             1.406747
    4 fonctionnaire         0.519358                             -0.922361

Avatar von

Ein anderes Problem?

Stell deine Frage

Willkommen bei der Stacklounge! Stell deine Frage einfach und kostenlos

x
Made by a lovely community