Skip to content

Instantly share code, notes, and snippets.

Avatar

Leon Aburime leonaburime

View GitHub Profile
@leonaburime
leonaburime / agaricus-lepiota.data
Created Jul 23, 2014
Data File - agaricus-lepiota.data file for various algorithms
View agaricus-lepiota.data
p,x,s,n,t,p,f,c,n,k,e,e,s,s,w,w,p,w,o,p,k,s,u
e,x,s,y,t,a,f,c,b,k,e,c,s,s,w,w,p,w,o,p,n,n,g
e,b,s,w,t,l,f,c,b,n,e,c,s,s,w,w,p,w,o,p,n,n,m
p,x,y,w,t,p,f,c,n,n,e,e,s,s,w,w,p,w,o,p,k,s,u
e,x,s,g,f,n,f,w,b,k,t,e,s,s,w,w,p,w,o,e,n,a,g
e,x,y,y,t,a,f,c,b,n,e,c,s,s,w,w,p,w,o,p,k,n,g
e,b,s,w,t,a,f,c,b,g,e,c,s,s,w,w,p,w,o,p,k,n,m
e,b,y,w,t,l,f,c,b,n,e,c,s,s,w,w,p,w,o,p,n,s,m
p,x,y,w,t,p,f,c,n,p,e,e,s,s,w,w,p,w,o,p,k,v,g
e,b,s,y,t,a,f,c,b,g,e,c,s,s,w,w,p,w,o,p,k,s,m
@leonaburime
leonaburime / randomForest.py
Last active Aug 29, 2015
Random Forest implementation in python. Will need to import datafile.py, decisionTree.py, and agaricus-lepiota.data file
View randomForest.py
from __future__ import division
import random, datafile, decisionTree, collections
#Must import datafile.py and decisionTree.py
def randomSelection(arr, n_items):
return random.sample(arr, n_items)
class randomForest:
@leonaburime
leonaburime / decisionTree.py
Created Jul 22, 2014
Decision Tree implementation in Python. Will need to import datafile.py and agaricus-lepiota.data.
View decisionTree.py
import numpy as np, pandas as pd
from pprint import pprint
from copy import copy
import math,urllib2,datafile,pdb
#This tutorial is derived from ...
#http://nbviewer.ipython.org/github/gumption/Python_for_Data_Science/blob/master/4_Python_Simple_Decision_Tree.ipynb
#Data set will be taken from
data= datafile.get('mushroom')
@leonaburime
leonaburime / datafile.py
Created Jul 22, 2014
File used to read in data -possibly into dataframes - for various sample python programs.
View datafile.py
import urllib2, pandas as pd
d = {
'mushroom' :{
'features': [
'class','cap-shape', 'cap-surface', 'cap-color',
'bruises?','odor','gill-attachment',
@leonaburime
leonaburime / naiveBayes.py
Last active Aug 29, 2015
Naive Bayes implementation in Python. Will need to import datafile.py for this program.
View naiveBayes.py
from __future__ import division
import pandas as pd, numpy as np,datafile,math,pdb,itertools
from pprint import pprint
from collections import Counter
#Will need to import datafile.py and correct dataset for this program
class naiveBayes:
def __init__(self,name='play', testSize=0):
@leonaburime
leonaburime / KMeans.java
Created Jul 22, 2014
KMeans algorithm implementation in Java. Imported Apache Commons 'lang' and 'math' library.
View KMeans.java
package KMeans;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.math3.linear.MatrixUtils;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.linear.RealVector;
import org.apache.commons.math3.stat.StatUtils;
import java.lang.reflect.Array;
import java.util.*;
@leonaburime
leonaburime / NeuralNetwork.java
Created Jul 22, 2014
Neural Network implementation in Java. Uses Apache Common Math library.
View NeuralNetwork.java
package NeuralNetwork;
import org.apache.commons.lang3.*;
import org.apache.commons.math3.linear.*;
import org.apache.commons.math3.stat.StatUtils;
import javax.swing.*;
import java.util.*;
/**
@leonaburime
leonaburime / kNearestNeighbor.java
Created Jul 20, 2014
k Neareast-Neighbor implementation in Java. Closely mirrors the the python implementation.
View kNearestNeighbor.java
package com.example.kNearestNeighbor;
//To use third party libraries simply download the jar
//and put it in the Program Files/jre/jdk#.#(version number)/lib/ext for example
//Can get the jar file for guava at https://code.google.com/p/guava-libraries/
import com.google.common.base.Functions;
import com.google.common.collect.Ordering;
//Can get the apache commons math file at
@leonaburime
leonaburime / neuralNetwork.py
Last active Aug 29, 2015
Short implementation of a feedforward neural network with backpropagation
View neuralNetwork.py
import numpy as np
import math
from pprint import pprint
import pdb
#Linearly separable
_or = {
'X': [[0,0],[0,1],[1,0],[1,1]],
@leonaburime
leonaburime / linearRegression.py
Created Jun 27, 2014
Linear Regression for single variable. For multivariable check out my gradientDescent.py
View linearRegression.py
import numpy as np
import dataMunge, pdb
from sklearn import linear_model
input = [
[95, 85],
[85, 95],
[80, 70],
[70, 65],
[60, 70]