Skip to content

Instantly share code, notes, and snippets.

View farrajota's full-sized avatar

M. Farrajota farrajota

View GitHub Profile
@farrajota
farrajota / data-structures.md
Last active May 3, 2021 07:57
Efficient data structures in python

Here I've put the most important data structures I could find with the most efficient implementations in Python I am aware of. Although this is a continuous process and many structures do not have any implementation reference available yet, if you happen to know a more efficient algorithm to implement one or more of this structures in Python (or any language) feel free to ping me :).

Basic Data Structures

Data Structure Python
Arrays numpy Tensorflow PyTorch
@farrajota
farrajota / s3_util.py
Created January 16, 2020 09:40 — forked from PGryllos/s3_util.py
Using dask's multithreaded scheduler to speedup download of multiple files from s3
"""
Using dask's multithreaded scheduler to speedup download of multiple files from
an s3 bucket
"""
import os
from functools import partial
import botocore
import boto3

I've been working with Apache Kafka for over 7 years. I inevitably find myself doing the same set of activities while I'm developing or working with someone else's system. Here's a set of Kafka productivity hacks for doing a few things way faster than you're probably doing them now. 🔥

Get the tools

@farrajota
farrajota / missing_value_imputation.md
Created October 25, 2018 13:32
How to treat missing values in your data

Missing values in data

Types of missing values

Missing completely at random (MCAR)

MCAR exists when missing values are randomly distributed across all observations. Missingness in given variable does not depend on any other variable, whether observed or unobserved. MCAR can be confirmed by dividing respondents into those with and without missing data, then using t-tests of mean differences on income, age, gender, and other key variables to establish that the two groups do not

@farrajota
farrajota / imputation_rules.md
Last active July 23, 2024 16:17
Rules of thumb for when imputation of missing values should not be used.

When imputation should not be used

  • If data are MCAR, imputation may not be not needed.
  • If missingness is due to unmeasured variables related to the dependent variable, data are MNAR and should not be imputed.
  • Imputation assumes data are MAR and should not be used with sparse data. Sparse data occur when missingness is non-random, such as a shopping cart survey of items purchased (coded 1) or not purchased (coded 0), because the null response (0) is non-random, due to unmeasured factors possibly not even known to the shopper.
  • Imputation should not be used to impute all the data for a subject
  • Imputation should not be used for a missing value for a given observation if that observation is also missing values on predictively critical variables in the imputation model. While this is difficult to check for each value to be imputed, a table of missing value patterns will show how many cases missing on a given variable also have missing values on other variables. In some cases this may lead a researcher
@farrajota
farrajota / checklist.md
Last active June 28, 2023 20:41
Data science process with checklists

data science checklist


Step 1


Data loading# data science checklist


Step 1

@farrajota
farrajota / guideline.md
Last active July 3, 2018 15:49
Data cleaning guidelines for multivariate data exploration (using Python's scipy stack).

Missing data

A Simple Example of a Missing Data Analysis Understanding the Reasons Leading to Missing Data Ignorable Missing Data Other Types of Missing Data Processes Examining the Patterns of Missing Data Diagnosing the Randomness of the Missing Data Process

Rules of Thumb

@farrajota
farrajota / bobp-python.md
Created May 31, 2017 14:10 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@farrajota
farrajota / mysplittable.lua
Created January 16, 2017 11:32
Splits a tensor into a table with `N` tensors (`N` is specified by the user).
local SplitTable, parent = torch.class('nn.MySplitTable', 'nn.Module')
function SplitTable:__init(dimension, nTensors)
parent.__init(self)
self.dimension = dimension
self.nTensors = nTensors
self.joinTable = nn.JoinTable(dimension)
end
function SplitTable:getSize(input)