首页 > 解决方案 > XGBClassifier 对测试数据提供 100% 的准确度?

问题描述

我正在尝试使用 NASA 数据集制作一个模型来预测小行星的危险性。数据集本身没有任何空值。在消除了诸如 id 之类的不相关特征之后,我只有几个分类列是日期时间。所以我以这种方式将数据拆分为 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(我有类似的结果),但我在这里的一篇文章中读到它是不正确的,因为日期时间特征的有序性质。

我将在我的 github 存储库中留下完整代码的链接:NASA 小行星分类模型

标签: pythonmachine-learningxgboost

解决方案


推荐阅读