Skip to content

Instantly share code, notes, and snippets.

def test_neighbors_metrics(n_samples=20, n_features=3,
n_query_pts=2, n_neighbors=5):
# Test computing the neighbors for various metrics
# create a symmetric matrix
V = rng.rand(n_features, n_features)
VI = np.dot(V, V.T)
metrics = [('euclidean', {}),
('manhattan', {}),
('minkowski', dict(p=1)),
@saihttam
saihttam / README.md
Created August 29, 2016 17:26 — forked from adewes/README.md
Ebay Ads - Bot. Because who wants to write messages by hand...

To use this bot:

  • Download ads_bot.py and requirements.txt.
  • Type pip install -r requirements.txt to install the requirements.
  • Fill out the required information in the Python file.
  • Ideally, create a (free) Slack account and set up a web hook to receive notifications from the bot.
  • Run the script :)
  • Relax and be ready to answer incoming calls :D
import pandas as pd
from sklearn.feature_extraction import DictVectorizer
def one_hot_dataframe(data, cols, replace=False):
""" Takes a dataframe and a list of columns that need to be encoded.
Returns a 3-tuple comprising the data, the vectorized data,
and the fitted vectorizor."""
vec = DictVectorizer(sparse=False)
vecData = pd.DataFrame(vec.fit_transform(data[cols].T.to_dict().values()))
vecData.columns = vec.get_feature_names()
@saihttam
saihttam / gist:7241db5be80d076c1e8f
Created September 27, 2015 16:45 — forked from anonymous/gist:1c6198cd663165d2dd53
Plot ROC Curve with Cut-Off Markers
def plot_roc(y, probs, threshmarkers=None):
fpr, tpr, thresh = sklearn.metrics.roc_curve(y, probs)
plt.plot(fpr, tpr, lw=2)
if threshmarkers is None:
threshmarkers = np.linspace(0, 1, 11)
for t in threshmarkers:
k = np.abs(thresh-t).argmin()
x = fpr[k]
y = tpr[k]