【问题标题】:TPOT: TPOTRegressor is showing Name ErrorTPOT:TPOTRegressor 显示名称错误
【发布时间】:2020-05-14 17:08:14
【问题描述】:

这是我正在运行的关于 TPOTRegressor 的代码。

from tpot import TPOTRegressor
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split

housing = sklearn.datasets.load_boston()
X_train, X_test, y_train, y_test = train_test_split(housing.data, housing.target,
                                                    train_size=0.75, test_size=0.25, random_state=42)

tpot = TPOTRegressor(generations=5, population_size=50, verbosity=2, random_state=42)
tpot.fit(X_train, y_train)
print(tpot.score(X_test, y_test))

现在我收到此错误:

NameError                                 Traceback (most recent call last)
<ipython-input-16-a52aaaaedc24> in <module>
      8 
      9 tpot = TPOTRegressor(generations=5, population_size=50, verbosity=2, random_state=42)
---> 10 tpot.fit(X_train, y_train)
     11 print(tpot.score(X_test, y_test))

~\anaconda3\lib\site-packages\tpot\base.py in fit(self, features, target, sample_weight, groups)
    637         features, target = self._check_dataset(features, target, sample_weight)
    638 
--> 639         self._init_pretest(features, target)
    640 
    641         # Randomly collect a subsample of training samples for pipeline optimization process.

~\anaconda3\lib\site-packages\tpot\tpot.py in _init_pretest(self, features, target)
     65 
     66         """
---> 67         self.pretest_X, _, self.pretest_y, _ = train_test_split(X, y, random_state=self.random_state,
     68                                                                 test_size=None, train_size=min(50,int(0.9*features.shape[0])))

NameError: name 'X' is not defined

由于某种原因,代码返回此 NameError 表示 X 未定义。

【问题讨论】:

    标签: scikit-learn python-3.7 nameerror train-test-split tpot


    【解决方案1】:

    我在 tpot v0.11.2 中遇到了同样的问题。卸载并重新安装到最新的 tpot v0.11.3 为我解决了这个问题。

    【讨论】:

      【解决方案2】:

      我遇到了这个确切的问题。代码中有一个很简单的bug,简单来说:

      • 打开日志中引用的tpot.py文件
      • 然后将TPOTRegressor中的X、y分别改为features、target
      • 保存更改,您应该一切顺利

      我的工作正常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-13
        • 1970-01-01
        • 1970-01-01
        • 2016-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多