• Stars
    star
    271
  • Rank 150,834 (Top 3 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created about 11 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A set of simple Python scripts for pre-processing large files

phraug

A set of simple Python scripts for pre-processing large files, things like splitting and format conversion. The names phraug comes from a great book, Made to Stick, by Chip and Dan Heath.

See http://fastml.com/processing-large-files-line-by-line/ for the basic idea.

There's always at least one input file and usually one or more output files. An input file always stays unchanged.

phraug2 is available. It offers improved handling of command line arguments. Check it out.

Format conversion

[...] means that the parameter is optional.

csv2libsvm.py <input file> <output file> [<label index = 0>] [<skip headers = 0>]

Convert CSV to the LIBSVM format. If there are no labels in the input file, specify label index = -1. If there are headers in the input file, specify skip headers = 1.

pivotedcsv2libsvm.py <input file> <output file> [<skip headers = 0>]

Convert pivoted CSV (each line contains sample id, feature index and feature value) to the LIBSVM format. If there are headers in the input file, specify skip headers = 1.

csv2vw.py <input file> <output file> [<label index = 0>] [<skip headers = 0>]

Convert CSV to VW format. Arguments as above.

libsvm2csv.py <input file> <output file> <input file dimensionality>

Convert LIBSVM to CSV. You need to specify dimensionality, that is a number of columns (not counting a label).

libsvm2vw.py <input file> <output file>

Convert LIBSVM to VW.

tsv2csv.py <input file> <output file>

Convert tab-separated file to comma-separated file.

Column means, standard deviations and standardization

How do you standardize (or shift and scale) your data if it doesn't fit into memory? With these two scripts.

colstats.py <input file> <output file> [<label index>]

Compute column means and standard deviations from data in csv file. Can skip label if present. Numbers only. The first line of the output file contains means, the second one standard deviations.

This script uses f_is_headers module, which contains is_headers() function. The purpose of the function is to automatically define if the [first] line in file contains headers.

standardize.py <stats file> <input file> <output file> [<label index>]

Standardize (shift and scale to zero mean and unit standard deviation) data from csv file. Meant to be used with column stats file produced by colstats.py. Numbers only.

Other operations

chunk.py <input file> <number of output files> [<random seed>]

Split a file randomly line by line into a number of smaller files. Might be useful for preparing cross-validation. Output files will have the base nume suffixed with a chunk number, for example data.csv will be chunked into data_0.csv, data_1.csv etc.

count.py <input file>

Count lines in a file. On Unix you can do it with wc -l

delete_cols.py <input file> <output_file> <indices of columns to delete> delete_cols.py train.csv train_del.csv 0 2 3

Delete some columns from a CSV file. Indexes start with 0. Separate them with whitespace.

sample.py <input file> <output file> [<P = 0.5>]

Sample lines from an input file with probability P. Similiar to split.py, but there's only one output file. Useful for sampling large datasets.

shuffle.py <input file> <output file> [<max. lines in memory = 25000>] [<random seed>]

Shuffle (randomize order of) lines in a [big] file. Similiar to Unix' shuf. Useful for files that don't fit in memory. For fastest operation, set max. lines in memory as big as possible - this will result in fewer passes over the input file.

split.py <input file> <output file 1> <output file 2> [<P = 0.9>] [<random seed>]

Split a file into two randomly. Default P (probability of writing to the first file) is 0.9. You can specify any string as a seed for random number generator.

subset.py <input file> <output file> [<offset = 0>] [<lines = 100>]

Save a subset of lines from an input file to an output file. Start at offset (default 0), save lines (default 100).

unshuffle.py <input file> <output file> <max. lines in memory> <random seed>

Unshuffle a previously shuffled file (or any file) to the original order. Syntax is the same as for shuffle.py, but the seed is mandatory so max. lines in memory is mandatory also.

More Repositories

1

goodbooks-10k

Ten thousand books, six million ratings
Jupyter Notebook
788
star
2

hyperband

Tuning hyperparams fast with Hyperband
Python
587
star
3

phraug2

A new version of phraug, which is a set of simple Python scripts for pre-processing large files
Python
206
star
4

numer.ai

Validation and prediction code for numer.ai
Python
150
star
5

kaggle-blackbox

Deep learning made easy
MATLAB
115
star
6

classifying-text

Classifying text with bag-of-words
Python
114
star
7

adversarial-validation

Creating a better validation set when test examples differ from training examples
Python
100
star
8

evaluating-recommenders

Compute and plot NDCG for a recommender system
Python
95
star
9

time-series-classification

Classifying time series using feature extraction
Python
86
star
10

classifier-calibration

Reliability diagrams, Platt's scaling, isotonic regression
Python
71
star
11

kaggle-advertised-salaries

Predicting job salaries from ads - a Kaggle competition
Python
55
star
12

the-secret-of-the-big-guys

k-means + a linear model = good results
Python
55
star
13

pointer-networks-experiments

Sorting numbers with pointer networks
Python
55
star
14

kaggle-cats-and-dogs

Classifying images with OverFeat
Python
46
star
15

kaggle-stackoverflow

Predicting closed questions on Stack Overflow
Python
46
star
16

gaussrank

Preparing continuous features for neural networks with GaussRank
Python
45
star
17

kaggle-happiness

Predicting happiness from demographics and poll answers
Python
45
star
18

kaggle-cifar

Code for the CIFAR-10 competition at Kaggle, uses cuda-convnet
Python
44
star
19

sofia-ml-mod

sofia-kmeans with sparse RBF cluster mapping
C++
42
star
20

pylearn2-practice

Pylearn2 in practice
Python
41
star
21

kaggle-burn-cpu

Code for the "Burn CPU, burn" competition at Kaggle. Uses Extreme Learning Machines and hyperopt.
Python
33
star
22

kaggle-amazon

Amazon access control challenge
Python
25
star
23

pybrain-practice

A regression example for PyBrain
Python
25
star
24

wine-quality

Predicting wine quality
R
25
star
25

dimensionality-reduction-for-sparse-binary-data

convert a lot of zeros and ones to fewer real numbers
Python
23
star
26

cubert

How to make those 3D data visualizations
JavaScript
22
star
27

kaggle-gender

A Kaggle competition: discriminate gender based on handwriting
Python
21
star
28

msda-denoising

Using a very fast denoising autoencoder
MATLAB
17
star
29

kaggle-solar

Code for Solar Energy Prediction Contest at Kaggle
Python
17
star
30

nonlinear-vowpal-wabbit

How to use automatic polynomial features and neural network mode in VW
Python
17
star
31

metric-learning-for-regression

Applying metric learning to kin8nm
MATLAB
16
star
32

kaggle-avito

Code for the Avito competition
Python
16
star
33

kaggle-rossmann

Predicting sales with Pandas
Python
15
star
34

spearmint

tuning hyperparams automatically with spearmint
R
15
star
35

kaggle-accelerometer

Code for Accelerometer Biometric Competition at Kaggle
Python
15
star
36

large-scale-linear-learners

VW, Liblinear and StreamSVM compared on webspam
Python
14
star
37

r-libsvm-format-read-write

R code for reading and writing files in libsvm format
R
14
star
38

stardose

A recommender system for GitHub repositories
Python
13
star
39

running-external-programs-from-python

Python
11
star
40

feature-selection

Selecting features for classification with MRMR
R
11
star
41

kaggle-merck

Merck challenge at Kaggle
Python
10
star
42

kaggle-stumbleupon

bag of words + sparsenn
Python
10
star
43

project-rhubarb

predicting mortality in England using air quality data
Python
9
star
44

kaggle-bestbuy_big

Code for the Best Buy competition at Kaggle
Python
8
star
45

kaggle-digits

Some code for the Digits competition at Kaggle, incl. pylearn2's maxout
MATLAB
8
star
46

misc

misc
Jupyter Notebook
7
star
47

kaggle-poker-hands

Code for the Poker Rule Induction competition
Python
7
star
48

kaggle-bestbuy_small

Python
6
star
49

AlpacaGPT

How to train your own ChatGPT, Alpaca style
Python
3
star
50

kaggle-jobs

Some auxiliary code for Kaggle job recommendation challenge
Python
2
star