<jupyter_start><jupyter_text>EVALUATION OF AFFILIATION TYPE INFERENCE METHODEvaluate how well works the method developed by checking accuracy with respect to ground truth.  Step necessary for ACII datasets, as ground truth is being used to check accuracy<jupyter_code>import io
import numpy as np
def get_code2(centre):
    
    university = ["University", "College", "Universidad", "Université", "Univ", "Università", "Universitat", 
              "Universidade", "Universiteit", "MIT"]
    research_centre = ["Research", "Centre", "Center", "Institute", "NASA", "Academy", 
                       'Project', 'Instituto', 'Institut', 'Lab', 'Labs', 'Centrum', 'Group', 'CNR']
    
    for item in university:
        if item in centre:
            return "Academia" 
    for item in research_centre:
        if item in centre:
            return "Research Centre"

    return "Industry" 
def infer_affiliation_type(df,col):
    df["Code"] = "I"
    codes = []

    for row in df[col]:
        if type(row) is str:
            codes.append(get_code2(row))
        else:
            codes.append(None)

    df.loc[:, 'Code'] = codes
    
    return df<jupyter_output><empty_output><jupyter_text>ACII<jupyter_code>ACII = True
if ACII == True:
    df_2019_test = infer_affiliation_type(df_2019_test,'Affiliation')
    df_2017_test = infer_affiliation_type(df_2017_test,'Affiliation')
    df_2015_test = infer_affiliation_type(df_2015_test,'Affiliation')
    df_2013_test = infer_affiliation_type(df_2013_test,'Affiliation')
    df_2011_test = infer_affiliation_type(df_2011_test,'Affiliation')
    df_2009_test = infer_affiliation_type(df_2009_test,'Affiliation')
    df_2007_test = infer_affiliation_type(df_2007_test,'Affiliation')
    df_2005_test = infer_affiliation_type(df_2005_test,'Affiliation')
if ACII == True:
    print('YEAR 2019')
    print()
    print('Academia       :', len(df_2019_test[df_2019_test.Code == 'Academia']))
    print('Industry       :', len(df_2019_test[df_2019_test.Code == 'Industry']))
    print('Research Centre:', len(df_2019_test[df_2019_test.Code == 'Research Centre']))
if ACII == True:
    print('YEAR 2017')
    print()
    print('Academia       :', len(df_2017_test[df_2017_test.Code == 'Academia']))
    print('Industry       :',len(df_2017_test[df_2017_test.Code == 'Industry']))
    print('Research Centre:',len(df_2017_test[df_2017_test.Code == 'Research Centre']))
if ACII == True:
    print('YEAR 2015')
    print()
    print('Academia       :',len(df_2015_test[df_2015_test.Code == 'Academia']))
    print('Industry       :',len(df_2015_test[df_2015_test.Code == 'Industry']))
    print('Research Centre:',len(df_2015_test[df_2015_test.Code == 'Research Centre']))
if ACII == True:
    print('YEAR 2013')
    print()
    print('Academia       :',len(df_2013_test[df_2013_test.Code == 'Academia']))
    print('Industry       :',len(df_2013_test[df_2013_test.Code == 'Industry']))
    print('Research Centre:',len(df_2013_test[df_2013_test.Code == 'Research Centre']))<jupyter_output>YEAR 2013

Academia       : 382
Industry       : 113
Research Centre: 61<jupyter_text>Eliminate null values for introducing data in divinAI<jupyter_code>df_complete_divinai = df_complete[['Gender', 'CountryAffilitation', 'Code']]
df_complete_divinai = df_complete_divinai.dropna()
df_complete_divinai.to_csv('') # specify route<jupyter_output><empty_output><jupyter_text>TEST : manually inferring Affiliation in order to see how my implementation works        Calculate how many inferences are correct with respect to ground truth.<jupyter_code>if ACII == True:
    df_2019['Code_infered']= df_2019_test.Code
    df_2017['Code_infered']= df_2017_test.Code
    df_2015['Code_infered']= df_2015_test.Code
    df_2013['Code_infered']= df_2013_test.Code
    df_2011['Code_infered']= df_2011_test.Code
    df_2009['Code_infered']= df_2009_test.Code
    df_2007['Code_infered']= df_2007_test.Code
    df_2005['Code_infered']= df_2005_test.Code
df_2019[['Affiliation','CountryAffilitation','Code','Code_infered']][5:15]
if ACII == True:
    aff_2019=len(df_2019[df_2019.Code == df_2019.Code_infered])/len(df_2019)*100
    aff_2017=len(df_2017[df_2017.Code == df_2017.Code_infered])/len(df_2017)*100
    aff_2015=len(df_2015[df_2015.Code == df_2015.Code_infered])/len(df_2015)*100
    aff_2013=len(df_2013[df_2013.Code == df_2013.Code_infered])/len(df_2013)*100
    aff_2011=len(df_2011[df_2011.Code == df_2011.Code_infered])/len(df_2011)*100
    aff_2009=len(df_2009[df_2009.Code == df_2009.Code_infered])/len(df_2009)*100
    aff_2007=len(df_2007[df_2007.Code == df_2007.Code_infered])/len(df_2007)*100
    aff_2005=len(df_2005[df_2005.Code == df_2005.Code_infered])/len(df_2005)*100
if ACII == True: 
    data = {'2019':[aff_2019],
            '2017':[aff_2017],
            '2015':[aff_2015],
           '2013':[aff_2013],
           '2011':[aff_2011],
            '2009':[aff_2009],
            '2007':[aff_2007],
           '2005':[aff_2005]}
    
    df_results = pd.DataFrame(data, index =['Affiliations coinciding with ground truth'])
    
    df_results = df_results.round(2)
    
    for i in df_results.columns:
        df_results[i] =  df_results[i].astype(str) + ' %'
    
    aff_acc = [aff_2019, aff_2017, aff_2015, aff_2013, aff_2011,aff_2009, aff_2007,aff_2005]
    
    mean_aff_acc = np.mean(aff_acc).round(3)
    print('MEAN ACCURACY OF AFFILIATION TYPE INFERENCE:', mean_aff_acc, '%')    
    print()
df_results.head()<jupyter_output>MEAN ACCURACY OF AFFILIATION TYPE INFERENCE: 86.982 %
{'fraction_non_alphanumeric': 0.13492494121902696, 'fraction_numerical': 0.0991137637909206, 'mean_word_length': 4.374149659863946, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '653525', 'license': 'MIT', 'n_tokens_mistral': 2422, 'n_tokens_neox': 1943, 'n_words': 331, 'path': 'evaluation/Evaluation Affiliation Inference with Ground Truth.ipynb', 'repo_name': 'saraestevez02/AI-diversity-analysis', 'size': '5529'}