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
72cdc309
Commit
72cdc309
authored
Apr 11, 2016
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed overflow errors in np.exp and changed iterations
parent
bb06cf28
Pipeline
#297
skipped
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
128 deletions
+131
-128
answer.txt
answer.txt
+120
-120
model2.py
model2.py
+11
-8
No files found.
answer.txt
View file @
72cdc309
...
...
@@ -2,7 +2,7 @@ Id,Label
0,0
1,1
2,1
3,
1
3,
0
4,0
5,0
6,0
...
...
@@ -12,17 +12,17 @@ Id,Label
10,1
11,1
12,0
13,
0
13,
1
14,1
15,0
16,1
17,
1
17,
0
18,0
19,0
20,0
21,0
22,0
23,
1
23,
0
24,0
25,1
26,0
...
...
@@ -38,16 +38,16 @@ Id,Label
36,0
37,1
38,0
39,
1
39,
0
40,0
41,1
42,
1
42,
0
43,1
44,0
45,0
46,0
47,0
48,
1
48,
0
49,0
50,1
51,0
...
...
@@ -55,7 +55,7 @@ Id,Label
53,0
54,1
55,1
56,
0
56,
1
57,0
58,1
59,1
...
...
@@ -66,13 +66,13 @@ Id,Label
64,0
65,1
66,0
67,
0
67,
1
68,0
69,0
70,1
71,0
72,0
73,
1
73,
0
74,1
75,0
76,1
...
...
@@ -83,7 +83,7 @@ Id,Label
81,0
82,0
83,0
84,
1
84,
0
85,1
86,0
87,1
...
...
@@ -93,7 +93,7 @@ Id,Label
91,1
92,0
93,0
94,
1
94,
0
95,0
96,1
97,0
...
...
@@ -102,8 +102,8 @@ Id,Label
100,1
101,0
102,0
103,
0
104,
1
103,
1
104,
0
105,1
106,1
107,0
...
...
@@ -114,8 +114,8 @@ Id,Label
112,1
113,1
114,0
115,
0
116,
0
115,
1
116,
1
117,0
118,1
119,0
...
...
@@ -125,7 +125,7 @@ Id,Label
123,0
124,0
125,1
126,
1
126,
0
127,1
128,0
129,0
...
...
@@ -156,7 +156,7 @@ Id,Label
154,0
155,1
156,0
157,
1
157,
0
158,0
159,0
160,1
...
...
@@ -178,7 +178,7 @@ Id,Label
176,1
177,1
178,0
179,
1
179,
0
180,0
181,0
182,1
...
...
@@ -214,9 +214,9 @@ Id,Label
212,0
213,0
214,0
215,
1
215,
0
216,1
217,
1
217,
0
218,1
219,0
220,0
...
...
@@ -250,7 +250,7 @@ Id,Label
248,0
249,1
250,1
251,
0
251,
1
252,1
253,0
254,1
...
...
@@ -260,9 +260,9 @@ Id,Label
258,1
259,1
260,1
261,
0
261,
1
262,0
263,
1
263,
0
264,0
265,1
266,1
...
...
@@ -281,7 +281,7 @@ Id,Label
279,0
280,1
281,0
282,
0
282,
1
283,0
284,1
285,1
...
...
@@ -312,7 +312,7 @@ Id,Label
310,1
311,1
312,0
313,
1
313,
0
314,0
315,0
316,1
...
...
@@ -346,7 +346,7 @@ Id,Label
344,1
345,1
346,0
347,
1
347,
0
348,0
349,0
350,0
...
...
@@ -383,9 +383,9 @@ Id,Label
381,0
382,0
383,0
384,
1
384,
0
385,1
386,
0
386,
1
387,0
388,0
389,0
...
...
@@ -398,8 +398,8 @@ Id,Label
396,1
397,0
398,0
399,
1
400,
1
399,
0
400,
0
401,1
402,0
403,0
...
...
@@ -431,12 +431,12 @@ Id,Label
429,0
430,0
431,0
432,
1
433,
1
432,
0
433,
0
434,1
435,0
436,1
437,
0
437,
1
438,0
439,0
440,0
...
...
@@ -449,7 +449,7 @@ Id,Label
447,0
448,1
449,0
450,
1
450,
0
451,1
452,1
453,1
...
...
@@ -458,28 +458,28 @@ Id,Label
456,0
457,0
458,1
459,
1
459,
0
460,1
461,0
462,1
463,1
464,0
465,
1
465,
0
466,1
467,1
468,1
469,0
470,
1
470,
0
471,1
472,0
473,1
474,
1
474,
0
475,0
476,0
477,0
478,1
479,1
480,
1
480,
0
481,1
482,0
483,0
...
...
@@ -509,14 +509,14 @@ Id,Label
507,1
508,0
509,0
510,
0
510,
1
511,0
512,0
513,0
514,0
515,0
516,1
517,
1
517,
0
518,0
519,1
520,1
...
...
@@ -528,9 +528,9 @@ Id,Label
526,1
527,0
528,0
529,
1
529,
0
530,0
531,
1
531,
0
532,1
533,0
534,1
...
...
@@ -539,7 +539,7 @@ Id,Label
537,1
538,0
539,0
540,
1
540,
0
541,0
542,0
543,0
...
...
@@ -556,18 +556,18 @@ Id,Label
554,0
555,0
556,1
557,
1
557,
0
558,0
559,0
560,0
561,1
562,1
563,0
564,
0
564,
1
565,0
566,1
567,0
568,
1
568,
0
569,0
570,0
571,1
...
...
@@ -580,7 +580,7 @@ Id,Label
578,0
579,0
580,0
581,
1
581,
0
582,1
583,0
584,1
...
...
@@ -590,7 +590,7 @@ Id,Label
588,1
589,0
590,1
591,
0
591,
1
592,1
593,0
594,0
...
...
@@ -598,12 +598,12 @@ Id,Label
596,0
597,0
598,0
599,
1
599,
0
600,1
601,1
602,
1
602,
0
603,0
604,
0
604,
1
605,0
606,0
607,0
...
...
@@ -622,7 +622,7 @@ Id,Label
620,0
621,0
622,0
623,
0
623,
1
624,1
625,0
626,0
...
...
@@ -652,13 +652,13 @@ Id,Label
650,0
651,0
652,1
653,
0
653,
1
654,1
655,0
656,1
657,0
658,0
659,
0
659,
1
660,1
661,0
662,0
...
...
@@ -676,7 +676,7 @@ Id,Label
674,0
675,1
676,1
677,
0
677,
1
678,0
679,1
680,0
...
...
@@ -691,7 +691,7 @@ Id,Label
689,0
690,0
691,0
692,
0
692,
1
693,0
694,0
695,1
...
...
@@ -716,11 +716,11 @@ Id,Label
714,0
715,0
716,0
717,
0
717,
1
718,0
719,0
720,1
721,
1
721,
0
722,1
723,0
724,0
...
...
@@ -728,7 +728,7 @@ Id,Label
726,1
727,1
728,1
729,
1
729,
0
730,0
731,0
732,1
...
...
@@ -759,7 +759,7 @@ Id,Label
757,0
758,1
759,1
760,
1
760,
0
761,0
762,1
763,0
...
...
@@ -768,8 +768,8 @@ Id,Label
766,0
767,0
768,1
769,
0
770,
1
769,
1
770,
0
771,1
772,0
773,1
...
...
@@ -785,18 +785,18 @@ Id,Label
783,0
784,0
785,1
786,
1
786,
0
787,0
788,1
789,0
790,
1
790,
0
791,0
792,1
793,0
794,1
795,0
796,0
797,
0
797,
1
798,0
799,1
800,0
...
...
@@ -827,7 +827,7 @@ Id,Label
825,0
826,1
827,0
828,
1
828,
0
829,1
830,0
831,1
...
...
@@ -895,7 +895,7 @@ Id,Label
893,0
894,1
895,0
896,
1
896,
0
897,1
898,0
899,0
...
...
@@ -919,7 +919,7 @@ Id,Label
917,0
918,1
919,1
920,
1
920,
0
921,0
922,0
923,0
...
...
@@ -927,24 +927,24 @@ Id,Label
925,1
926,0
927,1
928,
1
928,
0
929,0
930,1
931,1
932,0
933,0
934,
0
934,
1
935,1
936,0
937,1
938,
0
938,
1
939,0
940,
0
940,
1
941,0
942,1
943,0
944,1
945,
1
945,
0
946,0
947,1
948,1
...
...
@@ -961,7 +961,7 @@ Id,Label
959,0
960,0
961,0
962,
1
962,
0
963,0
964,0
965,1
...
...
@@ -995,13 +995,13 @@ Id,Label
993,0
994,0
995,1
996,
0
996,
1
997,0
998,0
999,0
1000,0
1001,
1
1002,
1
1001,
0
1002,
0
1003,0
1004,1
1005,0
...
...
@@ -1012,10 +1012,10 @@ Id,Label
1010,0
1011,0
1012,1
1013,
1
1013,
0
1014,1
1015,0
1016,
0
1016,
1
1017,0
1018,0
1019,1
...
...
@@ -1028,7 +1028,7 @@ Id,Label
1026,1
1027,1
1028,0
1029,
1
1029,
0
1030,0
1031,0
1032,1
...
...
@@ -1048,7 +1048,7 @@ Id,Label
1046,0
1047,1
1048,0
1049,
1
1049,
0
1050,1
1051,0
1052,0
...
...
@@ -1065,12 +1065,12 @@ Id,Label
1063,0
1064,0
1065,1
1066,
1
1066,
0
1067,0
1068,0
1069,0
1070,1
1071,
1
1071,
0
1072,0
1073,0
1074,1
...
...
@@ -1084,7 +1084,7 @@ Id,Label
1082,0
1083,1
1084,1
1085,
1
1085,
0
1086,1
1087,0
1088,1
...
...
@@ -1094,7 +1094,7 @@ Id,Label
1092,1
1093,0
1094,0
1095,
0
1095,
1
1096,0
1097,0
1098,1
...
...
@@ -1121,7 +1121,7 @@ Id,Label
1119,0
1120,0
1121,1
1122,
1
1122,
0
1123,0
1124,1
1125,1
...
...
@@ -1142,14 +1142,14 @@ Id,Label
1140,0
1141,1
1142,0
1143,
1
1144,
0
1143,
0
1144,
1
1145,0
1146,0
1147,0
1148,1
1149,0
1150,
1
1150,
0
1151,0
1152,1
1153,1
...
...
@@ -1160,7 +1160,7 @@ Id,Label
1158,1
1159,0
1160,1
1161,
0
1161,
1
1162,0
1163,0
1164,0
...
...
@@ -1168,7 +1168,7 @@ Id,Label
1166,1
1167,0
1168,0
1169,
0
1169,
1
1170,0
1171,1
1172,1
...
...
@@ -1189,7 +1189,7 @@ Id,Label
1187,0
1188,0
1189,0
1190,
1
1190,
0
1191,1
1192,0
1193,0
...
...
@@ -1205,7 +1205,7 @@ Id,Label
1203,1
1204,1
1205,1
1206,
0
1206,
1
1207,0
1208,1
1209,1
...
...
@@ -1213,10 +1213,10 @@ Id,Label
1211,1
1212,1
1213,1
1214,
1
1214,
0
1215,1
1216,0
1217,
0
1217,
1
1218,0
1219,1
1220,0
...
...
@@ -1226,8 +1226,8 @@ Id,Label
1224,1
1225,0
1226,1
1227,
1
1228,
1
1227,
0
1228,
0
1229,0
1230,0
1231,1
...
...
@@ -1247,9 +1247,9 @@ Id,Label
1245,0
1246,0
1247,0
1248,
0
1248,
1
1249,0
1250,
1
1250,
0
1251,0
1252,0
1253,1
...
...
@@ -1285,7 +1285,7 @@ Id,Label
1283,0
1284,0
1285,0
1286,
0
1286,
1
1287,0
1288,0
1289,1
...
...
@@ -1304,14 +1304,14 @@ Id,Label
1302,0
1303,0
1304,0
1305,
1
1305,
0
1306,0
1307,1
1308,1
1309,0
1310,1
1311,1
1312,
1
1312,
0
1313,0
1314,0
1315,0
...
...
@@ -1340,21 +1340,21 @@ Id,Label
1338,0
1339,1
1340,1
1341,
1
1341,
0
1342,1
1343,1
1344,0
1345,0
1346,0
1347,1
1348,
0
1348,
1
1349,1
1350,1
1351,1
1352,1
1353,0
1354,0
1355,
1
1355,
0
1356,1
1357,1
1358,0
...
...
@@ -1395,7 +1395,7 @@ Id,Label
1393,0
1394,0
1395,0
1396,
0
1396,
1
1397,0
1398,0
1399,1
...
...
@@ -1413,8 +1413,8 @@ Id,Label
1411,1
1412,0
1413,1
1414,
1
1415,
1
1414,
0
1415,
0
1416,1
1417,1
1418,0
...
...
@@ -1430,7 +1430,7 @@ Id,Label
1428,0
1429,1
1430,1
1431,
0
1431,
1
1432,0
1433,0
1434,1
...
...
@@ -1448,7 +1448,7 @@ Id,Label
1446,0
1447,0
1448,1
1449,
1
1449,
0
1450,0
1451,1
1452,0
...
...
@@ -1476,14 +1476,14 @@ Id,Label
1474,0
1475,1
1476,1
1477,
0
1477,
1
1478,1
1479,1
1480,0
1481,1
1482,0
1483,0
1484,
1
1484,
0
1485,0
1486,0
1487,1
...
...
@@ -1494,7 +1494,7 @@ Id,Label
1492,1
1493,0
1494,1
1495,
1
1495,
0
1496,1
1497,0
1498,0
...
...
@@ -1518,7 +1518,7 @@ Id,Label
1516,1
1517,1
1518,0
1519,
1
1519,
0
1520,0
1521,0
1522,1
...
...
@@ -1565,7 +1565,7 @@ Id,Label
1563,0
1564,1
1565,0
1566,
0
1566,
1
1567,1
1568,1
1569,0
...
...
@@ -1579,7 +1579,7 @@ Id,Label
1577,0
1578,0
1579,1
1580,
1
1580,
0
1581,0
1582,1
1583,1
...
...
@@ -1587,7 +1587,7 @@ Id,Label
1585,1
1586,0
1587,0
1588,
0
1588,
1
1589,1
1590,1
1591,1
...
...
@@ -1596,6 +1596,6 @@ Id,Label
1594,0
1595,1
1596,1
1597,
0
1597,
1
1598,0
1599,0
model2.py
View file @
72cdc309
...
...
@@ -42,7 +42,8 @@ def getData(srcF, isTrain=True, addBias=True, normalize=True):
return
(
np
.
array
(
X
),
np
.
array
(
y
))
def
sigmoid
(
v
):
return
1.0
/
(
1
+
np
.
exp
(
-
v
))
z
=
np
.
minimum
(
-
v
,
700.0
)
return
1
/
(
1
+
np
.
exp
(
z
))
def
sigmoidDiff
(
v
):
return
sigmoid
(
v
)
*
(
1
-
sigmoid
(
v
))
...
...
@@ -62,12 +63,13 @@ def restrictProb(a):
def
cost
(
model
,
X
,
y
):
m
=
X
.
shape
[
0
]
h
=
feedforward
(
model
,
X
)
h
=
np
.
minimum
(
np
.
maximum
(
h
,
1e-15
),
1
-
1e-15
)
y2
=
y
.
astype
(
float
)
vf
=
np
.
vectorize
(
restrictProb
)
py
=
vf
(
h
)
# vf = np.vectorize(restrictProb)
# py = vf(h)
loss
=
-
(
1.0
/
m
)
*
np
.
sum
(
y
*
np
.
log
(
py
)
+
(
1
-
y
)
*
np
.
log
(
1
-
py
))
#mx2 .* mx2
loss
=
-
(
1.0
/
m
)
*
np
.
sum
(
y
*
np
.
log
(
h
)
+
(
1
-
y
)
*
np
.
log
(
1
-
h
))
#mx2 .* mx2
#regularize
w1
,
w2
=
model
[
'w1'
],
model
[
'w2'
]
loss
+=
model
[
'lambda'
]
*
(
np
.
sum
(
np
.
square
(
w1
))
+
np
.
sum
(
np
.
square
(
w2
)))
/
(
2
*
m
)
...
...
@@ -90,7 +92,7 @@ def fit(model, X, y, passes=1000):
li
,
lh
,
lo
=
model
[
'li'
],
model
[
'lh'
],
model
[
'lo'
]
for
i
in
range
(
passes
):
z1
=
X
.
dot
(
w1
)
#mx58 * 58x28 = mx28
z1
=
X
.
dot
(
w1
)
#mx58 * 58x28 = mx28
a2
=
sigmoid
(
z1
)
#mx28
a2
=
np
.
insert
(
a2
,
0
,
np
.
ones
(
a2
.
shape
[
0
]),
axis
=
1
)
#mx29
z2
=
a2
.
dot
(
w2
)
#mx29 * 29x2
...
...
@@ -123,8 +125,9 @@ def fit(model, X, y, passes=1000):
if
__name__
==
"__main__"
:
np
.
random
.
seed
(
47
)
np
.
seterr
(
over
=
'raise'
)
model
=
{}
model
=
{
'li'
:
57
,
'lh'
:
85
,
'lo'
:
2
,
'lambda'
:
0.
05
,
'eta'
:
0.01
}
model
=
{
'li'
:
57
,
'lh'
:
85
,
'lo'
:
2
,
'lambda'
:
0.
1
,
'eta'
:
0.01
}
# model['w1'] = np.random.randn(model['li']+1, model['lh'])/np.sqrt(model['li']+1) #58x28
# model['w2'] = np.random.randn(model['lh']+1, model['lo'])/np.sqrt(model['lh']+1) #29x2
model
[
'w1'
]
=
np
.
random
.
rand
(
model
[
'li'
]
+
1
,
model
[
'lh'
])
*
0.24
-
0.12
...
...
@@ -139,7 +142,7 @@ if __name__ == "__main__":
# model['w1'] = np.random.randn(model['li']+1, model['lh'])/np.sqrt(model['li']+1) #58x28
# model['w2'] = np.random.randn(model['lh']+1, model['lo'])/np.sqrt(model['lh']+1) #29x2
model
=
fit
(
model
,
X
,
y
)
model
=
fit
(
model
,
X
,
y
,
passes
=
500
)
m
=
X
.
shape
[
0
]
py
,
y2
=
[],[]
...
...
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