def _validate_X(X):
    """Returns X if X isn't a pandas frame, otherwise 
    the underlying matrix in the frame. """
return X if not isinstance(X, pd.DataFrame) else X.as_matrix()

def _validate_y(y):
    """Returns y if y isn't a series, otherwise the array"""
if y is None:
    return y
elif isinstance(y, pd.Series):
    return np.array(y.tolist())
elif isinstance(y, pd.DataFrame):
    if y.shape[1] > 1:
        raise ValueError('matrix provided as y')
return y[y.columns[0]].tolist()
return y
How do I make GridSeachCV work with a custom transformer in my pipeline?