pyerualjetwork 2.8.1__py3-none-any.whl → 2.8.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
plan/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  # Bu dosya, plan modülünün ana giriş noktasıdır.
4
4
 
5
- from .plan import auto_balancer, normalization, Softmax, Sigmoid, Relu, weight_identification, fex, fit, evaluate, save_model, load_model, predict_model_ssd, predict_model_ram, get_weights, get_df, get_preds, get_acc, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate, manuel_balancer, weight_normalization, plot_decision_space
5
+ from .plan import auto_balancer, normalization, Softmax, Sigmoid, Relu, weight_identification, fex, fit, evaluate, save_model, load_model, predict_model_ssd, predict_model_ram, get_weights, get_df, get_preds, get_acc, synthetic_augmentation, standard_scaler, multiple_evaluate, encode_one_hot, split, metrics, decode_one_hot, roc_curve, confusion_matrix, plot_evaluate, manuel_balancer, weight_normalization, plot_decision_boundry
plan/plan.py CHANGED
@@ -14,6 +14,7 @@ from scipy.special import expit, softmax
14
14
  import matplotlib.pyplot as plt
15
15
  import seaborn as sns
16
16
  from tqdm import tqdm
17
+ from scipy.spatial import ConvexHull
17
18
 
18
19
  # BUILD -----
19
20
 
