Skip to content

Commit

Permalink
1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochaoroulalala committed Nov 23, 2023
1 parent 7eb1a6a commit 14b4e49
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
16 changes: 15 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,18 @@

使用网格搜索提供最优参数

效果图:![效果图](./img/mn1.jpg)
效果图:

![效果图](./img/mn1.jpg)

1.3:(苏沛泽)提交第四个版本,

考虑将多个模型融合,利用Stacking堆叠法,将两层算法进行串联。

在第一层中首先将多层感知机模型、逻辑斯特模型、决策树模型、随机森林模型、梯度提升回归树模型作为基础模型进行训练。

训练完后进行预测,得到预测结果后,将其预测结果转成二维矩阵作为一组新的特征交由第二层元学习器进行训练。

元学习器这里采用毛南设计好的adaboost分类器,通过将第一层基础模型的预测结果作为新的特征矩阵进行训练。

融合模型最终输出的预测结果就是元学习器输出的结果。
19 changes: 18 additions & 1 deletion yugou_theoryBest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@
user_info['age_range'].replace(np.nan, -1, inplace=True)
user_info['gender'].replace(np.nan, -1, inplace=True)

# 检查缺失值
user_info['gender'].replace(2.0, np.nan, inplace=True)
missing_values = user_info.isnull().sum()
print("缺失值统计:")
print(missing_values)

missing_values = user_log.isnull().sum();
print(missing_values)

user_log = user_log.fillna(method='ffill')

# 缺失值处理:使用众数填充
user_info['gender'].replace(2.0, np.nan, inplace=True)
user_info['age_range'].replace(0.0, np.nan, inplace=True)
user_info.fillna(user_info.mode(), inplace=True)

# 聚合特征
seller_group = user_log.groupby(["seller_id", "action_type"]).count()[["user_id"]].reset_index().rename(
columns={'user_id': 'count'})
Expand Down Expand Up @@ -92,7 +108,7 @@
# 模型构建与调参
Y = df_train['label']
X = df_train.drop(['user_id', 'merchant_id', 'label'], axis=1)
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.25, random_state=10)
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.20, random_state=10)

from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier, AdaBoostClassifier

Expand Down Expand Up @@ -158,4 +174,5 @@
stacking_predictions = meta_model.predict(stacking_features)

accuracy = accuracy_score(y_test, stacking_predictions)
print(stacking_predictions[:])
print(f"Accuracy of Stacking Model on test set: {accuracy:.8f}")

0 comments on commit 14b4e49

Please sign in to comment.