'DataFrame'对象不可调用

时间:2017-04-21 11:42:52

标签: python

我想使用sklearn的RFECV功能,我收到此错误:

    TypeError                                 Traceback (most recent call last)
<ipython-input-12-861c92e9f285> in <module>()
      9 # Build a classification task using 3 informative features
     10 X, y = df(n_samples=90, n_features=24, n_informative=5,
---> 11                      n_repeated=0, random_state=0)
     12 
     13 # Create the RFE object and compute a cross-validated score.

TypeError: 'DataFrame' object is not callable

我的代码是:

df = pd.read_csv('.../Regression data file.csv')
X_sk = df[[col for col in df.columns if col[:8] == 'ECA_AASK']]
Y = df[['ECA{}'.format(ii) for ii in range(1, 19)]]
y = np.mean(Y, axis=1)

print(__doc__)

import matplotlib.pyplot as plt
from sklearn.svm import SVC
from sklearn.model_selection import StratifiedKFold
from sklearn.feature_selection import RFECV
#from sklearn.datasets import make_classification


# Build a classification task using 3 informative features
X, y = df(n_samples=90, n_features=24, n_informative=5,
                     n_repeated=0, random_state=0)

# Create the RFE object and compute a cross-validated score.
svc = SVC(kernel="linear")
# The "accuracy" scoring is proportional to the number of correct
# classifications
rfecv = RFECV(estimator=svc, step=1, cv=StratifiedKFold(5),
              scoring='accuracy')
rfecv.fit(X, y)

print("Optimal number of features : %d" % rfecv.n_features_)

# Plot number of features VS. cross-validation scores
plt.figure()
plt.xlabel("Number of features selected")
plt.ylabel("Cross validation score (nb of correct classifications)")
plt.plot(range(1, len(rfecv.grid_scores_) + 1), rfecv.grid_scores_)
plt.show()

我是python的新手,我正在尝试使用Python中的ctross验证进行向后逐步回归。感谢

0 个答案:

没有答案