<jupyter_start><jupyter_text>Table of Contents<jupyter_code>import pandas as pd
import numpy as np
from sklearn.decomposition import FactorAnalysis
from sklearn.externals import joblib
loc_container = joblib.load('../../bld/out/data/loc_container.pkl')
container = joblib.load('../../bld/out/data/model_pca_two_comp.pkl')
pca = container['model'].named_steps['pca']
loc_container['cronbachs_alpha']
container['loadings']
container['loadings']
PERCEIVED_CONTROL = ['LOC_LIFES_COURSE', 'LOC_ACHIEVED_DESERVE', 'LOC_LUCK',
                     'LOC_OTHERS', 'LOC_DOUBT', 'LOC_POSSIBILITIES',
                     'LOC_LITTLE_CONTROL']

def calculate_cronbachs_alpha(itemscores):
    itemscores = np.asarray(itemscores)
    itemvars = itemscores.var(axis=1, ddof=1)
    tscores = itemscores.sum(axis=0)
    nitems = len(itemscores)

    return nitems / (nitems-1.) * (1 - itemvars.sum() / tscores.var(ddof=1))
calculate_cronbachs_alpha(df[PERCEIVED_CONTROL].T.values)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13494461228600202, 'fraction_numerical': 0.006042296072507553, 'mean_word_length': 4.9879518072289155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '407928', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 380, 'n_tokens_neox': 358, 'n_words': 53, 'path': 'src/exploration/explore_pca.ipynb', 'repo_name': 'tobiasraabe/locus-of-control', 'size': '993'}