hyppo/independence/_utils.py
def sim_matrix(model, x):
    """
    Computes the similarity matrix from a random forest.

    The model used must follow the scikit-learn API. That is, the model is a random
    forest class and is already trained (use :func:`fit`) before running this function.
    Also, :func:`apply` must be used to push input data down the trained forest. See
    :class:`sklearn.ensemble.RandomForestClassifier` and
    :class:`sklearn.ensemble.RandomForestRegressor` for similar classes.

    Parameters
    ----------
    model : class
        A trained random forest object for which the similarity matrix will be
        calculated.
    x : ndarray
        Input data matrice. ``x`` must have shape must be ``(n, p)`` where
        `n` is the number of samples and `p` are the number of
        dimensions.

    Returns
    -------
    proxMat : ndarray
        The proximity matrix induced by random kernel.
    """
    terminals = model.apply(x)
    ntrees = terminals.shape[1]

    prox_mat = sum(
        np.equal.outer(terminals[:, i], terminals[:, i]) for i in range(ntrees)
    )
    prox_mat = prox_mat / ntrees

    return prox_mat

    Computes the similarity matrix from a random forest.

    The model used must follow the scikit-learn API. That is, the model is a random
    forest class and is already trained (use :func:`fit`) before running this function.
    Also, :func:`apply` must be used to push input data down the trained forest. See
    :class:`sklearn.ensemble.RandomForestClassifier` and
    :class:`sklearn.ensemble.RandomForestRegressor` for similar classes.

    Parameters
    ----------
    model : class
        A trained random forest object for which the similarity matrix will be
        calculated.
    x : ndarray
        Input data matrice. ``x`` must have shape must be ``(n, p)`` where
        `n` is the number of samples and `p` are the number of
        dimensions.

    Returns
    -------
    proxMat : ndarray
        The proximity matrix induced by random kernel.
    
Computes the similarity matrix from a random forest.
The model used must follow the scikit-learn API. That is, the model is a random
forest class and is already trained (use :func:`fit`) before running this function.
Also, :func:`apply` must be used to push input data down the trained forest. See
Computes the similarity matrix from a random forest . The model used must follow the scikit - learn API . That is the model is a random forest class and is already trained ( use : func : ` fit ` ) before running this function . Also : func : ` apply ` must be used to push input data down the trained forest . See
def sim_matrix(model, x):
    terminals = model.apply(x)
    ntrees = terminals.shape[1]
    prox_mat = sum(
        np.equal.outer(terminals[:, i], terminals[:, i]) for i in range(ntrees)
    )
    prox_mat = prox_mat / ntrees
    return prox_mat
def sim_matrix ( model , x ) : terminals = model . apply ( x ) ntrees = terminals . shape [ 1 ] prox_mat = sum ( np . equal . outer ( terminals [ : , i ] , terminals [ : , i ] ) for i in range ( ntrees ) ) prox_mat = prox_mat / ntrees return prox_mat
Computes the similarity matrix from a random forest.
Computes the similarity matrix from a random forest .
"""
    Computes the similarity matrix from a random forest.

    The model used must follow the scikit-learn API. That is, the model is a random
    forest class and is already trained (use :func:`fit`) before running this function.
    Also, :func:`apply` must be used to push input data down the trained forest. See
    :class:`sklearn.ensemble.RandomForestClassifier` and
    :class:`sklearn.ensemble.RandomForestRegressor` for similar classes.

    Parameters
    ----------
    model : class
        A trained random forest object for which the similarity matrix will be
        calculated.
    x : ndarray
        Input data matrice. ``x`` must have shape must be ``(n, p)`` where
        `n` is the number of samples and `p` are the number of
        dimensions.

    Returns
    -------
    proxMat : ndarray
        The proximity matrix induced by random kernel.
    """
model
x
class
None
class
`sklearn.ensemble.RandomForestRegressor` for similar classes.
Parameters

model : class
A trained random forest object for which the similarity matrix will be
calculated.
x : ndarray
Input data matrice. ``x`` must have shape must be ``(n, p)`` where
`n` is the number of samples and `p` are the number of
dimensions.

Returns

proxMat : ndarray
The proximity matrix induced by random kernel.
` sklearn . ensemble . RandomForestRegressor ` for similar classes . Parameters model : class A trained random forest object for which the similarity matrix will be calculated . x : ndarray Input data matrice . ` ` x ` ` must have shape must be ` ` ( n p ) ` ` where ` n ` is the number of samples and ` p ` are the number of dimensions . Returns proxMat : ndarray The proximity matrix induced by random kernel .