python - 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 小行星分类模型
解决方案
推荐阅读
- google-sheets - 在 Google 表格中,如何根据 ID 获取行中逗号分隔值的总和
- python - 如何将 pypy 与 Django 以及 postgresql 后端一起使用?
- c# - 实体框架中错误的列名奇怪问题
- javascript - 在 React 中发布没有表单或按钮的请求?
- c# - 如何在 WPF 用户控件中使用 WndProc?
- javascript - 垂直滚动行可以同时包含普通元素和水平滚动元素吗?
- node.js - 如何用 sinon/mocha 模拟 npm 模块
- c - 通过 argv 操作进程名称和参数
- serialization - 序列化数据库中的数据
- django - Django注释:最大异物的总和