问题描述
我正在处理 this dataset,其中包含 10 列。前两列是我的特征,其余是我的目标,它们可以单独放入模型中,因为它们彼此无关。因此,该问题可以作为正常的单目标回归处理。由于我需要用一个方程来描述我的输入和一些常数之间的关系,我的模型选择范围非常有限,我使用了一个最近开发的模型,称为 Equation Learner Network。
然而,我的主要问题是,尽管模型的损失非常低,例如 @Test
void maxUserException() {
int maxUsers = 5;
MaxUserException exception = new MaxUserException(maxUsers);
String message = "Excedido el número máximo de "+ maxUsers +" dispositivos";
TestUtils.testException(exception,message,ErrorCodes.MAX_USERS_DEVICES,403);
}
或有时 5e-05
在 10000 个时期后,其预测非常糟糕,如此 csv file 所示.然后,我尝试通过keras ANN来解决这个问题,但结果比之前的模型差。
预处理步骤:
2e-05
模型类:
data = np.genfromtxt('/content/drive/MyDrive/SAEdsdata/MainData.dat',skip_header = 1)
x = data[:,:2]
y = data[:,2:]
imp = SimpleImputer(missing_values = np.nan,strategy = 'mean')
imp.fit(x)
x = imp.transform(x)
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size = 0.2,random_state = 0)
mmsc_x = MinMaxScaler()
mmsc_z1 = MinMaxScaler()
mmsc_z2 = MinMaxScaler()
mmsc_z3 = MinMaxScaler()
mmsc_z4 = MinMaxScaler()
mmsc_z5 = MinMaxScaler()
mmsc_pred = MinMaxScaler()
x_trainfit = mmsc_x.fit_transform(x_train)
x_testfit = mmsc_x.transform(x_test)
#y_train = np.array(y_train,ndmin = 2)
#y_test = np.array(y_test,ndmin = 2)
#z in the third column
z1_train = y_train[:,0]
z1_train = z1_train.reshape(len(z1_train),1)
z1_trainfit = mmsc_z1.fit_transform(z1_train)
z1_test = y_test[:,0]
z1_test = z1_test.reshape(len(z1_test),1)
z1_testfit = mmsc_z1.transform(z1_test)
#z in the fourth column
z2_train = y_train[:,1]
z2_train = z2_train.reshape(len(z2_train),1)
z2_trainfit = mmsc_z2.fit_transform(z2_train)
z2_test = y_test[:,1]
z2_test = z2_test.reshape(len(z2_test),1)
z2_testfit = mmsc_z2.transform(z2_test)
#z in the eighth column
z3_train = y_train[:,5]
z3_train = z3_train.reshape(len(z3_train),1)
z3_trainfit = mmsc_z3.fit_transform(z3_train)
z3_test = y_test[:,5]
z3_test = z3_test.reshape(len(z3_test),1)
z3_testfit = mmsc_z3.transform(z3_test)
#z in the nineth column
z4_train = y_train[:,6]
z4_train = z4_train.reshape(len(z4_train),1)
z4_trainfit = mmsc_z4.fit_transform(z4_train)
z4_test = y_test[:,6]
z4_test = z4_test.reshape(len(z4_test),1)
z4_testfit = mmsc_z4.transform(z4_test)
#z in the tenth column
z5_train = y_train[:,7]
z5_train = z5_train.reshape(len(z5_train),1)
z5_trainfit = mmsc_z5.fit_transform(z5_train)
z5_test = y_test[:,7]
z5_test = z5_test.reshape(len(z5_test),1)
z5_testfit = mmsc_z5.transform(z5_test)
class EQLModel:
def __init__(self):
self.eqlModel = EQL()
self.z_pred = []
self.z_pred_inversed = []
def model_configuration_and_training(self,z,hidden_layers = 4,epoch = 5000,batch = 32,step_per_epoch = None):
self.eqlModel = EQL(hidden_layers,dim = 2)
self.eqlModel.build_and_compile_model()
self.eqlModel.fit(x_trainfit,lmbda = ['x','y'],t0 = epoch,batch_size = batch,shuffle = False,verbose = 1,steps_per_epoch = step_per_epoch)
def single_prediction(self,prediction_x):
predicted = self.eqlModel.predict(mmsc_x.transform(prediction_x))
predicted_value = mmsc_z1.inverse_transform(predicted.reshape(1,-1)).ravel()
print("{:.6e}".format(predicted_value[0]))
def test_set_prediction(self,z_test,z_scaler_class,z_testfit):
self.z_pred = self.eqlModel.predict(x_testfit)
self.z_pred_inversed = z_scaler_class.inverse_transform(self.z_pred.reshape(-1,1))
print('R2 score: {:.2f}'.format(r2_score(z_test,self.z_pred_inversed)))
mse = mean_squared_error(z_testfit,self.z_pred)
print('RMSE: {:.2f}'.format(mse))
def make_csv(self,name,z_testfit):
with open(name + '.csv','w',newline = '') as f:
thewriter = csv.writer(f)
thewriter.writerow(['x','y','z','actual z with inversing','our inversed predictions','z without inversing','our predictions without invesing','error percentage'])
for i in range(len(x_test)):
ws_x = '{:.6e}'.format(x_test[i][0])
ws_y = '{:.6e}'.format(x_test[i][1])
ws_z = '{:.6e}'.format(z_test[i][0])
z_with_i_array = z_scaler_class.inverse_transform(z_testfit)
z_with_i = '{:.6e}'.format(z_with_i_array[i][0])
zp_with_i = '{:.6e}'.format(self.z_pred_inversed[i][0])
z_without_i = '{:.6e}'.format(z_testfit[i][0])
zp_without_i = '{:.6e}'.format(self.z_pred[i][0])
error = '{:.2f}'.format(np.abs(np.abs(z_test[i][0] - self.z_pred_inversed[i][0]) / z_test[i][0] * 100))
thewriter.writerow([ws_x,ws_y,ws_z,z_with_i,zp_with_i,z_without_i,zp_without_i,error])
def evaluate_model(self,plot = True,batch = 32):
history = self.eqlModel.evaluate(x_trainfit,verbose = 1)
print(history)
#if plot:
eqlm = EQLModel()
人工神经网络配置:
eqlm.model_configuration_and_training(z = z1_trainfit,hidden_layers = 5,batch = 512,epoch = 10000)
eqlm.single_prediction([[1.357238e+00,1.614171e+04]])
eqlm.test_set_prediction(z1_test,mmsc_z1,z1_testfit)
eqlm.make_csv(name = 'z1perf',z_test = z1_test,z_scaler_class = mmsc_z1,z_testfit = z1_testfit)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)