def mca(X, N=2):
    "对应分析函数，暂时支持双因素\n    X：观察频数表\n    N：返回的维数，默认2维\n    可以通过scatter函数绘制：\n    fig=scatter([pr,pc])\n    fig.savefig('mca.png')\n    "
    from scipy.linalg import diagsvd
    S = X.sum().sum()
    Z = (X / S)
    r = Z.sum(axis=1)
    c = Z.sum()
    D_r = np.diag((1 / np.sqrt(r)))
    Z_c = (Z - np.outer(r, c))
    D_c = np.diag((1 / np.sqrt(c)))
    (P, s, Q) = np.linalg.svd(np.dot(np.dot(D_r, Z_c), D_c))
    pr = np.dot(np.dot(D_r, P), diagsvd(s[:N], P.shape[0], N))
    pc = np.dot(np.dot(D_c, Q.T), diagsvd(s[:N], Q.shape[0], N))
    inertia = (np.cumsum((s ** 2)) / np.sum((s ** 2)))
    inertia = inertia.tolist()
    if isinstance(X, pd.DataFrame):
        pr = pd.DataFrame(pr, index=X.index, columns=list('XYZUVW')[:N])
        pc = pd.DataFrame(pc, index=X.columns, columns=list('XYZUVW')[:N])
    return (pr, pc, inertia)
    "\n    w=pd.ExcelWriter(u'mca_.xlsx')\n    pr.to_excel(w,startrow=0,index_label=True)\n    pc.to_excel(w,startrow=len(pr)+2,index_label=True)\n    w.save()\n    "
对应分析函数，暂时支持双因素
X：观察频数表
N：返回的维数，默认2维
可以通过scatter函数绘制：
fig=scatter([pr,pc])
fig.savefig('mca.png')
def mca(X, N=2):
    "对应分析函数，暂时支持双因素\n    X：观察频数表\n    N：返回的维数，默认2维\n    可以通过scatter函数绘制：\n    fig=scatter([pr,pc])\n    fig.savefig('mca.png')\n    "
    from scipy.linalg import diagsvd
    S = X.sum().sum()
    Z = (X / S)
    r = Z.sum(axis=1)
    c = Z.sum()
    D_r = np.diag((1 / np.sqrt(r)))
    Z_c = (Z - np.outer(r, c))
    D_c = np.diag((1 / np.sqrt(c)))
    (P, s, Q) = np.linalg.svd(np.dot(np.dot(D_r, Z_c), D_c))
    pr = np.dot(np.dot(D_r, P), diagsvd(s[:N], P.shape[0], N))
    pc = np.dot(np.dot(D_c, Q.T), diagsvd(s[:N], Q.shape[0], N))
    inertia = (np.cumsum((s ** 2)) / np.sum((s ** 2)))
    inertia = inertia.tolist()
    if isinstance(X, pd.DataFrame):
        pr = pd.DataFrame(pr, index=X.index, columns=list('XYZUVW')[:N])
        pc = pd.DataFrame(pc, index=X.columns, columns=list('XYZUVW')[:N])
    return (pr, pc, inertia)
    "\n    w=pd.ExcelWriter(u'mca_.xlsx')\n    pr.to_excel(w,startrow=0,index_label=True)\n    pc.to_excel(w,startrow=len(pr)+2,index_label=True)\n    w.save()\n    "