Bagging模型机器学习

问题描述 投票:0回答:1

我有以下代码行:

# Setting the values ​​for the number of folds

num_folds = 10
seed = 7

# Separating data into folds

kfold = KFold(num_folds, True, random_state = seed)

# Create the unit model (classificador fraco)

cart = DecisionTreeClassifier()

# Setting the number of trees

num_trees = 100

# Creating the bagging model

model = BaggingClassifier(base_estimator = cart, n_estimators = num_trees, random_state = seed)

# Cross Validation

resultado = cross_val_score(model, X, Y, cv = kfold)

# Result print

print("Acurácia: %.3f" % (resultado.mean() * 100))

这是我从互联网上获得的现成代码,很明显是预先定义的,用于测试我的交叉验证的TRAINING数据并了解装袋算法的准确性。

我想知道是否可以将其应用于我的TEST数据(无输出'Y'的数据)

代码有点混乱,我无法建模。

我正在寻找类似的东西:

# Training the model

model.fit(X, Y)

# Making predictions

Y_pred = model.predict(X_test)

我想在测试数据中的训练数据之上使用经过训练的装袋模型并进行预测,但我不知道如何修改代码

python scala machine-learning bigdata supervised-learning
1个回答
0
投票

您已经具备了预测新数据的一切能力。我提供了一个带有注释的小例子,以使其清楚。

© www.soinside.com 2019 - 2024. All rights reserved.