【问题标题】:TPOTClassifier producing errorsTPOTClassifier 产生错误
【发布时间】:2017-04-11 08:10:39
【问题描述】:

我试图在Forest Cover Type Prediction 上使用TPOTClassifier。 但是在初始运行之后,它会产生错误作为输出。如果 您建议如何解决该错误。谢谢。

from tpot import TPOTClassifier
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

# loading the data
data = pd.read_csv("train.csv")
data_test = pd.read_csv("test.csv")
data.head()
data_test.head()

print data['Cover_Type'].values
data1 = data

data1= data1.rename(columns={'Cover_Type':'class'})
data1.dtypes

features =list(data1.dtypes[1:55].index)
target =list(data1.dtypes[55:56].index)
print data1.dtypes.tail()

## train test split
X_train , X_test, y_train, y_test = train_test_split(data1[features],data1[target],train_size=0.75, test_size=0.25)
X_train.head()

tpot =TPOTClassifier(generations=5, population_size=500, verbosity=2)       
tpot.fit(X_train, y_train)
print (tpot.score(X_test, y_test))
tpot.export('tpot_forest_pipeline.py')

但它会产生错误:

第 1 代 - 当前最佳内部 CV 分数:inf

第 2 代 - 当前最佳内部 CV 分数:inf

第 3 代 - 当前最佳内部 CV 分数:inf

第 4 代 - 当前最佳内部 CV 分数:inf

第 5 代 - 当前最佳内部 CV 分数:inf

ValueError Traceback(最近一次调用最后一次) 在 ()

1 tpot =TPOTClassifier(generations=5, population_size=500, verbosity=2)

2 tpot.fit(X_train, y_train)

3 打印 (tpot.score(X_test, y_test))

4 tpot.export('tpot_forest_pipeline.py'

如果不是 self._optimized_pipeline,则为 355:

356 raise ValueError(TPOT优化出现错误

357 进程。这可能是因为数据是 358 格式不正确,或者因为)ValueError的数据:TPOT优化过程中出现错误。这可能是因为数据格式不正确,或者因为回归问题的数据提供给了TPOTClassifier对象。请确保您正确地将数据传递给 TPOT。

【问题讨论】:

    标签: python-2.7 python-3.x anaconda genetic-algorithm genetic-programming


    【解决方案1】:

    问题是由 data1[features] 引起的,它应该是一维数组,但 pandas 数据帧是二维数组类数据结构。更改 tpot.fit() 代码如下将解决输入问题。

    tpot.fit(pd.np.array(X_train), pd.np.array(y_train).ravel())
    

    【讨论】:

    • 感谢您的回复。我已按照您的建议进行了更改。它显示了几代人。然后它显示 Best pipeline: ExtraTreesClassifier(SelectFromModel(input_matrix, 1.0000000000000001e-05, 60, 0.080000000000000002), 6, 0.63) 之后,导出到 tpot.export('tpot_forest_pipeline.py') 时出错
    • 如何解读最佳管道显示中的参数?如何解决通过 tpot.export('tpot_forest_pipeline.py') 导出时最后出现的错误
    猜你喜欢
    • 2013-07-30
    • 2016-08-10
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 2017-06-04
    • 2021-04-04
    相关资源
    最近更新 更多