我正在尝试使用这样的功能来扩展功能
def featureNormalize(X):
'''
This function takes the features as input and
returns the normalized values, the mean, as well
as the standard deviation for each feature.
'''
X_norm = (X - np.mean(X))/np.std(X)
mu = np.mean(X)
sigma = np.std(X)
return X_norm, mu, sigma
然后调用它
X, mean, std = featureNormalize(X) ## We call the function over the features
所以它适用于我的火车组。
但是当我将其称为测试集时],某些列完全变成了 Nan 两个集合都没有 Nan 或 null 值。我试图用nanmean
and重写这个函数nanstd
,但是没有用:
def featureNormalize(X):
X_norm = (X - np.nanmean(X, dtype = 'float32')) / np.nanstd(X, dtype = 'float32')
mu = np.nanmean(X, dtype = 'float32')
sigma = np.nanstd(X, dtype = 'float32')
return X_norm, mu, sigma
什么会导致这个问题,我该怎么办