def train(self, X: np.ndarray, Y: np.ndarray, **kwargs):
"""Trains the EPM on X and Y.
Parameters
----------
X : np.ndarray [n_samples, n_features (config + instance features)]
Input data points.
Y : np.ndarray [n_samples, n_objectives]
The corresponding target values. n_objectives must match the
number of target names specified in the constructor.
Returns
-------
self : AbstractEPM
"""
self.n_params = X.shape[1] - self.n_feats
# reduce dimensionality of features of larger than PCA_DIM
if self.pca and X.shape[0] > 1:
X_feats = X[:, -self.n_feats:]
# scale features
X_feats = self.scaler.fit_transform(X_feats)
X_feats = np.nan_to_num(X_feats) # if features with max == min
# PCA
X_feats = self.pca.fit_transform(X_feats)
X = np.hstack((X[:, :self.n_params], X_feats))
if hasattr(self, "types"):
# for RF, adapt types list
# if X_feats.shape[0] < self.pca, X_feats.shape[1] ==
# X_feats.shape[0]
self.types = np.array(np.hstack((self.types[:self.n_params], np.zeros((X_feats.shape[1])))),
dtype=np.uint)
return self._train(X, Y)
评论列表
文章目录