可以将 cross_val_score() 形式的 sklearn 应用于具有 Weigth Elimination 等插件的 neupy NN?
It´s possible to apply cross_val_score() form sklearn to neupy NN that has an addon like Weigth Elimination?
我正在尝试将 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() 工作正常...还有其他方法吗?谢谢
看起来函数 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))
我正在尝试将 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() 工作正常...还有其他方法吗?谢谢
看起来函数 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))