Skip to content

Commit a54ea4f

Browse files
committed
Adding reference models and scripts
1 parent e89cc5b commit a54ea4f

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

iris_classification.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@
1414
network.setLearningRate(0.1)
1515

1616
datasetHandler = Dataset(inputs, outputs)
17-
datasetHandler.makeDataset('./datasets/Iris/inputs.csv', './datasets/Iris/targets.csv')
17+
datasetHandler.makeDataset(
18+
'./datasets/Iris/inputs.csv', './datasets/Iris/targets.csv')
1819
data, size = datasetHandler.getRawData()
20+
# data = datasetHandler.scaleData(data, size)
1921
data = shuffleArray(data)
2022
training, testing = splitArr(data, 3/4)
2123
# print(len(training))
2224

23-
network.Train(training, len(training), epochs=50, logging=False)
25+
network.Train(training, len(training), epochs=50,
26+
logging=False, epoch_logging=False)
2427
network.evaluate()
2528
network.epoch_vs_error()
2629

2730
network.export_model('iris_model.json')
2831

2932
correct = 0
3033
total = 0
31-
for sample in testing :
34+
for sample in testing:
3235
features = sample[0]
3336
prediction = network.predict(features)
3437
actual = sample[1]
@@ -53,4 +56,4 @@
5356
# if p == a:
5457
# correct += 1
5558
# total += 1
56-
# print("Testing accuracy:", correct*100/total)
59+
# print("Testing accuracy:", correct*100/total)

