• Stars
    star
    1,242
  • Rank 37,541 (Top 0.8 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated 11 months ago

Reviews

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

Repository Details

Multivariate imputation and matrix completion algorithms implemented in Python

Build Status Coverage Status DOI

plot

A variety of matrix completion and imputation algorithms implemented in Python 3.6.

To install:

pip install fancyimpute

If you run into tensorflow problems and use anaconda, you can try to fix them with conda install cudatoolkit.

Important Caveats

(1) This project is in "bare maintenance" mode. That means we are not planning on adding more imputation algorithms or features (but might if we get inspired). Please do report bugs, and we'll try to fix them. Also, we are happy to take pull requests for more algorithms and/or features.

(2) IterativeImputer started its life as a fancyimpute original, but was then merged into scikit-learn and we deleted it from fancyimpute in favor of the better-tested sklearn version. As a convenience, you can still from fancyimpute import IterativeImputer, but under the hood it's just doing from sklearn.impute import IterativeImputer. That means if you update scikit-learn in the future, you may also change the behavior of IterativeImputer.

Usage

from fancyimpute import KNN, NuclearNormMinimization, SoftImpute, BiScaler

# X is the complete data matrix
# X_incomplete has the same values as X except a subset have been replace with NaN

# Use 3 nearest rows which have a feature to fill in each row's missing features
X_filled_knn = KNN(k=3).fit_transform(X_incomplete)

# matrix completion using convex optimization to find low-rank solution
# that still matches observed values. Slow!
X_filled_nnm = NuclearNormMinimization().fit_transform(X_incomplete)

# Instead of solving the nuclear norm objective directly, instead
# induce sparsity using singular value thresholding
X_incomplete_normalized = BiScaler().fit_transform(X_incomplete)
X_filled_softimpute = SoftImpute().fit_transform(X_incomplete_normalized)

# print mean squared error for the  imputation methods above
nnm_mse = ((X_filled_nnm[missing_mask] - X[missing_mask]) ** 2).mean()
print("Nuclear norm minimization MSE: %f" % nnm_mse)

softImpute_mse = ((X_filled_softimpute[missing_mask] - X[missing_mask]) ** 2).mean()
print("SoftImpute MSE: %f" % softImpute_mse)

knn_mse = ((X_filled_knn[missing_mask] - X[missing_mask]) ** 2).mean()
print("knnImpute MSE: %f" % knn_mse)

Algorithms

  • SimpleFill: Replaces missing entries with the mean or median of each column.

  • KNN: Nearest neighbor imputations which weights samples using the mean squared difference on features for which two rows both have observed data.

  • SoftImpute: Matrix completion by iterative soft thresholding of SVD decompositions. Inspired by the softImpute package for R, which is based on Spectral Regularization Algorithms for Learning Large Incomplete Matrices by Mazumder et. al.

  • IterativeImputer: A strategy for imputing missing values by modeling each feature with missing values as a function of other features in a round-robin fashion. A stub that links to scikit-learn's IterativeImputer.

  • IterativeSVD: Matrix completion by iterative low-rank SVD decomposition. Should be similar to SVDimpute from Missing value estimation methods for DNA microarrays by Troyanskaya et. al.

  • MatrixFactorization: Direct factorization of the incomplete matrix into low-rank U and V, with per-row and per-column biases, as well as a global bias. Solved by SGD in pure numpy.

  • NuclearNormMinimization: Simple implementation of Exact Matrix Completion via Convex Optimization by Emmanuel Candes and Benjamin Recht using cvxpy. Too slow for large matrices.

  • BiScaler: Iterative estimation of row/column means and standard deviations to get doubly normalized matrix. Not guaranteed to converge but works well in practice. Taken from Matrix Completion and Low-Rank SVD via Fast Alternating Least Squares.

Citation

If you use fancyimpute in your academic publication, please cite it as follows:

@software{fancyimpute,
  author = {Alex Rubinsteyn and Sergey Feldman},
  title={fancyimpute: An Imputation Library for Python},
  url = {https://github.com/iskandr/fancyimpute},
  version = {0.7.0},
  date = {2016},
}

More Repositories

1

parakeet

Runtime compiler for numerical Python
Python
233
star
2

ocaml_llvm

Toy compiler for OCaml Meetup
OCaml
67
star
3

moving_pictures

Create a movie from a sequence of images in Python (uses PIL and ffmpeg)
Python
42
star
4

knnimpute

Python implementations of kNN imputation
Python
31
star
5

striate

Convolutional Neural Networks in Python
C++
28
star
6

shiver

A multi-threaded work queue for LLVM functions
Python
14
star
7

dsltools

Helpers for DSL construction in Python
Python
13
star
8

texture_synthesis

Repetitive pretty pictures on demand
MATLAB
11
star
9

genepool

Framework for writing evolutionary optimization algorithms in OCaml
OCaml
11
star
10

parakeet-retired

Parallelizing Runtime for Array Languages
OCaml
9
star
11

arma

Estimating ARMA model parameters using stochastic gradient descent
Python
6
star
12

adversarial-impute

Possibly ill-fated experimented with Generative Adversarial Imputation
Python
5
star
13

immuno

Predicting immunogenicity of short peptides
Python
4
star
14

censored_regression

Linear regression with lower-bound labels
Python
4
star
15

deep-learning-for-bio

Deep Learning for Biology
4
star
16

attention-in-neural-networks

Code for Miami ML meetup on Attention in Neural Networks
Jupyter Notebook
3
star
17

mhcpred

MHC Binding Prediction
Python
3
star
18

brainmets

Survival prediction for brain metastases
Python
3
star
19

bytestar

Analyze Python bytecode using an SSA control flow graph representation
Python
3
star
20

ml-experiments

Experiments with Jax, PyTorch and variable length sequence models
Jupyter Notebook
3
star
21

nnseq

Multi-sequence learning using recurrent neural networks
2
star
22

simple-somatic-variant-calling

A simple genomics "pipeline" implemented via shell scripts
Shell
2
star
23

data-experiments

Python
2
star
24

immunesearch

Search for peptide substrings in IEDB T-cell assay data
Python
1
star
25

interval

Conversion between genomic interval/coordinate systems
Python
1
star
26

vec

Simple vector expression language implemented in Python
1
star
27

image-experiments

Jupyter Notebook
1
star
28

prototype-pan-allele-class2

Prototype of a pan-allele Class II MHC binding predictor
Jupyter Notebook
1
star
29

msmhc

Looking for "dark matter" of the MHC ligandome in mass specta
Python
1
star
30

yoclo

You Only Command Line Once
Python
1
star