Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

mca

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.

like image 489
rtob Avatar asked Mar 08 '26 17:03

rtob


1 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

like image 73
user3563929 Avatar answered Mar 11 '26 07:03

user3563929



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!