Obtaining Multiple Correspondence Analysis (MCA) Plot in Python Using Prince Package

Question:

I am trying to plot a 2D MCA plot in Python. I am trying to replicate the tutorial found in the Prince Github Repository https://github.com/MaxHalford/prince

I currently have the following working:

import pandas as pd

X = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/balloons/adult+stretch.data')
X.columns = ['Color', 'Size', 'Action', 'Age', 'Inflated']

mca = prince.MCA(X,n_components=2)

However, when I run the plot command, I receive the following error even though there is a plot_coordinates function in the package.

mca.plot_coordinates(X = X)
AttributeError: 'MCA' object has no attribute 'plot_coordinates'

Any assistance to rectify this matter would be appreciated. Thank you.

Asked By: rtob

||

Answers:

You would need first initiate the MCA object and fit it with data to use plot_coordinates function.

X = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/balloons/adult+stretch.data')
X.columns = ['Color', 'Size', 'Action', 'Age', 'Inflated']
fig, ax = plt.subplots()
mc = prince.MCA(n_components=2).fit(X)
mc.plot_coordinates(X=X, ax=ax)
ax.set_xlabel('Component 1', fontsize=16)
ax.set_ylabel('Component 2', fontsize=16)

enter image description here

Answered By: user3563929

The problem is that for the new versions, there’s no "plot_coordinates". I’ve lost few hours to discover that you need to use "plot". Find here the documentation.
Example:

mca = prince.MCA(n_components = 2)
mca = mca.fit(df[cols_list])
ax = mca.plot(df[cols_list])
ax
Answered By: ruben
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.