iris_model.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"inputs": 4, "outputs": 3, "learning_rate": 0.1, "model_compiled": true, "layers": [{"neurons": 8, "inputs": 4, "weights": [[-1.1980620842958467, -1.389382012392828, 1.911786285145301, 1.7971653361188404], [-0.6478860781629479, -0.6972618152122247, 1.3061556889962278, 1.060215432090661], [-0.16711924924669477, -0.6518478415051556, 1.0996154079672267, 0.8758895162836916], [0.7488954519190297, 0.2540011276686966, -0.6816784951361697, -1.4331584486694733], [-0.7427300571450691, -0.7696545916047017, 0.4532695813571135, -0.1136196968951569], [0.20063127778306603, 0.5971378264658889, 0.9410141726191932, 0.13261557606889532], [-0.8997704738453277, -0.43050178873053735, -0.06911451713237556, -0.28917576593408556], [0.6250745439907223, 0.15577864602078909, -0.7506188401886924, -0.6130664248923341]], "biases": [[-0.6837340721817232], [-1.2311556459304298], [-0.005601666836334101], [-0.8643126801658811], [0.7312618263744967], [0.5927198238582277], [1.09409252273032], [-0.7721608983489493]], "activation_function": "sigmoid", "loss_function": "ce"}, {"neurons": 8, "inputs": 8, "weights": [[1.0740567141916733, 0.8007959517444297, -0.16013479028747082, -0.014017550016047854, -0.7184391867105454, -0.08499913832540426, 1.0221587428266108, -0.10306856287300119], [2.7607088788866947, 1.7517215800565669, 1.62327870116138, -1.2649864096896335, 0.5402488179052224, 0.5410325468341485, 0.4064461070781744, -0.5314671314281104], [-1.9785062056498466, -1.423005667612357, 0.5087620552235044, 0.46325402271676624, 0.5935850278921626, 0.9233404066104838, 0.06691015007758673, -0.7089052198039452], [-0.21987390439018262, 1.39487886883591, 0.45192305044059156, -0.1361900489714228, -1.155160779916594, 0.9369442191611966, 0.21634409848212635, 0.18818589873579328], [-0.5469044900196581, 0.38126202343304033, -0.5169385235252806, -0.7618933977096171, -0.37644047927154195, 0.19253622497767148, -0.15928048641921333, -0.23474241623183909], [-0.6585056460445937, 0.19637687170109874, 0.8934420738152888, 0.7349197906003753, -0.4586439268463848, -0.5268100340654202, 0.6256292125799022, 0.19991534367841707], [1.7010380707191204, 1.8020992010684993, -0.3128704965544261, -0.7805275059088574, 0.07472283195240731, -1.1846556766435963, -0.0567189039993598, -1.2833454793551677], [-2.7139928619520703, -0.9765615881448066, -0.09062520778584218, 0.5266000790344398, 0.31600542985061747, 0.8051894728899316, -1.007191619136977, 0.7553030993954004]], "biases": [[-1.0361472924690331], [-1.1722830374245694], [0.23672953955968834], [0.6999927800669341], [-0.5451521134009342], [0.34419163175680817], [-0.06024632759381554], [0.7541453393343746]], "activation_function": "sigmoid", "loss_function": "ce"}, {"neurons": 3, "inputs": 8, "weights": [[-0.6488056653075827, -2.1075402675190293, 0.6550930561125179, 1.7694085726786453, 0.01298931240886752, 0.843447010152206, -1.038741226791736, 2.8691783202006667], [0.25480692136971356, 2.8649337358938083, -0.1485336217716044, 2.30566233382788, -0.37999705256121824, 1.5718757771460796, -0.21742294558241182, 0.36662175811645725], [1.191443996206231, 3.363958182886314, -2.408992252856717, 1.7085108189433695, -0.0877141514845476, -0.3990910464061441, 3.6926475874371727, -2.8072709030209286]], "biases": [[1.3753669594075901], [0.30357976466114983], [0.5937342866904095]], "activation_function": "softmax", "loss_function": "ce"}], "accuracy": 93.75, "loss": 0.22078055329470742, "epochs": 50}
1+
{"inputs": 4, "outputs": 3, "learning_rate": 0.1, "model_compiled": true, "layers": [{"neurons": 8, "inputs": 4, "weights": [[-1.0700415467408173, -0.47497148586320775, 0.5566798557421224, -0.7777828189500775], [-0.7696915887624413, -0.6140562071249159, 1.3346027317060487, 1.2731648745849191], [1.4078816365047142, 1.3682120544676533, -2.11854904186138, -1.6945022754603607], [1.1154631598441513, -0.5205210251936551, -1.2803910349270866, -0.13187163716764894], [0.22840784900252517, 0.510609105902735, 0.24978442116741506, 0.29387233657303347], [0.7137207517949101, -0.16867843340894764, 0.36859586125326244, -0.01704262145978384], [0.5629132916234478, 0.6236059804916765, -1.6602407127112768, -0.4306899397690986], [-0.5716383479690711, -0.06762030912963893, 0.24572896922479084, 0.20923602317216378]], "biases": [[1.543650228794593], [-0.32734036308443387], [-0.5098634899319852], [0.2837008561686969], [0.6030174507344979], [-0.4528485459814387], [0.5331247507626853], [-1.4909211603720176]], "activation_function": "sigmoid", "loss_function": "ce"}, {"neurons": 8, "inputs": 8, "weights": [[-0.3103020614721703, 0.2359898850158288, -0.19579465036701318, -0.13931391973107884, 0.5814076015225622, -0.20118122119185297, 0.6819492156091436, 0.10885428817433039], [0.6722899203006012, -0.6828462168876362, 1.6937475950838112, -0.08615093263777607, 0.5297781233937315, -0.00873924638356966, 0.4728922558298986, 0.22098978114308693], [-0.03392810025854064, 0.9474535480633547, -0.4421107150805129, 0.2379506493109156, -0.8509534004051296, -0.14686482127630396, 0.33407233898310434, -0.5573498132515291], [0.7990958823760101, 3.0681050521315956, -1.1463811320174448, 0.2093063865910252, 0.505295499994145, 1.3432161568148802, -1.8416773649380784, -0.5181459733152441], [0.16212913503833906, -1.324808597586848, 1.776882405757641, 1.5100673637863913, 0.09091979151925947, 0.5976227891637328, 0.581833243802584, -0.2796027117628177], [-0.30591837664341687, 1.3626129148581465, -1.2520457096326938, -0.3049554452708643, 0.33956052327254777, 0.11008974254848633, -1.2106294647198275, 0.6108264115662586], [-0.004606316639861943, -0.8413245849026534, 0.03340674652318518, -0.24447824475118646, -0.5533223691697795, 0.04335084900249471, 0.7899128729244218, -0.22468590281344913], [0.7206866796054288, 1.1935628723714242, -1.8135097102893083, -0.050427119242374134, 0.23985564043472832, 0.13802769633321715, -1.9432846967465447, -0.03319958858970644]], "biases": [[0.6451516504103487], [0.48326007715301683], [-0.17573714630671247], [-0.8406801951207137], [-0.6660117658886968], [-0.5328328746694961], [0.1345759812336772], [0.10239796721191217]], "activation_function": "sigmoid", "loss_function": "ce"}, {"neurons": 3, "inputs": 8, "weights": [[1.2159701404445373, 2.299662080571871, 0.6365187899128956, -2.878236613047107, 2.8008157787324737, -0.6967095518607164, 0.9397070930030599, -2.4358337700779233], [0.14998302941205818, 2.4700535098363154, -0.3529081536645115, 2.25806800403666, 2.59462561116815, -0.09328490701651128, -0.8705853201455316, -0.2802233472582158], [0.8011544961276745, 0.29300479635715526, 1.2345021477849762, 2.586892038683854, -0.9242527540352224, 2.3518896560672142, -0.1926806512213309, 2.328172597696618]], "biases": [[2.554599648079301], [1.506758891089483], [0.7402691886036927]], "activation_function": "softmax", "loss_function": "ce"}], "accuracy": 93.75, "loss": 0.22695972159351355, "epochs": 50}

usage.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import numpy as np
66

77
XOR_data = [
8-
[np.array([[0], [0]]), np.array([[0]])],
9-
[np.array([[0], [1]]), np.array([[1]])],
10-
[np.array([[1], [0]]), np.array([[1]])],
11-
[np.array([[1], [1]]), np.array([[0]])],
8+
(np.array([[0], [0]]), np.array([[0]])),
9+
(np.array([[0], [1]]), np.array([[1]])),
10+
(np.array([[1], [0]]), np.array([[1]])),
11+
(np.array([[1], [1]]), np.array([[0]])),
1212
]
1313

1414
size = 4

0 commit comments

Comments
 (0)