• Scikit-learn yordamida misol
  • 2. Tens yoki Flow yordamida misol (oddiy neyron tarmoq uchun)
  • Konteynerlashtirishdan foydalanish




    Download 5,69 Mb.
    bet13/182
    Sana19.05.2024
    Hajmi5,69 Mb.
    #244351
    1   ...   9   10   11   12   13   14   15   16   ...   182
    Bog'liq
    Python sun\'iy intellekt texnologiyasi Dasrlik 2024

    Konteynerlashtirishdan foydalanish:
    Docker kabi konteynerlar AI modellarini turli muhitlarga joylashtirishni osonlashtirishi va ularning izolyatsiyasini ta’minlashi mumkin.
    Modelning hayot aylanishini boshqarishning avtomatlashtirilgan tizimlarini joriy etish:
    Modellarni ishlab chiqish, o‘qitish va joylashtirishni osonlashtirish uchun MLflow yoki Kubeflow kabi model hayot aylanishini boshqarish platformalaridan foydalanish.
    Python ilovalariga integratsiyalashda xavfsizlik, ishlash va miqyoslilik talablarini hisobga olish muhimdir. Tegishli texnologiyalar va kutubxonalarni tanlash sizning loyihangizning aniq vazifalari va ehtiyojlariga bog’liq.
    Python-da scikit-learn, TensorFlow va PyTorch-dan foydalangan holda mashinali o‘qitish kutubxonalaridan foydalanishning oddiy misollarini keltiraman.

    1. Scikit-learn yordamida misol:

    from sklearn.model_selection import train_test_split
    from sklearn.ensemble import RandomForestClassifier
    from sklearn.metrics import accuracy_score
    # Ma’lumotlarni yuklash (Iris ma’lumotlar to‘plamiga misol)
    from sklearn.datasets import load_iris
    iris = load_iris()
    X, y = iris.data, iris.target
    # Ma’lumotlarni o‘qitish va test namunalariga bo‘lish
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    # Modelni yaratish (tasodifiy o‘rmon klassifikatori)
    model = RandomForestClassifier(n_estimators=100, random_state=42)
    # Modelni o‘qitish
    model.fit(X_train, y_train)
    # Sinov namunasidagi bashorat
    predictions = model.predict(X_test)
    # Modelning aniqligini baholash
    accuracy = accuracy_score(y_test, predictions)
    print(f"Accuracy: {accuracy}")
    2. Tens yoki Flow yordamida misol (oddiy neyron tarmoq uchun):
    import tensorflow as tf
    from tensorflow.keras import layers, models
    from sklearn.model_selection import train_test_split
    from sklearn.metrics import accuracy_score
    # Ma’lumotlarni yuklash (Iris ma’lumotlar to‘plamiga misol)
    from sklearn.datasets import load_iris
    iris = load_iris()
    X, y = iris.data, iris.target
    # Ma’lumotlarni o‘qitish va test namunalariga bo‘lish
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    # Oddiy neyron tarmog’ini qurish
    model = models.Sequential([
    layers.Dense(64, activation='relu', input_shape=(4,)),
    layers.Dense(3, activation='softmax') ])
    # Modelni kompilyatsiya qilish
    model.compile(optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy'])
    # Modelni o‘qitish
    model.fit(X_train, y_train, epochs=50, batch_size=32, validation_split=0.2)
    # Modelning aniqligini baholash
    test_loss, test_acc = model.evaluate(X_test, y_test)
    print(f"Test Accuracy: {test_acc}")

    Download 5,69 Mb.
    1   ...   9   10   11   12   13   14   15   16   ...   182




    Download 5,69 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Konteynerlashtirishdan foydalanish

    Download 5,69 Mb.