コード例 #1
0
 def test_predict_heads_with_novelties(self):
     """Test scoring heads with labeling as novel w.r.t. training and testing."""
     heads_df = get_head_prediction_df(self.model, 'conferences', 'brazil', testing=self.testing_mapped_triples)
     self.assertEqual(['head_id', 'head_label', 'score', 'in_training', 'in_testing'], list(heads_df.columns))
     self.assertEqual(self.model.num_entities, len(heads_df.index))
     training_heads = set(heads_df.loc[heads_df['in_training'], 'head_label'])
     self.assertEqual({'usa', 'india', 'ussr', 'poland', 'cuba'}, training_heads)
     testing_heads = set(heads_df.loc[heads_df['in_testing'], 'head_label'])
     self.assertEqual(set(), testing_heads)
コード例 #2
0
ファイル: test_pipeline.py プロジェクト: pykeen/pykeen
 def test_predict_heads_with_novelties(self):
     """Test scoring heads with labeling as novel w.r.t. training and testing."""
     heads_df = get_head_prediction_df(
         self.model,
         "conferences",
         "brazil",
         triples_factory=self.dataset.training,
         testing=self.testing_mapped_triples,
     )
     self.assertEqual(
         ["head_id", "head_label", "score", "in_training", "in_testing"],
         list(heads_df.columns))
     self.assertEqual(self.model.num_entities, len(heads_df.index))
     training_heads = set(heads_df.loc[heads_df["in_training"],
                                       "head_label"])
     self.assertEqual({"usa", "india", "ussr", "poland", "cuba"},
                      training_heads)
     testing_heads = set(heads_df.loc[heads_df["in_testing"], "head_label"])
     self.assertEqual(set(), testing_heads)
コード例 #3
0
ファイル: kgraph.py プロジェクト: ideaconsult/notebooks-ambit
        indices=None).cpu().detach().numpy()

    e_idx = ann(entity_embedding_tensor)
    e_idx.save_index(entity_index)

    from pykeen.models import predict
    terms = [
        'http://purl.enanomapper.org/onto/ENM_8000299',
        'http://semanticscience.org/resource/CHEMINF_000228',
        'http://purl.jp/bio/4/id/200906029372903982',
        'http://purl.enanomapper.org/onto/ENM_0000084'
    ]
    for term in terms:
        print(term)
        try:
            predicted_heads_df = predict.get_head_prediction_df(
                result.model, 'keyword', term, triples_factory=result.training)
            predicted_heads_df.head()
        except:
            pass

with open("{}/entity_id_to_label.json".format(kg_file), 'r') as infile:
    entity_id_to_label = json.load(infile)
import pandas as pd
df = pd.DataFrame.from_dict(entity_id_to_label, orient='index', columns=["id"])

import numpy as np
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
pca.fit(entity_embedding_tensor)
X = pca.transform(entity_embedding_tensor)
df["x"] = X[:, 0]