pyerualjetwork 4.2.2b0__py3-none-any.whl → 4.2.2b1__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.
- pyerualjetwork/__init__.py +1 -1
- pyerualjetwork/deneme.py +171 -0
- pyerualjetwork/memory_operations.py +1 -1
- pyerualjetwork/plan_cuda.py +0 -1
- {pyerualjetwork-4.2.2b0.dist-info → pyerualjetwork-4.2.2b1.dist-info}/METADATA +1 -1
- {pyerualjetwork-4.2.2b0.dist-info → pyerualjetwork-4.2.2b1.dist-info}/RECORD +8 -7
- {pyerualjetwork-4.2.2b0.dist-info → pyerualjetwork-4.2.2b1.dist-info}/WHEEL +0 -0
- {pyerualjetwork-4.2.2b0.dist-info → pyerualjetwork-4.2.2b1.dist-info}/top_level.txt +0 -0
pyerualjetwork/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "4.2.
|
1
|
+
__version__ = "4.2.2b1"
|
2
2
|
__update__ = "* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES\n* PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main\n* PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf\n* YouTube tutorials: https://www.youtube.com/@HasanCanBeydili"
|
3
3
|
|
4
4
|
def print_version(__version__):
|
pyerualjetwork/deneme.py
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
Created on Thu Jun 20 03:55:15 2024
|
4
|
+
|
5
|
+
@author: hasan
|
6
|
+
"""
|
7
|
+
|
8
|
+
import numpy as np
|
9
|
+
from colorama import Fore
|
10
|
+
from pyerualjetwork import plan, planeat, data_operations, model_operations
|
11
|
+
from sklearn.linear_model import LogisticRegression
|
12
|
+
from sklearn.ensemble import RandomForestClassifier
|
13
|
+
import xgboost as xgb
|
14
|
+
import tensorflow as tf
|
15
|
+
from tensorflow.keras.models import Sequential
|
16
|
+
from tensorflow.keras.layers import Dense
|
17
|
+
from tensorflow.keras.optimizers import RMSprop
|
18
|
+
from sklearn.metrics import classification_report, accuracy_score
|
19
|
+
from sklearn.datasets import make_blobs
|
20
|
+
from matplotlib import pyplot as plt
|
21
|
+
|
22
|
+
fig, ax = plt.subplots(2, 3) # Create a new figure and axe
|
23
|
+
|
24
|
+
# Karar sınırı çizimi
|
25
|
+
def plot_decision_boundary(x, y, model, feature_indices=[0, 1], h=0.02, model_name='str', ax=None, which_ax1=None, which_ax2=None, W=None, activation_potentiation=None):
|
26
|
+
"""
|
27
|
+
Plot decision boundary by focusing on specific feature indices.
|
28
|
+
|
29
|
+
Parameters:
|
30
|
+
- x: Input data
|
31
|
+
- y: Target labels
|
32
|
+
- model: Trained model
|
33
|
+
- feature_indices: Indices of the features to plot (default: [0, 1])
|
34
|
+
- h: Step size for the mesh grid
|
35
|
+
"""
|
36
|
+
x_min, x_max = x[:, feature_indices[0]].min() - 1, x[:, feature_indices[0]].max() + 1
|
37
|
+
y_min, y_max = x[:, feature_indices[1]].min() - 1, x[:, feature_indices[1]].max() + 1
|
38
|
+
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
|
39
|
+
np.arange(y_min, y_max, h))
|
40
|
+
|
41
|
+
grid = np.c_[xx.ravel(), yy.ravel()]
|
42
|
+
|
43
|
+
# Create a full grid with zeros for non-selected features
|
44
|
+
grid_full = np.zeros((grid.shape[0], x.shape[1]))
|
45
|
+
grid_full[:, feature_indices] = grid
|
46
|
+
|
47
|
+
if model == 'PLAN':
|
48
|
+
|
49
|
+
Z = [None] * len(grid_full)
|
50
|
+
|
51
|
+
for i in range(len(grid_full)):
|
52
|
+
Z[i] = np.argmax(model_operations.predict_model_ram(grid_full[i], W=W, activation_potentiation=activation_potentiation))
|
53
|
+
|
54
|
+
Z = np.array(Z)
|
55
|
+
Z = Z.reshape(xx.shape)
|
56
|
+
|
57
|
+
else:
|
58
|
+
|
59
|
+
# Predict on the grid
|
60
|
+
#for i in range(len(grid_full)): grid_full[i] = activation_functions.apply_activation(grid_full[i], ['tanh', 'relu', 'elu', 'selu'])
|
61
|
+
Z = model.predict(grid_full)
|
62
|
+
|
63
|
+
if model_name == 'Deep Learning':
|
64
|
+
Z = np.argmax(Z, axis=1) # Get class predictions
|
65
|
+
|
66
|
+
Z = Z.reshape(xx.shape)
|
67
|
+
|
68
|
+
# Plot decision boundary
|
69
|
+
ax[which_ax1, which_ax2].contourf(xx, yy, Z, alpha=0.8)
|
70
|
+
ax[which_ax1, which_ax2].scatter(x[:, feature_indices[0]], x[:, feature_indices[1]], c=np.argmax(y, axis=1), edgecolors='k', marker='o', s=20, alpha=0.9)
|
71
|
+
ax[which_ax1, which_ax2].set_xlabel(f'Feature {feature_indices[0] + 1}')
|
72
|
+
ax[which_ax1, which_ax2].set_ylabel(f'Feature {feature_indices[1] + 1}')
|
73
|
+
ax[which_ax1, which_ax2].set_title(model_name)
|
74
|
+
|
75
|
+
|
76
|
+
X, y = make_blobs(n_samples=1000, centers=5, random_state=42)
|
77
|
+
|
78
|
+
# Eğitim, test ve doğrulama verilerini ayırma
|
79
|
+
x_train, x_test, y_train, y_test = data_operations.split(X, y, test_size=0.4, random_state=42) # For less train data use this: (X, y, test_size=0.9, random_state=42)
|
80
|
+
|
81
|
+
# One-hot encoding işlemi
|
82
|
+
y_train, y_test = data_operations.encode_one_hot(y_train, y_test)
|
83
|
+
|
84
|
+
|
85
|
+
# Veri dengesizliği durumunu otomatik dengeleme
|
86
|
+
x_train, y_train = data_operations.auto_balancer(x_train, y_train)
|
87
|
+
scaler_params, x_train, x_test = data_operations.standard_scaler(x_train, x_test)
|
88
|
+
|
89
|
+
# Lojistik Regresyon Modeli
|
90
|
+
print(Fore.YELLOW + "------Lojistik Regresyon Sonuçları------" + Fore.RESET)
|
91
|
+
lr_model = LogisticRegression(max_iter=1000, random_state=42)
|
92
|
+
y_train_decoded = data_operations.decode_one_hot(y_train)
|
93
|
+
lr_model.fit(x_train, y_train_decoded)
|
94
|
+
|
95
|
+
y_test_decoded = plan.decode_one_hot(y_test)
|
96
|
+
y_pred_lr = lr_model.predict(x_test)
|
97
|
+
test_acc_lr = accuracy_score(y_test_decoded, y_pred_lr)
|
98
|
+
print(f"Lojistik Regresyon Test Accuracy: {test_acc_lr:.4f}")
|
99
|
+
print(classification_report(y_test_decoded, y_pred_lr))
|
100
|
+
# Karar sınırını görselleştir
|
101
|
+
plot_decision_boundary(x_test, y_test, lr_model, feature_indices=[0, 1], model_name='Logistic Regression', ax=ax, which_ax1=0, which_ax2=0)
|
102
|
+
|
103
|
+
# Random Forest Modeli
|
104
|
+
print(Fore.CYAN + "------Random Forest Sonuçları------" + Fore.RESET)
|
105
|
+
rf_model = RandomForestClassifier(n_estimators=100, random_state=42)
|
106
|
+
rf_model.fit(x_train, y_train_decoded)
|
107
|
+
y_pred_rf = rf_model.predict(x_test)
|
108
|
+
test_acc_rf = accuracy_score(y_test_decoded, y_pred_rf)
|
109
|
+
print(f"Random Forest Test Accuracy: {test_acc_rf:.4f}")
|
110
|
+
print(classification_report(y_test_decoded, y_pred_rf))
|
111
|
+
# Karar sınırını görselleştir
|
112
|
+
plot_decision_boundary(x_test, y_test, rf_model, feature_indices=[0, 1], model_name='Random Forest', ax=ax, which_ax1=0, which_ax2=1)
|
113
|
+
|
114
|
+
# XGBoost Modeli
|
115
|
+
print(Fore.MAGENTA + "------XGBoost Sonuçları------" + Fore.RESET)
|
116
|
+
xgb_model = xgb.XGBClassifier(use_label_encoder=False, eval_metric='mlogloss', random_state=42)
|
117
|
+
xgb_model.fit(x_train, y_train_decoded)
|
118
|
+
y_pred_xgb = xgb_model.predict(x_test)
|
119
|
+
test_acc_xgb = accuracy_score(y_test_decoded, y_pred_xgb)
|
120
|
+
print(f"XGBoost Test Accuracy: {test_acc_xgb:.4f}")
|
121
|
+
print(classification_report(y_test_decoded, y_pred_xgb))
|
122
|
+
# Karar sınırını görselleştir
|
123
|
+
plot_decision_boundary(x_test, y_test, xgb_model, feature_indices=[0, 1], model_name='XGBoost', ax=ax, which_ax1=0, which_ax2=2)
|
124
|
+
|
125
|
+
# Derin Öğrenme Modeli (Yapay Sinir Ağı)
|
126
|
+
|
127
|
+
input_dim = x_train.shape[1] # Giriş boyutu
|
128
|
+
|
129
|
+
|
130
|
+
model = Sequential()
|
131
|
+
model.add(Dense(32, activation='relu', input_dim=input_dim))
|
132
|
+
model.add(Dense(64, activation='tanh'))
|
133
|
+
model.add(Dense(32, activation='relu'))
|
134
|
+
model.add(Dense(64, activation='tanh'))
|
135
|
+
model.add(Dense(y_train.shape[1], activation='softmax'))
|
136
|
+
|
137
|
+
# Model derlemesi
|
138
|
+
model.compile(optimizer=RMSprop(), loss='binary_crossentropy', metrics=['accuracy'])
|
139
|
+
|
140
|
+
# Model eğitimi (early stopping ile)
|
141
|
+
early_stop = tf.keras.callbacks.EarlyStopping(monitor='loss', patience=10, restore_best_weights=True)
|
142
|
+
model.fit(x_train, y_train, epochs=5, batch_size=32, callbacks=[early_stop], verbose=1)
|
143
|
+
|
144
|
+
# Test verileri üzerinde modelin performansını değerlendirme
|
145
|
+
y_pred_dl = model.predict(x_test)
|
146
|
+
y_pred_dl_classes = np.argmax(y_pred_dl, axis=1) # Tahmin edilen sınıflar
|
147
|
+
y_test_decoded_dl = plan.decode_one_hot(y_test)
|
148
|
+
print(Fore.BLUE + "------Derin Öğrenme (ANN) Sonuçları------" + Fore.RESET)
|
149
|
+
test_acc_dl = accuracy_score(y_test_decoded_dl, y_pred_dl_classes)
|
150
|
+
print(f"Derin Öğrenme Test Accuracy: {test_acc_dl:.4f}")
|
151
|
+
print(classification_report(y_test_decoded_dl, y_pred_dl_classes))
|
152
|
+
# Karar sınırını görselleştir
|
153
|
+
plot_decision_boundary(x_test, y_test, model=model, feature_indices=[0, 1], model_name='Deep Learning', ax=ax, which_ax1=1, which_ax2=0)
|
154
|
+
|
155
|
+
# PLAN Modeli
|
156
|
+
# Configuring optimizer
|
157
|
+
genetic_optimizer = lambda *args, **kwargs: planeat.evolver(*args, **kwargs)
|
158
|
+
|
159
|
+
model = plan.learner(x_train, y_train, genetic_optimizer, batch_size=0.05, gen=15) # learner function = TFL(Test Feedback Learning). If test parameters not given then uses Train Feedback. More information: https://github.com/HCB06/pyerualjetwork/blob/main/Welcome_to_PLAN/PLAN.pdf
|
160
|
+
|
161
|
+
W = model[model_operations.get_weights()]
|
162
|
+
activation_potentiation = model[model_operations.get_act_pot()]
|
163
|
+
|
164
|
+
test_model = plan.evaluate(x_test, y_test, W=W, activation_potentiation=activation_potentiation)
|
165
|
+
test_acc_plan = test_model[model_operations.get_acc()]
|
166
|
+
print(Fore.GREEN + "------PLAN Modeli Sonuçları------" + Fore.RESET)
|
167
|
+
print(f"PLAN Test Accuracy: {test_acc_plan:.4f}")
|
168
|
+
print(classification_report(plan.decode_one_hot(y_test), test_model[model_operations.get_preds()]))
|
169
|
+
# Karar sınırını görselleştir
|
170
|
+
plot_decision_boundary(x_test, y_test, model='PLAN', feature_indices=[0, 1], model_name='PLAN', ax=ax, which_ax1=1, which_ax2=1, W=W, activation_potentiation=activation_potentiation)
|
171
|
+
plt.show()
|
@@ -40,7 +40,7 @@ def transfer_to_cpu(x, dtype=np.float32):
|
|
40
40
|
|
41
41
|
return: NumPy array with the specified dtype
|
42
42
|
"""
|
43
|
-
from ui import loading_bars, initialize_loading_bar
|
43
|
+
from .ui import loading_bars, initialize_loading_bar
|
44
44
|
try:
|
45
45
|
if isinstance(x, np.ndarray):
|
46
46
|
return x.astype(dtype) if x.dtype != dtype else x
|
pyerualjetwork/plan_cuda.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pyerualjetwork
|
3
|
-
Version: 4.2.
|
3
|
+
Version: 4.2.2b1
|
4
4
|
Summary: PyerualJetwork is a machine learning library supported with GPU(CUDA) acceleration written in Python for professionals and researchers including with PLAN algorithm, PLANEAT algorithm (genetic optimization). Also includes data pre-process and memory manegament
|
5
5
|
Author: Hasan Can Beydili
|
6
6
|
Author-email: tchasancan@gmail.com
|
@@ -1,24 +1,25 @@
|
|
1
|
-
pyerualjetwork/__init__.py,sha256=
|
1
|
+
pyerualjetwork/__init__.py,sha256=S17EvWZTRS5-syTAdq8gQNAfuzqHEMStWH5I6fI5KnQ,641
|
2
2
|
pyerualjetwork/activation_functions.py,sha256=WWOdMd5pI6ZKe-ieKCIsKAYPQODHuXYxx7tzhA5xjes,11767
|
3
3
|
pyerualjetwork/activation_functions_cuda.py,sha256=KmXJ5Cdig46XAMYakXFPEOlxSxtFJjD21-i3nGtxPjE,11807
|
4
4
|
pyerualjetwork/data_operations.py,sha256=pb5CqJ0Th6fCjTNMCtqQMiwH3KezTxAijacglsKUxmY,14730
|
5
5
|
pyerualjetwork/data_operations_cuda.py,sha256=UpoJoFhIwTU4xg9dVuLAxLAT4CkRaGsxvtJG9j1xrNo,17629
|
6
|
+
pyerualjetwork/deneme.py,sha256=6b_g1ZyJRhPtqH5D5yUGeOKO6eHMwklUQenccs4G060,7869
|
6
7
|
pyerualjetwork/help.py,sha256=nQ_YbYA2RtuafhuvkreNpX0WWL1I_nzlelwCtvei0_Y,775
|
7
8
|
pyerualjetwork/loss_functions.py,sha256=6PyBI232SQRGuFnG3LDGvnv_PUdWzT2_2mUODJiejGI,618
|
8
9
|
pyerualjetwork/loss_functions_cuda.py,sha256=C93IZJcrOpT6HMK9x1O4AHJWXYTkN5WZiqdssPbvAPk,617
|
9
|
-
pyerualjetwork/memory_operations.py,sha256=
|
10
|
+
pyerualjetwork/memory_operations.py,sha256=I7QiZ--xSyRkFF0wcckPwZV7K9emEvyx5aJ3DiRHZFI,13468
|
10
11
|
pyerualjetwork/metrics.py,sha256=q7MkhnZDRbCjFBDDfUgrl8lBYnUT_1ro1LxeBq105pI,6077
|
11
12
|
pyerualjetwork/metrics_cuda.py,sha256=73h9GC7XwmnFCVzFEEiPQfF8CwHIz2wsCbxpZrJtYgw,5061
|
12
13
|
pyerualjetwork/model_operations.py,sha256=RKqnh7-MByFosxqme4q4jC1lOndX26O-OVXYV6ZxoEE,12965
|
13
14
|
pyerualjetwork/model_operations_cuda.py,sha256=XnKKq54ZLaqCm-NaJ6d8IToACKcKg2Ttq6moowVRRWo,13365
|
14
15
|
pyerualjetwork/plan.py,sha256=mACNJnHlPkeqsHDYw0BVDXp8PCOlwWsF-1KD4a2Bk7U,30431
|
15
|
-
pyerualjetwork/plan_cuda.py,sha256=
|
16
|
+
pyerualjetwork/plan_cuda.py,sha256=aSzXyIZtq38nszW9f9JibvqoEHBCYXvVLaXMVigUUKI,32016
|
16
17
|
pyerualjetwork/planeat.py,sha256=yLPQXO754lBv48f1MXdGodP93KstryeRG3HuUaRwj6g,40753
|
17
18
|
pyerualjetwork/planeat_cuda.py,sha256=9uopmM-gTZpSb0EOExrOZPT8FF5BqDdEfCX0zYQb9QU,40712
|
18
19
|
pyerualjetwork/ui.py,sha256=wu2BhU1k-w3Kcho5Jtq4SEKe68ftaUeRGneUOSCVDjU,575
|
19
20
|
pyerualjetwork/visualizations.py,sha256=QaYSIyVkJZ8NqpBKArQKkI1y37nCQo_KIM98IMssnRc,28766
|
20
21
|
pyerualjetwork/visualizations_cuda.py,sha256=F60vQ92AXlMgBka3InXnOtGoM25vQJAlBIU2AlYTwks,29200
|
21
|
-
pyerualjetwork-4.2.
|
22
|
-
pyerualjetwork-4.2.
|
23
|
-
pyerualjetwork-4.2.
|
24
|
-
pyerualjetwork-4.2.
|
22
|
+
pyerualjetwork-4.2.2b1.dist-info/METADATA,sha256=XBf-qok9_lB70pHC8EgwyPGxmCC9l-Penu0MiYc9Wvo,7914
|
23
|
+
pyerualjetwork-4.2.2b1.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
24
|
+
pyerualjetwork-4.2.2b1.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
|
25
|
+
pyerualjetwork-4.2.2b1.dist-info/RECORD,,
|
File without changes
|
File without changes
|