@@ -150,8 +151,9 @@ def fit(
150
151
  val_acc = validation_model[get_acc()]
151
152
  val_preds = validation_model[get_preds()]
152
153
 
154
+ plt.clf()
153
155
 
154
- plot_decision_space(x_val, val_preds, s=100, color='tab20')
156
+ plot_decision_boundry(x_val, y_val, y_preds=val_preds, s=100, color='tab20')
155
157
 
156
158
 
157
159
  plt.pause(0.0001)
@@ -255,7 +257,7 @@ def fit(
255
257
  val_preds = validation_model[get_preds()]
256
258
 
257
259
 
258
- plot_decision_space(x_val, val_preds, s=100, color='tab20')
260
+ plot_decision_boundry(x_val, y_val, y_preds=val_preds, s=100, color='tab20')
259
261
 
260
262
  val_list.append(val_acc)
261
263
 
@@ -501,76 +503,76 @@ def evaluate(
501
503
  real_classes = []
502
504
  predict_classes = []
503
505
 
504
- try:
505
- layers = ['fex']
506
-
507
- Wc = [0] * len(W) # Wc = Weight copy
508
- true = 0
509
- y_preds = []
510
- acc_list = []
511
-
512
- for i, w in enumerate(W):
513
- Wc[i] = np.copy(w)
514
-
515
-
516
- if bar_status == True:
506
+ #try:
507
+ layers = ['fex']
517
508
 
518
- test_progress = tqdm(total=len(x_test),leave=False, desc='Testing',ncols=120)
519
- acc_bar = tqdm(total=1, desc="Test Accuracy", ncols=120)
520
-
509
+ Wc = [0] * len(W) # Wc = Weight copy
510
+ true = 0
511
+ y_preds = []
512
+ acc_list = []
513
+
514
+ for i, w in enumerate(W):
515
+ Wc[i] = np.copy(w)
521
516
 
522
- for inpIndex, Input in enumerate(x_test):
523
- Input = np.array(Input)
524
- Input = Input.ravel()
525
- neural_layer = Input
517
+
518
+ if bar_status == True:
526
519
 
527
- for index, Layer in enumerate(layers):
520
+ test_progress = tqdm(total=len(x_test),leave=False, desc='Testing',ncols=120)
521
+ acc_bar = tqdm(total=1, desc="Test Accuracy", ncols=120)
522
+
523
+
524
+ for inpIndex, Input in enumerate(x_test):
525
+ Input = np.array(Input)
526
+ Input = Input.ravel()
527
+ neural_layer = Input
528
528
 
529
- if Layer == 'fex':
530
- neural_layer = fex(neural_layer, W[index], False, None, activation_potentiation)
529
+ for index, Layer in enumerate(layers):
531
530
 
531
+ if Layer == 'fex':
532
+ neural_layer = fex(neural_layer, W[index], False, None, activation_potentiation)
532
533
 
533
- for i, w in enumerate(Wc):
534
- W[i] = np.copy(w)
535
-
536
- neural_layer = Softmax(neural_layer)
537
- max_value = max(neural_layer)
538
534
 
539
- predict_probabilitys.append(max_value)
540
-
535
+ for i, w in enumerate(Wc):
536
+ W[i] = np.copy(w)
541
537
 
542
- RealOutput = np.argmax(y_test[inpIndex])
543
- real_classes.append(RealOutput)
544
- PredictedOutput = np.argmax(neural_layer)
545
- predict_classes.append(PredictedOutput)
538
+ neural_layer = Softmax(neural_layer)
539
+ max_value = max(neural_layer)
546
540
 
547
- if RealOutput == PredictedOutput:
548
- true += 1
549
- acc = true / len(y_test)
541
+ predict_probabilitys.append(max_value)
542
+
543
+
544
+ RealOutput = np.argmax(y_test[inpIndex])
545
+ real_classes.append(RealOutput)
546
+ PredictedOutput = np.argmax(neural_layer)
547
+ predict_classes.append(PredictedOutput)
550
548
 
549
+ if RealOutput == PredictedOutput:
550
+ true += 1
551
+ acc = true / len(y_test)
551
552
 
552
- acc_list.append(acc)
553
- y_preds.append(PredictedOutput)
554
-
555
- if bar_status == True:
556
- test_progress.update(1)
557
- if inpIndex == 0:
558
- acc_bar.update(acc)
559
-
560
- else:
561
- acc = acc - acc_list[inpIndex - 1]
562
- acc_bar.update(acc)
563
-
564
- if show_metrices == True:
565
- plot_evaluate(x_test, y_test, y_preds, acc_list)
566
-
553
+
554
+ acc_list.append(acc)
555
+ y_preds.append(PredictedOutput)
567
556
 
568
- for i, w in enumerate(Wc):
569
- W[i] = np.copy(w)
557
+ if bar_status == True:
558
+ test_progress.update(1)
559
+ if inpIndex == 0:
560
+ acc_bar.update(acc)
561
+
562
+ else:
563
+ acc = acc - acc_list[inpIndex - 1]
564
+ acc_bar.update(acc)
570
565
 
571
- except:
566
+ if show_metrices == True:
567
+ plot_evaluate(x_test, y_test, y_preds, acc_list)
572
568
 
573
- print(Fore.RED + 'ERROR:' + infoTestModel + Style.RESET_ALL)
569
+
570
+ for i, w in enumerate(Wc):
571
+ W[i] = np.copy(w)
572
+
573
+ #except:
574
+
575
+ #print(Fore.RED + 'ERROR:' + infoTestModel + Style.RESET_ALL)
574
576
 
575
577
  return W, y_preds, acc
576
578
 
@@ -997,21 +999,21 @@ def predict_model_ram(Input, W, scaler_params=None, activation_potentiation=None
997
999
  Wc = [0] * len(W)
998
1000
  for i, w in enumerate(W):
999
1001
  Wc[i] = np.copy(w)
1000
- try:
1001
- neural_layer = Input
1002
- neural_layer = np.array(neural_layer)
1003
- neural_layer = neural_layer.ravel()
1004
- for index, Layer in enumerate(layers):
1005
-
1006
- if Layer == 'fex':
1007
- neural_layer = fex(neural_layer, W[index], False, None, activation_potentiation)
1008
- elif Layer == 'cat':
1009
- neural_layer = np.dot(W[index], neural_layer)
1010
-
1011
- except:
1012
- print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: predict_model_ram." +
1013
- infopredict_model_ram + Style.RESET_ALL)
1014
- return 'e'
1002
+ #try:
1003
+ neural_layer = Input
1004
+ neural_layer = np.array(neural_layer)
1005
+ neural_layer = neural_layer.ravel()
1006
+ for index, Layer in enumerate(layers):
1007
+
1008
+ if Layer == 'fex':
1009
+ neural_layer = fex(neural_layer, W[index], False, None, activation_potentiation)
1010
+ elif Layer == 'cat':
1011
+ neural_layer = np.dot(W[index], neural_layer)
1012
+
1013
+ """ except:
1014
+ print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: predict_model_ram." +
1015
+ infopredict_model_ram + Style.RESET_ALL)
1016
+ return 'e'"""
1015
1017
  for i, w in enumerate(Wc):
1016
1018
  W[i] = np.copy(w)
1017
1019
  return neural_layer
@@ -1423,6 +1425,7 @@ def confusion_matrix(y_true, y_pred, class_count):
1423
1425
 
1424
1426
  def plot_evaluate(x_test, y_test, y_preds, acc_list):
1425
1427
 
1428
+
1426
1429
  acc = acc_list[len(acc_list) - 1]
1427
1430
  y_true = decode_one_hot(y_test)
1428
1431
 
@@ -1433,11 +1436,9 @@ def plot_evaluate(x_test, y_test, y_preds, acc_list):
1433
1436
  precision, recall, f1 = metrics(y_test, y_preds)
1434
1437
 
1435
1438
 
1436
- # Confusion matrix
1437
1439
  cm = confusion_matrix(y_true, y_preds, len(Class))
1438
1440
  fig, axs = plt.subplots(2, 2, figsize=(16, 12))
1439
-
1440
- # Confusion Matrix
1441
+
1441
1442
  sns.heatmap(cm, annot=True, fmt='d', ax=axs[0, 0])
1442
1443
  axs[0, 0].set_title("Confusion Matrix")
1443
1444
  axs[0, 0].set_xlabel("Predicted Class")
@@ -1445,7 +1446,7 @@ def plot_evaluate(x_test, y_test, y_preds, acc_list):
1445
1446
 
1446
1447
  if len(Class) == 2:
1447
1448
  fpr, tpr, thresholds = roc_curve(y_true, y_preds)
1448
- # ROC Curve
1449
+
1449
1450
  roc_auc = np.trapz(tpr, fpr)
1450
1451
  axs[1, 0].plot(fpr, tpr, color='darkorange', lw=2, label=f'ROC curve (area = {roc_auc:.2f})')
1451
1452
  axs[1, 0].plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
@@ -1523,21 +1524,50 @@ def plot_evaluate(x_test, y_test, y_preds, acc_list):
1523
1524
  axs[0, 1].set_title('Precision, Recall, F1 Score, and Accuracy (Weighted)')
1524
1525
  axs[0, 1].grid(True, axis='y', linestyle='--', alpha=0.7)
1525
1526
 
1526
-
1527
+
1527
1528
  if x_test.shape[1] > 2:
1528
1529
 
1529
- X_pca = pca(x_test, n_components=2)
1530
+ X_pca = pca(x_test, n_components=2)
1530
1531
  else:
1531
- X_pca = x_test
1532
-
1533
- num_classes = len(y_test[0])
1532
+ X_pca = x_test
1533
+
1534
+ y_test = decode_one_hot(y_test)
1535
+ num_classes = len(np.unique(y_test))
1534
1536
 
1535
1537
 
1536
1538
  cmap = plt.get_cmap('tab20')
1537
1539
 
1538
- axs[1,1].scatter(X_pca[:, 0], X_pca[:, 1], c=y_preds, edgecolor='k', s=100, cmap=cmap, vmin=0, vmax=num_classes - 1)
1539
- axs[1,1].set_title("Decision Space")
1540
-
1540
+
1541
+
1542
+ norm = plt.Normalize(vmin=0, vmax=num_classes - 1)
1543
+
1544
+
1545
+ scatter = axs[1, 1].scatter(X_pca[:, 0], X_pca[:, 1], c=y_test, edgecolor='k', s=50, cmap=cmap, norm=norm)
1546
+
1547
+
1548
+ for cls in range(num_classes):
1549
+ class_points = []
1550
+
1551
+
1552
+ for i in range(len(y_test)):
1553
+ if y_preds[i] == cls:
1554
+ class_points.append(X_pca[i])
1555
+
1556
+ class_points = np.array(class_points)
1557
+
1558
+ if len(class_points) > 2:
1559
+ hull = ConvexHull(class_points)
1560
+ hull_points = class_points[hull.vertices]
1561
+
1562
+
1563
+ hull_points = np.vstack([hull_points, hull_points[0]])
1564
+
1565
+
1566
+ axs[1, 1].fill(hull_points[:, 0], hull_points[:, 1], color=cmap(norm(cls)), alpha=0.3, edgecolor='k', label=f'Class {cls} Hull')
1567
+
1568
+
1569
+ axs[1, 1].set_title("Decision Boundry")
1570
+
1541
1571
  plt.show()
1542
1572
 
1543
1573
  def pca(X, n_components):
@@ -1568,7 +1598,7 @@ def pca(X, n_components):
1568
1598
 
1569
1599
  return X_reduced
1570
1600
 
1571
- def plot_decision_space(x, y, s=100, color='tab20'):
1601
+ def plot_decision_boundry(x, y, y_preds=None, s=100, color='tab20'):
1572
1602
 
1573
1603
  if x.shape[1] > 2:
1574
1604
 
@@ -1576,15 +1606,43 @@ def plot_decision_space(x, y, s=100, color='tab20'):
1576
1606
  else:
1577
1607
  X_pca = x
1578
1608
 
1609
+ if y_preds == None:
1610
+ y_preds = y
1611
+
1579
1612
 
1613
+ y = decode_one_hot(y)
1580
1614
  num_classes = len(np.unique(y))
1581
1615
 
1582
-
1583
1616
  cmap = plt.get_cmap(color)
1584
1617
 
1585
1618
 
1586
- plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y, edgecolor='k', s=s, cmap=cmap, vmin=0, vmax=num_classes - 1)
1587
- plt.title("Decision Space")
1619
+ norm = plt.Normalize(vmin=0, vmax=num_classes - 1)
1620
+
1621
+
1622
+ scatter = plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y, edgecolor='k', s=50, cmap=cmap, norm=norm)
1623
+
1624
+
1625
+ for cls in range(num_classes):
1626
+
1627
+ class_points = []
1628
+
1629
+
1630
+ for i in range(len(y)):
1631
+ if y_preds[i] == cls:
1632
+ class_points.append(X_pca[i])
1633
+
1634
+ class_points = np.array(class_points)
1635
+
1636
+
1637
+ if len(class_points) > 2:
1638
+ hull = ConvexHull(class_points)
1639
+ hull_points = class_points[hull.vertices]
1640
+
1641
+ hull_points = np.vstack([hull_points, hull_points[0]])
1642
+
1643
+ plt.fill(hull_points[:, 0], hull_points[:, 1], color=cmap(norm(cls)), alpha=0.3, edgecolor='k', label=f'Class {cls} Hull')
1644
+
1645
+ plt.title("Decision Boundry")
1588
1646
 
1589
1647
  plt.draw()
1590
1648
 
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 2.8.1
4
- Summary: Code improvoments
3
+ Version: 2.8.2
4
+ Summary: plot_decision_boundry function added
5
5
  Home-page: UNKNOWN
6
6
  Author: Hasan Can Beydili
7
7
  Author-email: tchasancan@gmail.com
@@ -0,0 +1,6 @@
1
+ plan/__init__.py,sha256=SLgk4uuvhVr3CjscpcqN2TQMGyAd4Pe8YBiXfl3brd8,525
2
+ plan/plan.py,sha256=DUNmfjy81eQBB2gtQDLxOpTio7d8i5-H3VbietxVO-Y,56026
3
+ pyerualjetwork-2.8.2.dist-info/METADATA,sha256=YuQspdVsLubSt0LaA5vLv_tzp7Q7WzjOcvWtzK4YtP4,331
4
+ pyerualjetwork-2.8.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
5
+ pyerualjetwork-2.8.2.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
+ pyerualjetwork-2.8.2.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- plan/__init__.py,sha256=WStB_zoAADCWXzIqieDZo4frPQMEZzxXnRZ6QiQKSGY,523
2
- plan/plan.py,sha256=x2sLhTt97E2lclfsBKFexvLEAgPUfH8uPc2hg9ggpUM,54731
3
- pyerualjetwork-2.8.1.dist-info/METADATA,sha256=pgJXu2Fbh7ItUXFke792-D_zvGxU7Y8JB_1XnPaLwYI,312
4
- pyerualjetwork-2.8.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
5
- pyerualjetwork-2.8.1.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
- pyerualjetwork-2.8.1.dist-info/RECORD,,