pyerualjetwork 2.8.1__py3-none-any.whl → 2.8.3__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 +1 -1
- plan/plan.py +92 -34
- {pyerualjetwork-2.8.1.dist-info → pyerualjetwork-2.8.3.dist-info}/METADATA +2 -2
- pyerualjetwork-2.8.3.dist-info/RECORD +6 -0
- pyerualjetwork-2.8.1.dist-info/RECORD +0 -6
- {pyerualjetwork-2.8.1.dist-info → pyerualjetwork-2.8.3.dist-info}/WHEEL +0 -0
- {pyerualjetwork-2.8.1.dist-info → pyerualjetwork-2.8.3.dist-info}/top_level.txt +0 -0
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_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
|
-
|
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
|
-
|
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
|
|
@@ -569,7 +571,7 @@ def evaluate(
|
|
569
571
|
W[i] = np.copy(w)
|
570
572
|
|
571
573
|
except:
|
572
|
-
|
574
|
+
|
573
575
|
print(Fore.RED + 'ERROR:' + infoTestModel + Style.RESET_ALL)
|
574
576
|
|
575
577
|
return W, y_preds, acc
|
@@ -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
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
except:
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
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
|
-
|
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
|
-
|
1530
|
+
X_pca = pca(x_test, n_components=2)
|
1530
1531
|
else:
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
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
|
-
|
1539
|
-
|
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
|
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.
|
1587
|
-
|
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
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
plan/__init__.py,sha256=SLgk4uuvhVr3CjscpcqN2TQMGyAd4Pe8YBiXfl3brd8,525
|
2
|
+
plan/plan.py,sha256=dh4sqKyS_KKw-bfsZb1EqfP5YeSvwbCNb0SC6Iz9ZTo,56255
|
3
|
+
pyerualjetwork-2.8.3.dist-info/METADATA,sha256=Yqg_Kxv3Y1cdJNWnbUz8OUSJGZqNIBzoQZvdysA5fYg,331
|
4
|
+
pyerualjetwork-2.8.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
5
|
+
pyerualjetwork-2.8.3.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
|
6
|
+
pyerualjetwork-2.8.3.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,,
|
File without changes
|
File without changes
|