1.对数据进行归一化
(1)api方式
from sklearn.preprocessing import MinMaxScaler
scaler1 = MinMaxScaler()
scaler1.fit(y_data)
scaler1.data_max_
y_data = scaler1.transform(y_data)
(2)函数方式
def normalize(X):
mean = np.mean(X)
std = np.std(X)
X = (X-mean)/std
return np.array(X)
需要注意的是在函数方式中如果X过大需要检验是否被全部归一化为了0
2.tensorflow2.0版本如果需要使用1.0
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
3.对数据网格化
X,Y = np.meshgrid(glon,glat)
gon和glat是整数,如50,30
4.如果loss降不下去
(1)考虑调整学习率
(2)考虑是否过拟合
(3)调整激活函数及隐藏层
5.对原始数据划分训练集和测试集
from sklearn.model_selection import train_test_split
x_data,x_test,y_data,y_test = train_test_split(ind_data,ind_ele,test_size=.3)
ind_data是特征向量,ind_ele是标签,按照0.3的比例划分
6.消除原始数据中的一些离群点,如nan和inf,同时打乱数据顺序
# 如果是数字则返回True,否则返回Flase,nan和inf会返回False
inf_ind = np.isfinite(ind_ele).squeeze()
ind_data = ind_data[inf_ind]
# 打乱
shuffle_index = np.random.permutation(np.shape(x_data)[0])
y_data = y_data[shuffle_index]
x_data = x_data[shuffle_index,:]
注意特征向量和标签要同时打乱