我可以预测角膜的反三角函数吗?

问题描述

首先,我生成2000个随机数作为x(作为输入,范围从-25到-27,然后y = cos(x)作为 标签以进入完整的连接层。该模型的损失函数如图所示, 在此处输入图片描述,我对结果感到满意。 然后,我交换X和y,y作为输入,X作为标签,并将它们输入到同一模型中。损失 功能如下图所示。无论训练集还是验证集, 性能很差。 我尝试了conv1d,但在训练集或验证集中都不好。 最后,我尝试了LSTM,结果在训练集上是好的,但在验证集上却很差。 问题是什么?我该如何解决?可以使用keras来预测逆三角函数吗?

import numpy as np
import tensorflow as tf
import tensorflow.keras as keras
from tensorflow.keras import layers
from pandas import DataFrame
import os    
from sklearn import metrics
from sklearn.model_selection import train_test_split
from tensorflow.keras.callbacks import EarlyStopping
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from keras.models import Sequential
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from keras.layers import Dense,LSTM,Dropout
from sklearn.preprocessing import MinMaxScaler   
import matplotlib.pyplot as plt

x=np.random.randn(2000,1)*8
print(x[0:10])
print(x.shape)
print('x.max',x.max())
print('x.min',x.min())

y = np.cos(x)
print('y.shape',y.shape)


x_train,x_test,y_train,y_test = train_test_split(y,x,test_size=0.3,random_state=42)
#x_train,y_test = train_test_split(x,y,random_state=42)
model = Sequential()
model.add(Dense(100,input_shape = (1,),activation='relu'))
model.add(Dense(50,activation='relu'))
model.add(Dense(1))
model.compile(loss='mean_squared_error',optimizer = 'adam')


history = model.fit(x_train,validation_data=(x_test,y_test),verbose=1,epochs=300)
pred = model.predict(x_test)    

history_dict = history.history
history_dict.keys()
loss = history_dict['loss']
val_loss = history_dict['val_loss']

epochs = range(1,len(loss) + 1)
plt.figure(2)
# "bo" is for "blue dot"
plt.plot(epochs,loss,'bo',label='Training loss')
# b is for "solid blue line"
plt.plot(epochs,val_loss,'b',label='Validation loss')
plt.title('Training and validation loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()

enter image description here

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...