我正在使用 xgboost python 来执行文本分类
下面是我正在考虑的火车
itemid description category
11802974 SPRO VUH3C1 DIFFUSER VUH1 TRIPLE Space heaters Architectural Diffusers
10688548 ANTIQUE BRONZE FINISH PUSHBUTTON switch Door Bell Pushbuttons
9836436 Descente pour Cable tray fitting and accessories Tray Cable Drop Outs
我正在使用 Sckit learn 的 counvectorizer 构建描述的文档术语矩阵,它使用下面的代码生成 scipy 矩阵(因为我有 110 万的大量数据,我正在使用稀疏表示来降低空间复杂度)
countvec = CountVectorizer()
documenttermmatrix=countvec.fit_transform(trainset['description'])
之后,我将使用上述矩阵应用特征选择
fs = feature_selection.SelectPercentile(feature_selection.chi2, percentile=40)
documenttermmatrix_train= fs.fit_transform(documenttermmatrix,y1_train)
我正在使用 xgboost 分类器来训练模型
model = XGBClassifier(silent=False)
model.fit(documenttermmatrix_train, y_train,verbose=True)
以下是我正在考虑的测试集
itemid description category
9836442 TRIPLE Space heaters Architectural Diffusers
13863918 pushbutton switch Door Bell Pushbuttons
我正在为测试集构建单独的矩阵,就像我使用下面的代码为训练集做的那样
documenttermmatrix_test=countvec.fit_transform(testset['description'])
虽然预测测试集 Xgboost 期望训练集的所有特征都在测试集中,但这是不可能的(稀疏矩阵仅表示非零条目)
我无法将训练集和测试集组合成单个数据集,因为我只需要为训练集进行特征选择
谁能告诉我如何进一步接近?