def transform(self, x, center=True, rescale=True, ddof=0): # XX: this forces all inputs to double-precision real, even if the # input is single- or extended-precision or complex. But I got all # tangled up in knots trying to do that without breaking something # else (e.g. by requiring an extra copy). x = asarray_or_pandas(x, copy=True, dtype=float) x_2d = atleast_2d_column_default(x, preserve_pandas=True) if center: x_2d -= self.current_mean if rescale: x_2d /= np.sqrt(self.current_M2 / (self.current_n - ddof)) return pandas_friendly_reshape(x_2d, x.shape)
def __init__(self, int_array, levels, contrast=None): self.int_array = asarray_or_pandas(int_array, dtype=int) if self.int_array.ndim != 1: if self.int_array.ndim == 2 and self.int_array.shape[1] == 1: new_shape = (self.int_array.shape[0],) self.int_array = pandas_friendly_reshape(self.int_array, new_shape) else: raise PatsyError("Categorical data must be 1 dimensional " "or column vector") self.levels = tuple(levels) self.contrast = contrast
def transform(self, x): x = asarray_or_pandas(x) # This doesn't copy data unless our input is a DataFrame that has # heterogenous types. And in that case we're going to be munging the # types anyway, so copying isn't a big deal. x_arr = np.asarray(x) if np.issubdtype(x_arr.dtype, np.integer): dt = float else: dt = x_arr.dtype mean_val = np.asarray(self._sum / self._count, dtype=dt) centered = atleast_2d_column_default(x, preserve_pandas=True) - mean_val return pandas_friendly_reshape(centered, x.shape)
def transform(self, x): x = asarray_or_pandas(x) # This doesn't copy data unless our input is a DataFrame that has # heterogeneous types. And in that case we're going to be munging the # types anyway, so copying isn't a big deal. x_arr = np.asarray(x) if safe_issubdtype(x_arr.dtype, np.integer): dt = float else: dt = x_arr.dtype mean_val = np.asarray(self._sum / self._count, dtype=dt) centered = atleast_2d_column_default(x, preserve_pandas=True) - mean_val return pandas_friendly_reshape(centered, x.shape)