我正在制作一个模型,用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存储库中保留指向完整代码的链接:NASA Asteroids Classification Model
目前没有回答
相关问题 更多 >
编程相关推荐