Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
submissions
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mis21-intersession-2016
submissions
Commits
e65997d7
Commit
e65997d7
authored
Jul 16, 2016
by
Alexander Hans Collado Jr.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added lab1
parent
a6f47644
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
0 deletions
+125
-0
.DS_Store
140991/.DS_Store
+0
-0
.gitignore
140991/lab1/.gitignore
+21
-0
rcd.rb
140991/lab1/rcd.rb
+96
-0
Gemfile.lock
140991/lab2/Gemfile.lock
+8
-0
No files found.
140991/.DS_Store
View file @
e65997d7
No preview for this file type
140991/lab1/.gitignore
0 → 100644
View file @
e65997d7
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
# Ignore Byebug command history file.
.byebug_history
140991/lab1/rcd.rb
0 → 100644
View file @
e65997d7
data_points
=
[]
k
=
5
data_point_a
=
{
:label
=>
"cat"
,
:features
=>
[
12
,
1
,
1
],
:dist
=>
999
}
data_point_b
=
{
:label
=>
"cat"
,
:features
=>
[
13
,
3
,
1
],
:dist
=>
999
}
data_point_c
=
{
:label
=>
"cat"
,
:features
=>
[
15
,
1
,
1
],
:dist
=>
999
}
data_point_d
=
{
:label
=>
"cat"
,
:features
=>
[
3
,
12
,
2
],
:dist
=>
999
}
data_point_e
=
{
:label
=>
"dog"
,
:features
=>
[
4
,
11
,
2
],
:dist
=>
999
}
data_point_f
=
{
:label
=>
"dog"
,
:features
=>
[
1
,
11
,
2
],
:dist
=>
999
}
data_point_g
=
{
:label
=>
"cat"
,
:features
=>
[
11
,
4
,
1
],
:dist
=>
999
}
data_point_h
=
{
:label
=>
"cat"
,
:features
=>
[
13
,
2
,
1
],
:dist
=>
999
}
data_point_i
=
{
:label
=>
"dog"
,
:features
=>
[
3
,
13
,
2
],
:dist
=>
999
}
data_point_j
=
{
:label
=>
"dog"
,
:features
=>
[
7
,
12
,
2
],
:dist
=>
999
}
data_points
<<
data_point_a
data_points<<data_point_b
data_points<<data_point_c
data_points<<data_point_d
data_points<<data_point_e
data_points<<data_point_f
data_points<<data_point_g
data_points<<data_point_h
data_points<<data_point_i
data_points<<data_point_j
unknown = {label:nil,features:[14, 2, 1]}
distance_label = []
def modified_bubble_sort(result)
for i in 0 ..result.count-1
for j in 0 ..result.count-1
if result[j+1] != nil
if result[j][:dist] > result[j+1][:dist]
temp = result[j]
result[j] = result[j+1]
result[j+1] = temp
end
end
end
end
result
end
def euclidean(v1, v2)
total = 0
v1.each_with_index do |v1, index|
total = total + (v1 - v2[index])**2
end
Math.sqrt(total)
end
def use_knn( data, k, unknown_data_point)
resulting_array_of_stuff = []
#data.each do |d|
#assign distances to entries
#d[:dist] = euclidean(d[:features], unknown_data_point[:features])
#puts " entry
#{
d
[
:label
]
}
distance:
#{
d
[
:dist
]
}
"
#end
sorted_data = modified_bubble_sort(data)
#data.each do |d|
# puts " sorted entry
#{
d
[
:label
]
}
distance:
#{
d
[
:dist
]
}
"
#end
cat_count=0
dog_count=0
for x in 0 .. k-1
if sorted_data[x][:label] == "cat"
cat_count = cat_count +1
else
if sorted_data[x][:label] == "dog"
dog_count = dog_count +1
else
end
end
end
if cat_count>dog_count
type="cat"
else
if cat_count<dog_count
type="dog"
else
type="something in between"
end
end
type
end
puts use_knn(data_points,k,unknown)
\ No newline at end of file
140991/lab2/Gemfile.lock
View file @
e65997d7
...
...
@@ -73,6 +73,9 @@ GEM
mini_portile2 (2.1.0)
minitest (5.9.0)
multi_json (1.12.1)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
nokogiri (1.6.8-x86-mingw32)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
...
...
@@ -124,6 +127,7 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.11)
sqlite3 (1.3.11-x86-mingw32)
thor (0.19.1)
thread_safe (0.3.5)
...
...
@@ -143,6 +147,7 @@ GEM
sprockets-rails (>= 2.0, < 4.0)
PLATFORMS
ruby
x86-mingw32
DEPENDENCIES
...
...
@@ -158,3 +163,6 @@ DEPENDENCIES
tzinfo-data
uglifier (>= 1.3.0)
web-console (~> 2.0)
BUNDLED WITH
1.12.5
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment