<jupyter_start><jupyter_text>Fitzpatrick Undersampling Test Data  Import Libraries<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Load Data<jupyter_code>test_data1=pd.read_csv("/content/drive/MyDrive/fairface_resampling/fitzpatrick_categorization/fitz_type_test_final.csv")
test_data=test_data1.copy()
test_data.head()
test_data.shape<jupyter_output><empty_output><jupyter_text>Undersampling The objective is to balance the data on 'gender' and 'phototype'. Manual undersampling was done by removing samples from the majority classes so that they are exactly equal to the minority class.<jupyter_code>plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = test_data)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
test_data['phototype'].value_counts()<jupyter_output><empty_output><jupyter_text>Taking an equal number of samples for phototype<jupyter_code>equal_phototype =test_data.groupby('phototype').head(1005)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_phototype)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_phototype)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_phototype['gender'].value_counts()<jupyter_output><empty_output><jupyter_text>----------------------------------------------------------------------- From equal ethnicities, take equal age groups<jupyter_code>equal_gender =equal_phototype.groupby('gender').head(2429)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_gender)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_gender)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_gender['phototype'].value_counts()<jupyter_output><empty_output><jupyter_text>From equal age groups take equal ethnicities<jupyter_code>equal_phototype_2 =equal_gender.groupby('phototype').head(929)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_phototype_2)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_phototype_2)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_phototype_2['gender'].value_counts()<jupyter_output><empty_output><jupyter_text>From second round of equal ethnicities, take equal ages<jupyter_code>equal_gender_2 =equal_phototype_2.groupby('gender').head(2313)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_gender_2)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_gender_2)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_gender_2['phototype'].value_counts()
equal_phototype_3 =equal_gender_2.groupby('phototype').head(920)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_phototype_3)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_phototype_3)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_phototype_3['gender'].value_counts()
equal_gender_3 =equal_phototype_3.groupby('gender').head(2294)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_gender_3)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_gender_3)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_gender_3['phototype'].value_counts()
equal_phototype_4 =equal_gender_3.groupby('phototype').head(908)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_phototype_4)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_phototype_4)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_phototype_4['gender'].value_counts()
equal_gender_4 =equal_phototype_4.groupby('gender').head(2266)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_gender_4)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_gender_4)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_gender_4['phototype'].value_counts()
equal_phototype_5 =equal_gender_4.groupby('phototype').head(903)
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='phototype', data = equal_phototype_5)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
plt.figure(figsize=(10,10))
chart=sns.countplot(x ='gender', data = equal_phototype_5)
chart.set_xticklabels(chart.get_xticklabels(), rotation=45);
equal_phototype_5['gender'].value_counts()
equal_phototype_5.head()<jupyter_output><empty_output><jupyter_text>Print out csv of images for final dataset<jupyter_code>equal_phototype_5.to_csv('/content/drive/MyDrive/fairface_resampling/fitz_undersampled_test.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15424311926605505, 'fraction_numerical': 0.035168195718654434, 'mean_word_length': 10.229613733905579, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '630351', 'license': 'Unlicense', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1872, 'n_words': 249, 'path': 'sourcecode/data_pre_processing/fitzpatrick_undersampling_test.ipynb', 'repo_name': 'VinitaSilaparasetty/msc-data-science-dissertation', 'size': '5232'}