pyerualjetwork 2.7.8__py3-none-any.whl → 2.7.9__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
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
plan/plan.py CHANGED
@@ -2,7 +2,7 @@
2
2
  """
3
3
  Created on Tue Jun 18 23:32:16 2024
4
4
 
5
- @author: hasan
5
+ @author: hasan can
6
6
  """
7
7
 
8
8
  import pandas as pd
@@ -146,9 +146,12 @@ def fit(
146
146
 
147
147
  val_count += val_count_copy
148
148
 
149
- validation_model = evaluate(x_val, y_val, LTPW, activation_potentiation, None)
149
+ validation_model = evaluate(x_val, y_val, LTPW, activation_potentiation=activation_potentiation, show_metrices=None)
150
150
 
151
151
  val_acc = validation_model[get_acc()]
152
+ val_preds = validation_model[get_preds()]
153
+
154
+ plot_decision_space(x_val, val_preds, s=100, color='tab20')
152
155
 
153
156
  val_list.append(val_acc)
154
157
 
@@ -252,7 +255,7 @@ def fit(
252
255
  val_bar.update(val_acc)
253
256
 
254
257
  LTPW = normalization(LTPW)
255
-
258
+
256
259
  return LTPW
257
260
 
258
261
  # FUNCTIONS -----
@@ -485,23 +488,28 @@ def evaluate(
485
488
  Returns:
486
489
  tuple: A tuple containing the predicted labels and the accuracy of the model.
487
490
  """
491
+
492
+ predict_probabilitys = []
493
+ real_classes = []
494
+ predict_classes = []
495
+
488
496
  try:
489
497
  layers = ['fex']
490
498
 
491
499
  Wc = [0] * len(W) # Wc = Weight copy
492
500
  true = 0
493
- y_preds = [-1] * len(y_test)
501
+ y_preds = []
494
502
  acc_list = []
495
503
 
496
504
  for i, w in enumerate(W):
497
505
  Wc[i] = np.copy(w)
498
506
 
499
-
507
+
500
508
  if bar_status == True:
501
509
 
502
510
  test_progress = tqdm(total=len(x_test),leave=False, desc='Testing',ncols=120)
503
511
  acc_bar = tqdm(total=1, desc="Test Accuracy", ncols=120)
504
-
512
+
505
513
 
506
514
  for inpIndex, Input in enumerate(x_test):
507
515
  Input = np.array(Input)
@@ -516,15 +524,25 @@ def evaluate(
516
524
 
517
525
  for i, w in enumerate(Wc):
518
526
  W[i] = np.copy(w)
527
+
528
+ neural_layer = Softmax(neural_layer)
529
+ max_value = max(neural_layer)
530
+
531
+ predict_probabilitys.append(max_value)
532
+
533
+
519
534
  RealOutput = np.argmax(y_test[inpIndex])
535
+ real_classes.append(RealOutput)
520
536
  PredictedOutput = np.argmax(neural_layer)
537
+ predict_classes.append(PredictedOutput)
538
+
521
539
  if RealOutput == PredictedOutput:
522
540
  true += 1
523
541
  acc = true / len(y_test)
524
542
 
525
543
 
526
544
  acc_list.append(acc)
527
- y_preds[inpIndex] = PredictedOutput
545
+ y_preds.append(PredictedOutput)
528
546
 
529
547
  if bar_status == True:
530
548
  test_progress.update(1)
@@ -534,14 +552,14 @@ def evaluate(
534
552
  else:
535
553
  acc = acc - acc_list[inpIndex - 1]
536
554
  acc_bar.update(acc)
537
-
555
+
538
556
  if show_metrices == True:
539
- plot_evaluate(y_test, y_preds, acc_list)
557
+ plot_evaluate(x_test, y_test, y_preds, acc_list)
540
558
 
541
559
 
542
560
  for i, w in enumerate(Wc):
543
561
  W[i] = np.copy(w)
544
-
562
+
545
563
  except:
546
564
 
547
565
  print(Fore.RED + 'ERROR:' + infoTestModel + Style.RESET_ALL)
@@ -1055,7 +1073,6 @@ def synthetic_augmentation(x_train, y_train):
1055
1073
  classes = np.arange(y_train.shape[1])
1056
1074
  class_count = len(classes)
1057
1075
 
1058
- # Calculate class distribution
1059
1076
  class_distribution = {i: 0 for i in range(class_count)}
1060
1077
  for label in y:
1061
1078
  class_distribution[np.argmax(label)] += 1
@@ -1396,7 +1413,7 @@ def confusion_matrix(y_true, y_pred, class_count):
1396
1413
  return confusion
1397
1414
 
1398
1415
 
1399
- def plot_evaluate(y_test, y_preds, acc_list):
1416
+ def plot_evaluate(x_test, y_test, y_preds, acc_list):
1400
1417
 
1401
1418
  acc = acc_list[len(acc_list) - 1]
1402
1419
  y_true = decode_one_hot(y_test)
@@ -1479,42 +1496,89 @@ def plot_evaluate(y_test, y_preds, acc_list):
1479
1496
 
1480
1497
 
1481
1498
 
1482
- # Precision, Recall, F1 Score, Accuracy
1499
+
1483
1500
  metric = ['Precision', 'Recall', 'F1 Score', 'Accuracy']
1484
1501
  values = [precision, recall, f1, acc]
1485
1502
  colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728']
1486
1503
 
1487
- #
1504
+
1488
1505
  bars = axs[0, 1].bar(metric, values, color=colors)
1489
1506
 
1490
1507
 
1491
1508
  for bar, value in zip(bars, values):
1492
- axs[0, 1].text(bar.get_x() + bar.get_width() / 2, bar.get_height() - 0.05, f'{value:.2f}',
1509
+ axs[0, 1].text(bar.get_x() + bar.get_width() / 2, bar.get_height() - 0.05, f'{value:.2f}',
1493
1510
  ha='center', va='bottom', fontsize=12, color='white', weight='bold')
1494
1511
 
1495
- axs[0, 1].set_ylim(0, 1) # Y eksenini 0 ile 1 arasında sınırla
1512
+ axs[0, 1].set_ylim(0, 1)
1496
1513
  axs[0, 1].set_xlabel('Metrics')
1497
1514
  axs[0, 1].set_ylabel('Score')
1498
1515
  axs[0, 1].set_title('Precision, Recall, F1 Score, and Accuracy (Weighted)')
1499
1516
  axs[0, 1].grid(True, axis='y', linestyle='--', alpha=0.7)
1500
1517
 
1501
- # Accuracy
1502
- plt.plot(acc_list, marker='o', linestyle='-',
1503
- color='r', label='Accuracy')
1518
+
1519
+ if x_test.shape[1] > 2:
1520
+
1521
+ X_pca = pca(x_test, n_components=2)
1522
+ else:
1523
+ X_pca = x_test
1504
1524
 
1525
+ num_classes = len(y_test[0])
1505
1526
 
1506
- plt.axhline(y=1, color='g', linestyle='--', label='Maximum Accuracy')
1527
+
1528
+ cmap = plt.get_cmap('tab20')
1529
+
1530
+ 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)
1531
+ axs[1,1].set_title("Decision Space")
1532
+
1533
+ plt.show()
1534
+
1535
+ def pca(X, n_components):
1536
+ """
1537
+ PCA algoritmasını uygulayan fonksiyon.
1507
1538
 
1539
+ Parameters:
1540
+ X (numpy array): Giriş verisi (n_samples, n_features)
1541
+ n_components (int): Saklanacak ana bileşen sayısı
1508
1542
 
1509
- plt.xlabel('Samples')
1510
- plt.ylabel('Accuracy')
1511
- plt.title('Accuracy History')
1512
- plt.legend()
1543
+ Returns:
1544
+ X_reduced (numpy array): (n_samples, n_components)
1545
+ """
1513
1546
 
1547
+ X_meaned = X - np.mean(X, axis=0)
1514
1548
 
1515
- plt.tight_layout()
1516
- plt.show()
1549
+ covariance_matrix = np.cov(X_meaned, rowvar=False)
1550
+
1551
+ eigenvalues, eigenvectors = np.linalg.eigh(covariance_matrix)
1552
+
1553
+ sorted_index = np.argsort(eigenvalues)[::-1]
1554
+ sorted_eigenvectors = eigenvectors[:, sorted_index]
1555
+ sorted_eigenvalues = eigenvalues[sorted_index]
1556
+
1557
+ eigenvectors_subset = sorted_eigenvectors[:, :n_components]
1558
+
1559
+ X_reduced = np.dot(X_meaned, eigenvectors_subset)
1560
+
1561
+ return X_reduced
1562
+
1563
+ def plot_decision_space(x, y, s=100, color='tab20'):
1564
+
1565
+ if x.shape[1] > 2:
1566
+
1567
+ X_pca = pca(x, n_components=2)
1568
+ else:
1569
+ X_pca = x
1570
+
1571
+ num_classes = len(y[0])
1572
+
1573
+
1574
+ cmap = plt.get_cmap(color)
1517
1575
 
1576
+
1577
+ plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y, edgecolor='k', s=s, cmap=cmap, vmin=0, vmax=num_classes - 1)
1578
+ plt.title("Decision Space")
1579
+
1580
+ plt.draw()
1581
+
1518
1582
  def manuel_balancer(x_train, y_train, target_samples_per_class):
1519
1583
  """
1520
1584
  Generates synthetic examples to balance classes to the specified number of examples per class.
@@ -1,8 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 2.7.8
4
- Summary: Code improvements
3
+ Version: 2.7.9
4
+ Summary: Decision Space included in evaluate with plot_decision_space function
5
+ Home-page: UNKNOWN
5
6
  Author: Hasan Can Beydili
6
7
  Author-email: tchasancan@gmail.com
8
+ License: UNKNOWN
7
9
  Keywords: model evaluation,classifcation,potentiation learning artficial neural networks
10
+ Platform: UNKNOWN
11
+
12
+ UNKNOWN
8
13
 
@@ -0,0 +1,6 @@
1
+ plan/__init__.py,sha256=WStB_zoAADCWXzIqieDZo4frPQMEZzxXnRZ6QiQKSGY,523
2
+ plan/plan.py,sha256=mGYaNgbEjJKjBz9zCWG2weGBHQoIXDGF2Z6prL8xGq8,54466
3
+ pyerualjetwork-2.7.9.dist-info/METADATA,sha256=CqzPI6YYfXXC46C1RtmvYun29c1wxlIAX4rK37OtMzs,364
4
+ pyerualjetwork-2.7.9.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
5
+ pyerualjetwork-2.7.9.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
+ pyerualjetwork-2.7.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: bdist_wheel (0.42.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- plan/__init__.py,sha256=gmaz8lnQfl18MbOQwabBUPmShajK5S99jfyY-hQe8tc,502
2
- plan/plan.py,sha256=h1u6hk_wTjbCGkKhnAz6jidxTogmMTM2AEm7nxE9WQQ,52805
3
- pyerualjetwork-2.7.8.dist-info/METADATA,sha256=921fYXjv_44__3jjG8aZWt_iHE3I6rbNdHEar_vIDOw,244
4
- pyerualjetwork-2.7.8.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
5
- pyerualjetwork-2.7.8.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
6
- pyerualjetwork-2.7.8.dist-info/RECORD,,