mirror of
https://github.com/jung-geun/PSO.git
synced 2025-12-20 04:50:45 +09:00
23-07-06
dev container 실행 코드 추가
This commit is contained in:
48
iris.py
48
iris.py
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
||||
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
|
||||
|
||||
import gc
|
||||
|
||||
@@ -16,12 +16,13 @@ from tensorflow.keras.models import Sequential
|
||||
|
||||
def make_model():
|
||||
model = Sequential()
|
||||
model.add(layers.Dense(10, activation='relu', input_shape=(4,)))
|
||||
model.add(layers.Dense(10, activation='relu'))
|
||||
model.add(layers.Dense(3, activation='softmax'))
|
||||
model.add(layers.Dense(10, activation="relu", input_shape=(4,)))
|
||||
model.add(layers.Dense(10, activation="relu"))
|
||||
model.add(layers.Dense(3, activation="softmax"))
|
||||
|
||||
return model
|
||||
|
||||
|
||||
def load_data():
|
||||
iris = load_iris()
|
||||
x = iris.data
|
||||
@@ -29,37 +30,40 @@ def load_data():
|
||||
|
||||
y = keras.utils.to_categorical(y, 3)
|
||||
|
||||
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, shuffle=True, stratify=y)
|
||||
x_train, x_test, y_train, y_test = train_test_split(
|
||||
x, y, test_size=0.2, shuffle=True, stratify=y
|
||||
)
|
||||
|
||||
return x_train, x_test, y_train, y_test
|
||||
|
||||
|
||||
model = make_model()
|
||||
x_train, x_test, y_train, y_test = load_data()
|
||||
|
||||
loss = ['categorical_crossentropy']
|
||||
loss = ["categorical_crossentropy"]
|
||||
|
||||
pso_iris = Optimizer(
|
||||
model,
|
||||
loss=loss[0],
|
||||
n_particles=100,
|
||||
c0=0.4,
|
||||
c1=0.8,
|
||||
loss=loss[0],
|
||||
n_particles=100,
|
||||
c0=0.4,
|
||||
c1=0.8,
|
||||
w_min=0.7,
|
||||
w_max=1.0,
|
||||
w_max=1.0,
|
||||
negative_swarm=0.1,
|
||||
mutation_swarm=0.2,
|
||||
)
|
||||
)
|
||||
|
||||
best_score = pso_iris.fit(
|
||||
x_train,
|
||||
y_train,
|
||||
epochs=200,
|
||||
save=True,
|
||||
save_path="./result/iris",
|
||||
renewal="acc",
|
||||
empirical_balance=False,
|
||||
Dispersion=False,
|
||||
check_point=25
|
||||
)
|
||||
x_train,
|
||||
y_train,
|
||||
epochs=200,
|
||||
save=True,
|
||||
save_path="./result/iris",
|
||||
renewal="acc",
|
||||
empirical_balance=False,
|
||||
Dispersion=False,
|
||||
check_point=25,
|
||||
)
|
||||
|
||||
gc.collect()
|
||||
|
||||
Reference in New Issue
Block a user