Skip to content
Open

Knn #22

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
25a38e0
Update .travis.yml
julienawilson Jan 18, 2017
97e30fc
Update README.md
julienawilson Jan 18, 2017
c8b6b90
added new methods to README and module doctstrings
rveeblefetzer Jan 18, 2017
f7e5913
Merge branch 'bst' of https://github.com/julienawilson/data-structure…
rveeblefetzer Jan 18, 2017
cb54d06
adding delete method
rveeblefetzer Jan 18, 2017
18d7877
added 1-child node instances for delete
rveeblefetzer Jan 18, 2017
4ba611a
delete for node with two childs
julienawilson Jan 18, 2017
cf9a522
added the easy tests for delete
rveeblefetzer Jan 18, 2017
a65f8c6
Merge branch 'bst' of https://github.com/julienawilson/data-structure…
rveeblefetzer Jan 18, 2017
1505ae8
fix in the delete method
julienawilson Jan 18, 2017
136cd50
delete fix
julienawilson Jan 19, 2017
2214ff2
fix in delete, more tests
julienawilson Jan 19, 2017
dba1e85
balance fix
julienawilson Jan 19, 2017
621f7ff
added tests for delete to check two-way connections of deleted; added…
rveeblefetzer Jan 19, 2017
046afe0
cleanup for merge
rveeblefetzer Jan 19, 2017
95ec636
deleted corpse code
rveeblefetzer Jan 19, 2017
cc7ad6c
changed balance method so it can take non-root nodes as argument
rveeblefetzer Jan 19, 2017
5e0c421
added autobalanc helper functions to rotate left/right
rveeblefetzer Jan 19, 2017
c63dc6d
tests for rotation
julienawilson Jan 19, 2017
98ec9d1
bug in left right rotation
julienawilson Jan 24, 2017
b26a465
true/false switch for autobalancing tree
julienawilson Jan 24, 2017
99a354c
fixed the rotations bug. small operator error.
julienawilson Jan 24, 2017
61c5e7d
adding to docstrings
rveeblefetzer Jan 24, 2017
276306e
Merge branch 'bst' of https://github.com/julienawilson/data-structure…
rveeblefetzer Jan 24, 2017
343328a
Merge branch 'bst-rotation' of https://github.com/julienawilson/data-…
rveeblefetzer Jan 24, 2017
2f8af43
added docstrings, made autobalance, rebalance and rotations into hidd…
rveeblefetzer Jan 24, 2017
04d8649
adding initial files
rveeblefetzer Jan 25, 2017
ae697bd
hash table
julienawilson Jan 25, 2017
41bcb9e
Merge branch 'hash-table' of https://github.com/julienawilson/data-st…
rveeblefetzer Jan 25, 2017
14197b9
added pseudocode-ish addititve hash
rveeblefetzer Jan 25, 2017
366131f
add hash func written
julienawilson Jan 25, 2017
577725b
added blank test file for hash table module
rveeblefetzer Jan 25, 2017
a21cad5
Merge branch 'hash-table' of https://github.com/julienawilson/data-st…
rveeblefetzer Jan 25, 2017
5ca754b
set and hash functions
julienawilson Jan 25, 2017
0e23f34
Merge branch 'hash-table' of https://github.com/julienawilson/data-st…
rveeblefetzer Jan 25, 2017
1d25cbd
get for the hash function
julienawilson Jan 25, 2017
0ec88b5
added test for seting a number; fix typon in docstrings
rveeblefetzer Jan 25, 2017
201e12a
Merge branch 'hash-table' of https://github.com/julienawilson/data-st…
rveeblefetzer Jan 25, 2017
bf2a18b
added tests using unix dictionary list
rveeblefetzer Jan 25, 2017
7743b62
xor hash
julienawilson Jan 25, 2017
2c15414
added tests for xor with unix dict file
rveeblefetzer Jan 25, 2017
5eddf66
Added class docstring to module; added module info to README
rveeblefetzer Jan 25, 2017
b0852eb
adding initial module file
rveeblefetzer Jan 28, 2017
720ff5f
added class for trie trees and contains and insert methods
rveeblefetzer Jan 28, 2017
bc60e6d
tests for insert and contains
julienawilson Jan 28, 2017
fc3b20b
added Node class
rveeblefetzer Jan 28, 2017
4feee77
Merge branch 'trie' of https://github.com/julienawilson/data-structur…
julienawilson Jan 28, 2017
49038b7
more tests for insert and contains
julienawilson Jan 28, 2017
bd6e0ba
delete word
julienawilson Jan 28, 2017
87ce4b7
adding basic tests for remove method
rveeblefetzer Jan 28, 2017
3c40215
Merge branch 'trie' of https://github.com/julienawilson/data-structur…
rveeblefetzer Jan 28, 2017
86e9d10
delete raises error
julienawilson Jan 28, 2017
b9d74fa
Merge branch 'trie' of https://github.com/julienawilson/data-structur…
julienawilson Jan 28, 2017
269c22f
add another test for remove method
rveeblefetzer Jan 28, 2017
f90a8bc
Merge branch 'trie' of https://github.com/julienawilson/data-structur…
rveeblefetzer Jan 28, 2017
794e557
delete works on single word trees
julienawilson Jan 28, 2017
f184564
Merge branch 'trie' of https://github.com/julienawilson/data-structur…
julienawilson Jan 28, 2017
64e09fd
added size()
julienawilson Jan 28, 2017
4664d20
add more tests for remove method
rveeblefetzer Jan 28, 2017
f4d0471
Merge branch 'trie' of https://github.com/julienawilson/data-structur…
rveeblefetzer Jan 28, 2017
baddf49
debugging remove's helper method, tests
rveeblefetzer Jan 28, 2017
b7cfccf
deletes word parts and extensions
julienawilson Jan 29, 2017
474714a
add tests for size method
rveeblefetzer Jan 29, 2017
bdedcfe
Merge branch 'trie' of https://github.com/julienawilson/data-structur…
rveeblefetzer Jan 29, 2017
1f64fbb
adding docstrings, README info
rveeblefetzer Jan 29, 2017
416b704
adding initial traversal method
rveeblefetzer Jan 29, 2017
1e83927
added traversal and helper methods
rveeblefetzer Jan 29, 2017
cec048e
test for traversal
julienawilson Jan 29, 2017
a3f059b
Merge branch 'trie-traversal' of https://github.com/julienawilson/dat…
julienawilson Jan 29, 2017
7f92d13
test for traversal is a mess
julienawilson Jan 29, 2017
3ecd96d
draft function written
rveeblefetzer Jan 30, 2017
e431eaf
adding to repo
rveeblefetzer Jan 30, 2017
dd383b7
fixed insertion sort bug
julienawilson Jan 31, 2017
9ff3e3b
adding draft function, helper function
rveeblefetzer Jan 31, 2017
6bbd43d
test merge sort
julienawilson Jan 31, 2017
ca5daa8
Merge branch 'merge_sort' of https://github.com/julienawilson/data-st…
julienawilson Jan 31, 2017
55420a8
reverting helper functions final ifs
rveeblefetzer Jan 31, 2017
4897c73
not sorting, some tests
julienawilson Jan 31, 2017
3b39110
undoing the revert. not working anyway tho
rveeblefetzer Jan 31, 2017
974f7de
undoing the revert. not working anyway tho
rveeblefetzer Jan 31, 2017
5592fb8
its worrrking
julienawilson Jan 31, 2017
a4f618e
syncing back up with Julien
rveeblefetzer Jan 31, 2017
c205e52
merge sort timit
julienawilson Jan 31, 2017
1ddd6e0
Merge branch 'merge_sort' of https://github.com/julienawilson/data-st…
rveeblefetzer Jan 31, 2017
7f6208a
timit insertion sort
julienawilson Jan 31, 2017
2f3ebfa
adding first draft of quicksort
rveeblefetzer Feb 1, 2017
9084490
quicksort timit
julienawilson Feb 1, 2017
f51591f
test for quicksort
julienawilson Feb 1, 2017
37f4dc7
edited README, module docstrings
rveeblefetzer Feb 1, 2017
54fdde4
starting radix
julienawilson Feb 2, 2017
b701e85
radix sort
julienawilson Feb 2, 2017
cb8db1d
adding tests for radix sort. any adds on other files are trivial typo…
rveeblefetzer Feb 9, 2017
e33cbb6
beginning framework for dec tree
julienawilson Feb 10, 2017
54a801f
Merge branch 'decision-tree' of https://github.com/julienawilson/data…
rveeblefetzer Feb 10, 2017
5fba058
added required installs for machine learning work
rveeblefetzer Feb 10, 2017
de31f02
a little bit of best_split_alg pseudo code
julienawilson Feb 10, 2017
f7192e8
Merge branch 'decision-tree' of https://github.com/julienawilson/data…
julienawilson Feb 10, 2017
26ae2ac
adding knn, test files
rveeblefetzer Mar 1, 2017
c29579d
added to doctring, README
rveeblefetzer Mar 1, 2017
2574a66
deleted merge conflict notes
rveeblefetzer Mar 1, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: python
python:
- "2.7"
- "3.5"

