Skip to content

Instantly share code, notes, and snippets.

# calculate and visualize silhouette score from k-means clustering.
# plots first two features in 2D and first three features in 3D.
# from: http://scikit-learn.org/stable/auto_examples/cluster/plot_kmeans_silhouette_analysis.html
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score, silhouette_samples
from mpl_toolkits.mplot3d import Axes3D
##### cluster data into K=1..K_MAX clusters #####
K_MAX = 10
@cfperez
cfperez / log_transformer.py
Created September 10, 2015 23:52
LogTransformer to log scale features in sklearn Pipelines
from sklearn.base import BaseEstimator,TransformerMixin
class LogTransformer(BaseEstimator,TransformerMixin):
def __init__(self, constant=1, base='e'):
from numpy import log,log10
if base == 'e' or base == np.e:
self.log = log
elif base == '10' or base == 10:
self.log = log10
else:
@dmargala
dmargala / NeighboringDataScientists.ipynb
Last active August 17, 2016 23:29
How clustered are data scientists in the office?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/bash
# Usage:
# sudo su
# export https_proxy=proxy:8888
# wget https://gist.githubusercontent.com/danielballan/c02c17f92650e21488a3/raw -O setup_conda.sh
# chmod +x setup_conda.sh
# rm -rf ~/.conda
# rm ~/.condarc
# ./setup_conda.sh
@marcelinollano
marcelinollano / anki.rb
Last active August 26, 2020 11:16
You can use Markdown inside the questions and answers! Images in the same folder though.
#!/usr/bin/env ruby
# Usage:
#
# => brew install imagemagick
# => gem install anki2 kramdown rmagick image_optim image_optim_pack
# => chmod +x ./anki.rb
# => ./anki.rb questions.md
require 'rubygems'
anonymous
anonymous / model_selection.ipynb
Created August 27, 2015 12:42
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cavedave
cavedave / README.md
Last active January 3, 2022 20:40
When will the Carnage end?

"This American carnage stops right here and stops right now." Donald Trump

Draw for yourself the pattern of how many people are murdered in the US each year

This code was made by Adam Pearce and the data comes from Homicide Trends in United States

@zed
zed / dp.py
Last active January 19, 2022 00:24
Find height, width of the largest rectangle containing all 0's in the matrix
#!/usr/bin/env python
"""Find height, width of the largest rectangle containing all 0's in the matrix.
The algorithm for `max_size()` is suggested by @j_random_hacker [1].
The algorithm for `max_rectangle_size()` is from [2].
The Python implementation [3] is dual licensed under CC BY-SA 3.0
and ISC license.
[1]: http://stackoverflow.com/questions/2478447/find-largest-rectangle-containing-only-zeros-in-an-nn-binary-matrix#comment5169734_4671342
@AustinRochford
AustinRochford / Bayesian Survival analysis with PyMC3.ipynb
Last active April 10, 2022 05:02
Bayesian Survival analysis with PyMC3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mjnaderi
mjnaderi / AnkiCardTemplate.md
Last active May 3, 2022 10:00
Anki Card Template
  • Install "Syntax Highlighting for Code" plugin: https://ankiweb.net/shared/info/1463041493

  • In the plugin's options (Tools > Syntax Highlighting Options), set:

    • Line numbers
    • Center code fragments
    • Use CSS classes
  • Enter following HTML and CSS templates in Tools > Manage Note Types > Cards