0

我正在尝试将 cross_val_score() 应用于以下算法:

cgnet = algorithms.LevenbergMarquardt(
    connection=[
        layers.Input(XTrain.shape[1]),
        layers.Linear(6),
        layers.Linear(1)],
        mu_update_factor=2,
        mu=0.1,
        shuffle_data=True,
        verbose=True,
        decay_rate=0.1,
        addons=[algorithms.WeightElimination])

kfold = KFold(n_splits=5, shuffle=True, random_state=7)
scores=cross_val_score(cgnet, XTrainScaled,yTrainScaled,scoring='neg_mean_absolute_error',cv=kfold,verbose=10)
print scores
print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2))

这是我收到的错误消息:

TypeError: Cannot create a consistent method resolution
order (MRO) for bases LevenbergMarquardtWeightElimination, WeightElimination

没有 WeightElimination 或任何其他插件,cross_val_score() 可以正常工作……还有其他方法吗?谢谢

4

1 回答 1

2

看起来函数cross_val_score在 neupy 中不起作用,但您可以以稍微不同的方式运行相同的代码。

import numpy as np
from neupy import algorithms, layers
from sklearn.model_selection import *
from sklearn import metrics

XTrainScaled = XTrain = np.random.random((10, 2))
yTrainScaled = np.random.random((10, 1))

kfold = KFold(n_splits=5, shuffle=True, random_state=7)
scores = []

for train, test in kfold.split(XTrainScaled):
    x_train, x_test = XTrainScaled[train], XTrainScaled[test]
    y_train, y_test = yTrainScaled[train], yTrainScaled[test]

    cgnet = algorithms.LevenbergMarquardt(
        connection=[
            layers.Input(XTrain.shape[1]),
            layers.Linear(6),
            layers.Linear(1)
        ],
        mu_update_factor=2,
        mu=0.1,
        shuffle_data=True,
        verbose=True,
        decay_rate=0.1,
        addons=[algorithms.WeightElimination]
    )

    cgnet.train(x_train, y_train, epochs=5)
    y_predicted = cgnet.predict(x_test)

    score = metrics.mean_absolute_error(y_test, y_predicted)
    scores.append(score)

print(scores)
scores = np.array(scores)
print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2))
于 2018-11-21T14:39:03.567 回答