TypeError: 'Data argument can't be an iterator...'

TypeError: 'Data argument can't be an iterator...'

我正在尝试使用 zip 函数将列名组合在一起,并使用 np.transpose 函数将我创建的 log_model 的系数组合在一起。

我的代码:

# Create LogisticRegression model object
log_model = LogisticRegression()

# Fit our data into that object
log_model.fit(X,Y)

# Check your accuracy
log_model.score(X,Y)

这段代码工作得很好,因为我能够检查我的模型的准确性。 但是,以下代码是我出错的地方。

错误代码:

coeff_df = DataFrame(zip(X.columns,np.transpose(log_model.coef_)))

错误信息:

TypeError                                 Traceback (most recent call last)
<ipython-input-147-a4e0ad234518> in <module>()
      1 # Use zip to bring the column names and the np.transpose function to bring together the coefficients from the model
----> 2 coeff_df = DataFrame(zip(X.columns,np.transpose(log_model.coef_)))

~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    387                 mgr = self._init_dict({}, index, columns, dtype=dtype)
    388         elif isinstance(data, collections.Iterator):
--> 389             raise TypeError("data argument can't be an iterator")
    390         else:
    391             try:

TypeError: data argument can't be an iterator

我做错了什么?抱歉,这里是新手。我正在使用 Python 教程关注 Udemy 数据可视化。我的讲师正在使用 Python 2,但我已经能够使用 Python 3 进行管理,只是进行和研究转换以确保我的代码仍然有效。任何建议将不胜感激。

对于二进制class化,只使用一个线性模型。在多标签class化的情况下,每个class都会有一个线性模型。假设你的X是pd.DataFrame,你可以进行如下操作:

output = pd.DataFrame(my_model.coef_, columns=X.columns)

行代表不同 classes 的线性模型,列代表系数。