Mean Cords Per Group


1. Mean Number of Cords Per Group

Mean Number of Cords Per Group, including pendant cords, subsidiary cords, top cords, etc.

2.Summary Charts:

Code
# Initialize plotly
import plotly
plotly.offline.init_notebook_mode(connected = False);

# Read in the Fieldmark and its associated dataframe and match dictionary
from fieldmark_khipu_summary import FieldmarkMeanCordsPerGroup
aFieldmark = FieldmarkMeanCordsPerGroup()
fieldmark_dataframe = aFieldmark.dataframes[0].dataframe
raw_match_dict = aFieldmark.raw_match_dict()
Code
import plotly.express as px
# Plot Matching khipu
matching_khipus = aFieldmark.matching_khipus() 
matching_values = [raw_match_dict[aKhipuName] for aKhipuName in matching_khipus]
matching_df =  pd.DataFrame(list(zip(matching_khipus, matching_values)), columns =['KhipuName', 'Value'])
fig = px.bar(matching_df, x='KhipuName', y='Value', labels={"KhipuName": "Khipu Name", "Value": "Mean Number of Cords Per Group", }, 
            title=f"Matching Khipu for Mean Number of Cords Per Group",  width=944, height=450).update_layout(showlegend=True).show()
Code
import pandas as pd
import utils_khipu as ukhipu

# Plot Significant khipu
significant_khipus = aFieldmark.significant_khipus()
significant_values = [raw_match_dict[aKhipuName] for aKhipuName in significant_khipus]
significant_df =  pd.DataFrame(list(zip(significant_khipus, significant_values)), columns =['KhipuName', 'Value'])
fig = px.bar(significant_df, x='KhipuName', y='Value', labels={"KhipuName": "Khipu Name", "Value": "Mean Number of Cords Per Group", },
             title=f"Significant Khipu  {ukhipu.pct_kfg_khipus(len(significant_khipus))}  for Mean Number of Cords Per Group", width=944, height=450).update_layout(showlegend=True).show()

3. Exploratory Data Analysis

The smoothness of the graph is perplexing. Despite the mean doing some artificial smoothing, one would expect a stair step function, not a smooth looking curve. Especially with low numbers of cords per group. Another way to measure might be the mode rather than the mean. Let’s do that.

Code
# Khipu Imports
import qollqa_chuspa as qc
from statistics import mode, mean
# Load khipus
khipu_dict, all_khipus = qc.fetch_khipus()

mode_cords_per_group = []
for aKhipu in all_khipus:
    cords_per_group = [aGroup.num_all_cords() for aGroup in aKhipu[:]]
    try:
        mode = mode(cords_per_group) if len(cords_per_group) > 0 else 0
    except:
        mode = round(mean(cords_per_group)) if len(cords_per_group) > 0 else 0
    mode_cords_per_group.append((aKhipu.name(), mode))
sorted_modes = sorted(mode_cords_per_group, key=lambda x: x[1], reverse=True)
mode_cords_per_group_df =  pd.DataFrame(sorted_modes, columns =['KhipuName', 'mode_cords_per_group'])
Code
fig = px.bar(mode_cords_per_group_df, x='KhipuName', y='mode_cords_per_group', labels={"KhipuName": "Khipu Name", "Value": "Mode Number of Cords Per Group", },
             title="Khipu for Mode Number of Cords Per Group", width=944, height=450).update_layout(showlegend=True).show()

This seems more reasonable and expected.