Neyron tarmog‘i. Eng oddiy neyron tarmoq qurish texnologiyasi Ishdan maqsad




Download 0,53 Mb.
bet2/3
Sana19.12.2023
Hajmi0,53 Mb.
#123948
1   2   3
Bog'liq
anvar robo5

2-dastur kodi va natijasi
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris
from keras.models import Sequential
from keras.layers import Dense

# Ma'lumotlarni yuklash


iris = load_iris()
X = iris.data
y = iris.target

# Qiymatlarni binar kategoriyaga aylantiramiz


y = pd.get_dummies(y).values

# Ma'lumotlarni o'qitish va sinov uchun ajratamiz


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Ma'lumotlarni standartlashtiramiz


scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

# Modelni tuzamiz


model = Sequential()
model.add(Dense(4, input_dim=4, activation='relu'))
model.add(Dense(3, activation='softmax'))

# Modelni tuzamiz


model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Modelni o'qitamiz


model.fit(X_train, y_train, epochs=50, batch_size=8, validation_data=(X_test, y_test))
import matplotlib.pyplot as plt

# Modelning o'qitilishi davriga oid ma'lumotlarni olamiz


history = model.history.history

# O'qitish natijalarni grafikga chizamiz


plt.plot(history['accuracy'], label='Training Accuracy')
plt.plot(history['val_accuracy'], label='Validation Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend()
plt.show()
# Test ma'lumotlaridan bashqa ma'lumotlarni standartlashtiramiz
X_new = scaler.transform(X_test)

# Natijalarni olish


predictions = model.predict(X_new)

# Baholarni chiqaramiz


print(predictions)








Download 0,53 Mb.
1   2   3




Download 0,53 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



Neyron tarmog‘i. Eng oddiy neyron tarmoq qurish texnologiyasi Ishdan maqsad

Download 0,53 Mb.