install:
- pip install -e .[test]

Expand Down
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![Build Status](https://travis-ci.org/julienawilson/data-structures.svg?branch=master)](https://travis-ci.org/julienawilson/data-structures)

# Data Structures

# data-structures
Patrick Saunders and Julien Wilson
<br>
Data Structures created in Python401
Expand All @@ -26,7 +28,7 @@ A linked list that points in both directions
A tree of nodes sorted by values less than and greater than root branching to the left and right, respectively.

Methods include:
* insert(self, val): Insert value into tree; if value already exists, ignore it.
* insert(self, val): Insert value into tree; if value already exists, ignore it. Method autobalances after insertion, and tree size increments by one.
* search(self, val): Return node containing that value, else None.
* size(self): Return number of nodes/vertices in tree, 0 if empty.
* depth(self): Return number of levels in tree. Tree with one value has depth of 0.
Expand All @@ -35,3 +37,44 @@ Methods include:
Trees that are higher on the left than the right should return a positive value;
trees that are higher on the right than the left should return a negative value;
an ideally-balanced tree should return 0.
* in_order(self): Return a generator that returns each node value from in-order traversal.
* pre_order(self): Return a generator that returns each node value from pre-order traversal.
* post_order(self): Return a generator that returns each node value from post_order traversal.
* breadth_first(self): Return a generator returns each node value from breadth-first traversal.
* delete(value): Delete a node's connections (edges), effectively deleting node. Method autobalances after deletion, and tree size decrements by one.

##Hash Table
Stores key-value pairs using a given hashing algorithm. Choices for hashing algorithms are additive hash and xor hash.
Additive hash sums the Unicode code point for each letter in the word or string, then calls modulo with the number of buckets in the table.
XOR hash runs exclusive or with the letters of the word or string.

Methods include:
set(key, value): Add a key-value pair to the hash table.
get(key): Retrieve a value for the given key.

##Trie Trees
Module is an implementation of a trie tree, using nested dictionaries instead of nodes.

Words branch out from root, with root's immediate children being
the initial letter of each word. Words can then branch from that initial,
as well as from initial substrings.

Methods include:
contains(word): Check to see whether a word is in the tree. O(k), where k is the length of the given word.
insert(word): Inserts a word into the trie tree. O(k), where k is the length of the given word.

##Merge Sort
This implementation of the merge sort algorithm recursively divides the input list into sublists small enough to be sorted on their own, then merges them.
When run as a script, a timeit function runs merge_sort() on a list of 200 random integers three times, and returns the run time for each.

Methods include:
merge_sort(a_list): Recursively divides list at midpoint, more or less.
merge(list1, list2): A helper function to do the comparisons between values.

##K-Nearest Neighbors Classifier
Categorize new data based on labels of the *k* closest data points.

Public method:
predict(self, new_points, k=None): Takes in a new dataset, and defaults its search
for *k* neighbors to KNN onject default of 5. Returns the likely class/grouping
for each set of data in the dataset, based on its *k* nearest neighbors.
Loading