Question: Hello, I am getting an error when trying to execute the following problem and code. In PYTHON and PANDAS cramers_v function Q 14 (.5 points)
Hello, I am getting an error when trying to execute the following problem and code.
In PYTHON and PANDAS

cramers_v function

Q 14 (.5 points) Using pandas cross tabulate Survived and Title in titanic_df_small. Also compute cramers_v for association between Survived and Title. In [27]: 1 from IPython.display import display 2 3 ct = pd.crosstab(index=titanic_df_small('Title'], columns=titanic_df_small('Survived']) 4 5 display(ct) 6 7 ct.apply(cramers_v) Survived 0 1 Title Master. 17 23 Miss. 55 126 Mr. 436 81 Mrs. 26 98 : 1 def cramers_v(confusion_matrix) : 2 "' calculate Cramers V statistic for categorial-categorial association. 3 uses correction from Bergsma and Wicher, 4 Journal of the Korean Statistical Society 42 (2013): 323-328 5 6 chi2 = ss.chi2_contingency(confusion_matrix)[0] 7 n = confusion_matrix.sum() 8 phi2 = chi2 / n 9 r, k = confusion_matrix.shape 10 phi2corr = max(0, phi2 - ((k-1)*(r-1))/(n-1)) 11 rcorr = r - ((r-1)**2)/(n-1) 12 kcorr = k - ((k-1)**2)/(n-1) 13 return np.sqrt(phi2corr / min((kcorr-1), (rcorr-1)))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
