我需要从prince软件包中运行多个对应分析,但它似乎已损坏

2024-04-28 12:33:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用the prince package的MCA,但它无法运行文档中显示的测试示例:

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(n_iter=3, copy=True, check_input=True, engine='auto', random_state=42)
mca = mca.fit(X)


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)

只需复制粘贴并尝试运行它,就会抛出:

/home/user/anaconda3/envs/python38/lib/python3.8/site-packages/prince/one_hot.py:31: FutureWarning: The SparseDataFrame class is removed from pandas. Accessing it from the top-level namespace will also be removed in the next version
  return pd.SparseDataFrame(

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-6fd265f4e0f4> in <module>
      3 
      4 mca = prince.MCA(n_iter=3, copy=True, check_input=True, engine='auto', random_state=42)
----> 5 mca = mca.fit(X)
      6 
      7 

~/anaconda3/envs/python38/lib/python3.8/site-packages/prince/mca.py in fit(self, X, y)
     26 
     27         # Apply CA to the indicator matrix
---> 28         super().fit(self.one_hot_.transform(X))
     29 
     30         # Compute the total inertia

~/anaconda3/envs/python38/lib/python3.8/site-packages/prince/one_hot.py in transform(self, X)
     29 
     30     def transform(self, X):
---> 31         return pd.SparseDataFrame(
     32             data=super().transform(X),
     33             columns=self.column_names_,

TypeError: SparseDataFrame() takes no arguments

你知道我需要在什么地方做些什么才能让它工作吗?我迫切需要做的阴谋,我还没有找到另一个包,可以做到这一点


Tags: theinselftrueinputshowtransformcolumn
1条回答
网友
1楼 · 发布于 2024-04-28 12:33:56

我刚刚第一次尝试使用prince包,但在重新安装anaconda python 3.7和最新的prince/numpy/pandas/scikit_learn堆栈时,运行自述文件中的示例时遇到了相同的错误。在prince中使用不推荐的pandas类SparseDataFrame似乎是一个问题。有一个悬而未决的问题。解决办法是降级到pandas-0.24.2

pip install pandas==0.24.2

这使它起作用

相关问题 更多 >