Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mlassign2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sushant Mahajan
mlassign2
Commits
85b39497
Commit
85b39497
authored
Apr 09, 2016
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added prediction code, need to perform minimization
parent
e13e9135
Pipeline
#278
skipped
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
+24
-3
model.py
model.py
+24
-3
No files found.
model.py
View file @
85b39497
...
@@ -5,12 +5,21 @@ import csv
...
@@ -5,12 +5,21 @@ import csv
from
random
import
random
from
random
import
random
from
pprint
import
pprint
as
pp
from
pprint
import
pprint
as
pp
from
math
import
log
,
exp
from
math
import
log
,
exp
from
functools
import
reduce
import
numpy
as
np
import
numpy
as
np
params
=
{
"layers"
:[
57
,
int
(
57
/
2
),
1
],
"test"
:
"TestX.csv"
,
"train"
:
"Train.csv"
}
params
=
{
"layers"
:[
57
,
int
(
57
/
2
),
1
],
"test"
:
"TestX.csv"
,
"train"
:
"Train.csv"
}
def
getData
(
srcF
,
isTrain
=
True
,
addBias
=
True
):
def
doNormalize
(
X
):
#do 0 mean 1 std normalization
x1
=
np
.
array
(
X
,
dtype
=
float
)
for
i
in
range
(
len
(
X
[
0
])):
col
=
x1
[:,
i
]
mean
,
std
=
col
.
mean
(),
col
.
std
()
std
=
std
if
std
!=
0.0
else
1.0
x1
[:,
i
]
=
(
x1
[:,
i
]
-
mean
)
/
std
return
x1
.
tolist
()
def
getData
(
srcF
,
isTrain
=
True
,
addBias
=
True
,
normalize
=
True
):
X
,
y
=
[],[]
X
,
y
=
[],[]
with
open
(
srcF
)
as
src
:
with
open
(
srcF
)
as
src
:
reader
=
csv
.
reader
(
src
,
delimiter
=
','
)
reader
=
csv
.
reader
(
src
,
delimiter
=
','
)
...
@@ -27,6 +36,9 @@ def getData(srcF, isTrain=True, addBias=True):
...
@@ -27,6 +36,9 @@ def getData(srcF, isTrain=True, addBias=True):
if
isTrain
:
if
isTrain
:
y
.
append
(
int
(
row
[
-
1
]))
y
.
append
(
int
(
row
[
-
1
]))
if
normalize
:
X
=
doNormalize
(
X
)
#print(X[0])
return
(
X
,
y
)
return
(
X
,
y
)
def
sigmoid
(
v
):
def
sigmoid
(
v
):
...
@@ -87,10 +99,19 @@ def cost(li, lh, lo, weights, X, y, lamb):
...
@@ -87,10 +99,19 @@ def cost(li, lh, lo, weights, X, y, lamb):
grad
=
gradient
(
tdel1
,
tdel2
,
w1
.
reshape
((
lh
,
li
+
1
)),
w2
.
reshape
((
lo
,
lh
+
1
)),
lamb
,
m
)
grad
=
gradient
(
tdel1
,
tdel2
,
w1
.
reshape
((
lh
,
li
+
1
)),
w2
.
reshape
((
lo
,
lh
+
1
)),
lamb
,
m
)
return
J
,
grad
return
J
,
grad
def
predict
(
x
,
w1
,
w2
):
x
=
[
1
]
+
x
#58x1
x
=
np
.
array
(
x
)
h1
=
sigmoid
(
np
.
dot
(
w1
,
x
)
.
tolist
())
#28x58 * 58x1 = 28x1
h1
=
[
1
]
+
h1
h2
=
sigmoid
(
np
.
dot
(
w2
,
h1
)
.
tolist
())
#1x29 * 29x1 = 1x1
return
1
if
h2
>
0.5
else
0
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
X
,
y
=
getData
(
params
[
"train"
])
X
,
y
=
getData
(
params
[
"train"
])
#
tX,ty = getData(params["test"], isTrain=False)
tX
,
ty
=
getData
(
params
[
"test"
],
isTrain
=
False
)
# print(len(X), len(X[0]), len(y), X[0])
# print(len(X), len(X[0]), len(y), X[0])
# print(len(tX), len(ty), tX[0])
# print(len(tX), len(ty), tX[0])
li
,
lh
,
lo
=
tuple
(
params
[
"layers"
])
li
,
lh
,
lo
=
tuple
(
params
[
"layers"
])
...
...
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