Skip to content

Instantly share code, notes, and snippets.

View mikkelam's full-sized avatar
🍌
banana

Mikkel A. Madsen mikkelam

🍌
banana
View GitHub Profile
@mikkelam
mikkelam / gradient_boosting.py
Created April 29, 2016 09:23
Minimal example Gradient Boosting Regressor using scikit
import numpy as np
from sklearn.tree import DecisionTreeRegressor
class LeastSquares:
@staticmethod
def negative_gradient(preds, y):
return y - preds
class GradientBoostingRegressor:
models = []
@mikkelam
mikkelam / sklearn_vw.py
Created March 30, 2016 16:34
Extends vowpals sklearn interface to ect with multiclass classification
# -*- coding: utf-8 -*-
# pylint: disable=line-too-long, unused-argument, invalid-name, too-many-arguments, too-many-locals
"""
Utilities to support integration of Vowpal Wabbit and scikit-learn
"""
import numpy as np
import sklearn
from pyvw import vw
import re
@mikkelam
mikkelam / hamilton.py
Last active October 29, 2022 07:21
Finds a hamiltonian path using networkx graph library in Python with a backtrack solution
import networkx as nx
def hamilton(G):
F = [(G,[list(G.nodes())[0]])]
n = G.number_of_nodes()
while F:
graph,path = F.pop()
confs = []
neighbors = (node for node in graph.neighbors(path[-1])
if node != path[-1]) #exclude self loops