Reputation: 91
I would like to plot a graph using python showing variables on X/Y axis after applying MCA. I tried this code but returns the following error:
AttributeError: 'DataFrame' object has no attribute 'plot_coordinates'
This is the code:
ax = mca.plot_coordinates(
X=X,
ax=None,
figsize=(6, 6),
show_row_points=True,
row_points_size=10,
show_row_labels=False,
show_column_points=True,
column_points_size=30,
show_column_labels=False,
legend_n_cols=1)
Can anyone help please?
Thanks,
Upvotes: 1
Views: 3053
Reputation: 11
mca = prince.MCA()
typeof mca is prince.mca.MCA ,it has the method . if you add the code,
mca = mca.fit(X) # same as calling ca.fs_r(1)
mca = mca.transform(X)
type of mca is DataFrame.it do not have the method plot_coordinates. The right code:
import pandas as pd
import prince
X = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/balloons/adult+stretch.data')
X.columns = ['Color', 'Size', 'Action', 'Age', 'Inflated']
print(X.head())
mca = prince.MCA()
mca = mca.fit(X) # same as calling ca.fs_r(1)
mca1 = mca.transform(X) # same as calling ca.fs_r_sup(df_new) for *another* test set.
print(mca1)
ax = mca.plot_coordinates(
X=X,
ax=None,
figsize=(6, 6),
show_row_points=True,
row_points_size=10,
show_row_labels=False,
show_column_points=True,
column_points_size=30,
show_column_labels=False,
legend_n_cols=1
)
ax.get_figure().savefig('./mca_coordinates.svg')
Upvotes: 1
Reputation: 16
I don't know if this helps but I ran into that same error. To fix it, I specified the X= to be the exact dataframe and columns/variables and it fixed the problem: X=train[variables] instead of X=X
ax = mca.plot_coordinates(
X=train[variables],
ax=None,
figsize=(6, 6),
show_row_points=True,
row_points_size=10,
show_row_labels=False,
show_column_points=True,
column_points_size=30,
show_column_labels=False,
legend_n_cols=1)
Upvotes: 0