Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python XGBClassifier提供100%的测试数据准确性?_Python_Machine Learning_Xgboost - Fatal编程技术网

Python XGBClassifier提供100%的测试数据准确性?

Python XGBClassifier提供100%的测试数据准确性?,python,machine-learning,xgboost,Python,Machine Learning,Xgboost,我正在制作一个模型,用NASA的数据集预测小行星的危险性。 数据集本身没有任何空值。在消除了不相关的特性(如ID)之后,我只有几个属于datetimes的分类列。所以我用这种方式将数据分成80列和20列: X_train, X_test= np.split(X, [int(.80 *len(X))]) y_train, y_test= np.split(y, [int(.80 *len(X))]) 然后,我制作了一个个性化的转换器来处理日期,为日、月和年创建了新列,并从数据中删除了原始日期功能

我正在制作一个模型,用NASA的数据集预测小行星的危险性。 数据集本身没有任何空值。在消除了不相关的特性(如ID)之后,我只有几个属于datetimes的分类列。所以我用这种方式将数据分成80列和20列:

X_train, X_test= np.split(X, [int(.80 *len(X))])
y_train, y_test= np.split(y, [int(.80 *len(X))])
然后,我制作了一个个性化的转换器来处理日期,为日、月和年创建了新列,并从数据中删除了原始日期功能:

from sklearn.base import BaseEstimator

class DateProcessor(BaseEstimator):

    def __init__(self):
        pass

    def fit(self, documents, y=None):
        return self

    def transform(self, df):
        dateCols = ['Close Approach Date', 'Orbit Determination Date']
        new_df = df.copy()
        for col in dateCols:
        
            new_df[col] = pd.to_datetime(new_df[col], errors="coerce",format="%Y-%m-%d")
            #df.dropna(axis=1, subset=['date'], inplace=True)
        
            newColsDict = {'day': str(col) + " day", 'month': str(col) + " month", 'year': str(col) + " year"}
            new_df[newColsDict['day']] = new_df[col].dt.day
            new_df[newColsDict['month']] = new_df[col].dt.month
            new_df[newColsDict['year']] = new_df[col].dt.year
        
        new_df.drop(inplace=True, columns=dateCols)
        return new_df
之后,我制作了一个管道来预处理数据,然后使用XGBClassifier对其进行训练:

estimator = XGBClassifier(learning_rate=0.1)
model_pipeline = Pipeline(steps=[
                                ('process_dates', DateProcessor()),
                                ('XGBoost', estimator)
                                ])
model_pipeline.fit(X_train, y_train)
训练结束后,我尝试的每一个得分指标都能给出100%的准确率。我对人工智能不是很有经验,但我认为测试数据的100%准确性通常表明存在问题? 我真的不知道是否存在某种数据泄漏、数据污染或类似的情况。 PD:我也尝试过使用普通的train_test_split(我有类似的结果),但我在这里的一篇文章中读到,这是不正确的,因为datetime特性的有序性


我将在github存储库中留下完整代码的链接:

欢迎使用SO。我认为错误与
列车测试分割
部分有关。尝试
train\u test\u split()
而不使用您创建的基于时间的功能。此外,您是否可以更新Github ipython笔记本,以在feature engineering之后显示数据集的
标题
和摘要统计信息。sklearn有一个专门针对以下内容的功能。您还应该检查您的功能和targeti之间的数据泄漏我在“实验”分支上所做的更改。我删除了基于时间的功能,使用了train\u test\u split,添加了
X\u train.head(10)
X\u train.info()
X\u train.description()
。我对测试数据仍然有100%的准确性。我还注意到,如果我不使用random_state,我每次都会得到不同的结果,从99.5%到100%考虑两件事:(1)如果你的数据集高度不平衡?(2) 在拆分之前对数据进行洗牌欢迎使用SO。我认为错误与
列车测试分割
部分有关。尝试
train\u test\u split()
而不使用您创建的基于时间的功能。此外,您是否可以更新Github ipython笔记本,以在feature engineering之后显示数据集的
标题
和摘要统计信息。sklearn有一个专门针对以下内容的功能。您还应该检查您的功能和targeti之间的数据泄漏我在“实验”分支上所做的更改。我删除了基于时间的功能,使用了train\u test\u split,添加了
X\u train.head(10)
X\u train.info()
X\u train.description()
。我对测试数据仍然有100%的准确性。我还注意到,如果我不使用random_state,我每次都会得到不同的结果,从99.5%到100%考虑两件事:(1)如果你的数据集高度不平衡?(2) 在分割之前先洗牌数据