def _calculate_feature_stats(feature_list, prepared, serialization_file):  # pylint: disable=R0914
    """Calculate min, max and mean for each feature. Store it in object."""
    # Create feature only list
    feats = [x for x, _ in prepared]  # Label is not necessary

    # Calculate all means / mins / maxs
    means = numpy.mean(feats, 0)
    mins = numpy.min(feats, 0)
    maxs = numpy.max(feats, 0)

    # Calculate, min, max and mean vector for each feature with
    # normalization
    start = 0
    mode = 'w'
    arguments = {'newline': ''}
    if sys.version_info.major < 3:
        mode += 'b'
        arguments = {}
    with open(serialization_file, mode, **arguments) as csvfile:
        spamwriter = csv.writer(csvfile,
                                delimiter=str(';'),
                                quotechar=str('"'),
                                quoting=csv.QUOTE_MINIMAL)
        for feature in feature_list:
            end = start + feature.get_dimension()
            # append the data to the feature class
            feature.mean = numpy.array(means[start:end])
            feature.min = numpy.array(mins[start:end])
            feature.max = numpy.array(maxs[start:end])
            start = end
            for mean, fmax, fmin in zip(feature.mean, feature.max,
                                        feature.min):
                spamwriter.writerow([mean, fmax - fmin])
def _calculate_feature_stats ( feature_list , prepared , serialization_file ) : feats = [ x for x , _ in prepared ] means = numpy . mean ( feats , 0 ) mins = numpy . min ( feats , 0 ) maxs = numpy . max ( feats , 0 ) start = 0 mode = 'w' arguments = { 'newline' : '' } if sys . version_info . major < 3 : mode += 'b' arguments = { } with open ( serialization_file , mode , ** arguments ) as csvfile : spamwriter = csv . writer ( csvfile , delimiter = str ( ';' ) , quotechar = str ( '"' ) , quoting = csv . QUOTE_MINIMAL ) for feature in feature_list : end = start + feature . get_dimension ( ) feature . mean = numpy . array ( means [ start : end ] ) feature . min = numpy . array ( mins [ start : end ] ) feature . max = numpy . array ( maxs [ start : end ] ) start = end for mean , fmax , fmin in zip ( feature . mean , feature . max , feature . min ) : spamwriter . writerow ( [ mean , fmax - fmin ] )
Calculate min, max and mean for each feature. Store it in object.