<commit_before>from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
from sklearn.cluster import AgglomerativeClustering, KMeans
from sklearn import metrics
import numpy as np
from scipy.cluster.hierarchy import cophenet
from scipy.spatial.distance import pdist
from mousestyles.data.utils import day_to_mouse_average


# prep data functions
def prep_data(mouse_data, std=True, rescale=True):
    """
    Returns a ndarray data to be used in clustering algorithms:
        column 0 : strain,
        column 1: mouse,
        other columns corresponding to feature avg/std of a mouse over 16 days
            that may or may not be rescaled to the same unit as specified

    Parameters
    ----------
    mouse_data: a 21131 * 13 pandas DataFrame,
        column 0 : strain,
        column 1: mouse,
        column 2: day,
        column 3: hour,
        other columns corresponding to features
    std: bool,
        whether the standard deviation of each feature is returned
    rescale: bool,
        whether each column is rescaled or not (rescale is performed by the
        column's maximum)

    Returns
    ----------
    The ndarray as specified
    """
    mouse_X = np.array(mouse_data.iloc[:, 4:], dtype=float)
    mouse_labels = np.array(mouse_data.iloc[:, 0:3])
    mouse_dayavg, mouse_daystd = day_to_mouse_average(
        mouse_X, mouse_labels, num_strains=16, stdev=True, stderr=False)
    mouse_dayavgstd = np.hstack([mouse_dayavg, mouse_daystd[:, 2:]])
    mouse_dayavgstd_X = mouse_dayavgstd[:, 2:]
    mouse_dayavgstd_X_scl = mouse_dayavgstd_X / np.max(
        mouse_dayavgstd_X, axis=0)
    mouse_dayavgstd_scl = np.hstack(
        [mouse_dayavgstd[:, 0:2], mouse_dayavgstd_X_scl])
    if (std is False and rescale is False):
        return(mouse_dayavg)
    elif (std is True and rescale is True):
        return(mouse_dayavgstd)
    elif (std is False and rescale is True):
        return(mouse_dayavgstd_scl[:, 0:(mouse_dayavg.shape[1])])
    else:<commit_msg>ENH: modified input of prep_data per comment<commit_after>from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
from sklearn.cluster import AgglomerativeClustering, KMeans
from sklearn import metrics
import numpy as np
from scipy.cluster.hierarchy import cophenet
from scipy.spatial.distance import pdist
from mousestyles.data.utils import day_to_mouse_average


# prep data functions
def prep_data(mouse_data, melted=False, std=True, rescale=True):
    """
    Returns a ndarray data to be used in clustering algorithms:
        column 0 : strain,
        column 1: mouse,
        other columns corresponding to feature avg/std of a mouse over 16 days
            that may or may not be rescaled to the same unit as specified

    Parameters
    ----------
    mouse_data: 
        (i) a 21131 * (4 + ) pandas DataFrame,
            column 0 : strain,
            column 1: mouse,
            column 2: day,
            column 3: hour,
            other columns corresponding to features
        or
        (ii) a 1921 * (3 + ) pandas DataFrame,
            column 0: strain,
            column 1: mouse,
            column 2: day,
            other columns corresponding to features
    melted: bool,
        False if the input mouse_data is of type (i)    
    std: bool,
        whether the standard deviation of each feature is returned
    rescale: bool,
        whether each column is rescaled or not (rescale is performed by the
        column's maximum)

    Returns
    ----------
    The ndarray as specified
    """
    if melted:
        mouse_X = np.array(mouse_data.iloc[:, 3:], dtype=float)
    else:
        mouse_X = np.array(mouse_data.iloc[:, 4:], dtype=float)
    mouse_labels = np.array(mouse_data.iloc[:, 0:3])
    mouse_dayavg, mouse_daystd = day_to_mouse_average(
        mouse_X, mouse_labels, num_strains=16, stdev=True, stderr=False)
    mouse_dayavgstd = np.hstack([mouse_dayavg, mouse_daystd[:, 2:]])
    mouse_dayavgstd_X = mouse_dayavgstd[:, 2:]
    mouse_dayavgstd_X_scl = mouse_dayavgstd_X / np.max(
        mouse_dayavgstd_X, axis=0)
    mouse_dayavgstd_scl = np.hstack(
        [mouse_dayavgstd[:, 0:2], mouse_dayavgstd_X_scl])
    if (std is False and rescale is False):
        return(mouse_dayavg)
    elif (std is True and rescale is True):
        return(mouse_dayavgstd)
    elif (std is False and rescale is True):
        return(mouse_dayavgstd_scl[:, 0:(mouse_dayavg.shape[1])])
    else:
{'fraction_non_alphanumeric': 0.08337038683859493, 'fraction_numerical': 0.013783903957314362, 'mean_word_length': 2.8289361702127658, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '963179', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1377, 'n_words': 448}