You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ML-For-Beginners/translations/my/4-Classification/2-Classifiers-1
localizeflow[bot] d493273e8e
chore(i18n): sync translations with latest source changes (chunk 1/1, 12 changes)
3 months ago
..
solution chore(i18n): sync translations with latest source changes (chunk 1/1, 300 changes) 6 months ago
README.md chore(i18n): sync translations with latest source changes (chunk 1/1, 12 changes) 3 months ago
assignment.md chore(i18n): sync translations with latest source changes (chunk 1/1, 300 changes) 6 months ago
notebook.ipynb 🌐 Update translations via Co-op Translator 10 months ago

README.md

အစားအသောက် အမျိုးအစား ခွဲခြားသူများ ၁

ဒီသင်ခန်းစာမှာ သင်ဟာ ယင်းအစားအသောက်အမျိုးအစားတွေနဲ့ပတ်သက်ပြီး ချိန်ညှိပြီး သန့်ရှင်းသော ဒေတာတစ်ခုကို မပြီးဆုံးခင်သင်ခန်းစာကနေ သိမ်းဆည်းထားတဲ့ ဒေတာ set ကိုအသုံးပြုပါမည်။

အဲဒီ dataset ကို အမျိုးအစားခွဲခြားသူမျိုးစုံနဲ့ သုံးပြီး ပေးထားတဲ့ အစားအစာပစ္စည်း အုပ်စုတစ်ခုအပေါ်အခြေခံပြီး အမျိုးအစားခွဲခြားဖော်ထုတ်ခြင်း ပြုလုပ်မှာဖြစ်ပါတယ်။ ဒီအလုပ်လုပ်နေစဉ်အတွင်း အပိုင်းခွဲခြားလုပ်ငန်းများအတွက် algorithm တွေကို ဘယ်လိုအသုံးချနိုင်ကြောင်း အပိုများစွာ လေ့လာနိုင်မှာဖြစ်ပါတယ်။

သင်ခန်းစာမတိုင်မီ စမ်းမေးပွဲ

ပြင်ဆင်မှုပြုလုပ်ခြင်း

သင်ခန်းစာ ၁ ပြီးဆုံးပြီးသားဖြစ်ကြောင်း သတ်မှတ်ပြီးသားဆိုထားပြီး၊ ဤသင်ခန်းစာလေးခုအတွက် root /data ဖိုလ်ဒါအတွင်း cleaned_cuisines.csv ဖိုင်ရှိနေပြီးဖြစ်ကြောင်း သေချာစေပါ။

လေ့ကျင့်ခန်း - အမျိုးအစားခွဲခြားရန် ခန့်မှန်းခြင်း

  1. ဒီသင်ခန်းစာ၏ notebook.ipynb ဖိုလ်ဒါအတွင်းမှာ အဲဒီဖိုင်နဲ့ Pandas စာကြည့်တိုက်ကို တင်သွင်းပါ။

    import pandas as pd
    cuisines_df = pd.read_csv("../data/cleaned_cuisines.csv")
    cuisines_df.head()
    

    ဒေတာဟာ ဒီလိုမျိုးပုံစံရှိပါတယ် -

Unnamed: 0 cuisine almond angelica anise anise_seed apple apple_brandy apricot armagnac ... whiskey white_bread white_wine whole_grain_wheat_flour wine wood yam yeast yogurt zucchini
0 0 indian 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
1 1 indian 1 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
2 2 indian 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
3 3 indian 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
4 4 indian 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 1 0
  1. ယခု အခြားစာကြည့်တိုက်များကို တင်သွင်းပါ။

    from sklearn.linear_model import LogisticRegression
    from sklearn.model_selection import train_test_split, cross_val_score
    from sklearn.metrics import accuracy_score,precision_score,confusion_matrix,classification_report, precision_recall_curve
    from sklearn.svm import SVC
    import numpy as np
    
  2. X နှင့် y ကို သင်ကြားရေးအတွက် နှစ်ခုသော dataframe များအဖြစ် ခွဲထုတ်ပါ။ cuisine ကို label အဖြစ်သတ်မှတ်နိုင်သည်။

    cuisines_label_df = cuisines_df['cuisine']
    cuisines_label_df.head()
    

    ဒီလိုမျိုးရှိပါလိမ့်မယ် -

    0    indian
    1    indian
    2    indian
    3    indian
    4    indian
    Name: cuisine, dtype: object
    
  3. Unnamed: 0နှင့် cuisine ကော်လံများကို drop() ဖြင့် ဖယ်ရှားပြီး training features အဖြစ် အခြားဒေတာများအား သိမ်းဆည်းပါ။

    cuisines_feature_df = cuisines_df.drop(['Unnamed: 0', 'cuisine'], axis=1)
    cuisines_feature_df.head()
    

    သင့် features ဟာ ဒီလိုပုံစံရှိတော့မယ် -

almond angelica anise anise_seed apple apple_brandy apricot armagnac artemisia artichoke ... whiskey white_bread white_wine whole_grain_wheat_flour wine wood yam yeast yogurt zucchini
0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 1 0

ယခု သင့်မှာ သင်တန်းပေးဖို့ အဆင်သင့်ဖြစ်ပါပြီ။

သင့်အတွက် အမျိုးအစားခွဲခြားသူ ရွေးချယ်ခြင်း

ဒေတာ သန့်ရှင်းပြီး သင်ကြားရန် ပြင်ဆင်ပြီး ဖြစ်တဲ့အခါ၊ အလုပ်အတွက် ဘယ် algorithm ကို သုံးမလဲ ဆိုတာဆုံးဖြတ်ရပါမယ်။

Scikit-learn ဟာ Classification ကို Supervised Learning အတွင်း ထည့်သွင်းပြီး၊ အဲဒီအုပ်စုမှာ သင်တွေ့နိုင်တဲ့ အမျိုးအစားလာလားဖြစ်စေ classification နည်းလမ်းမျိုးစုံကို ရှာတွေ့နိုင်ပါတယ်။ အမျိုးမျိုး မှာ ရှိတာက ပထမကြည့်တဲ့အခါ စိတ်မချမ်းသာ ဖြစ်စေတတ်ပါတယ်။ အောက်ပါနည်းလမ်းများတွင် classification နည်းပညာများ ပါဝင်သည် -

  • လိုင်းနီးယား မော်ဒယ်များ
  • Support Vector Machines
  • Stochastic Gradient Descent
  • အနီးဆုံးအိမ်နီးများ
  • Gaussian Processes
  • ဆုံးဖြတ်ရိုက်ပုံများ
  • Ensemble နည်းလမ်းများ (voting Classifier)
  • Multiclass နှင့် multioutput algorithm များ (multiclass နှင့် multilabel classification, multiclass-multioutput classification)

သင်ဟာ နယူးရာလ်နက်ဝက်များဖြင့် ဒေတာပြုလုပ်ခြင်းကိုပါ အသုံးပြုနိုင်သော်လည်း၊ ဒီသင်ခန်းစာ၏ ပတ်ဝန်းကျင်ဟာ အဲဒါနဲ့ မဟုတ်ပါ။

ဘယ်အမျိုးအစားခွဲခြားသူကို ရွေးမလဲ?

ဒါဆို အမျိုးအစားခွဲခြားသူ ဘယ်အမျိုးကိုရွေးသင့်သလဲ? ပုံမှန်အားဖြင့် အမျိုးမျိုးကို တွန်းလှန် စမ်းသပ်ပြီး ရလဒ်ကောင်းလာလားကြည့်ရင် စမ်းသပ်နိုင်ပါတယ်။ Scikit-learn ဟာ တပြိုင်နက်မှာ နှိုင်းယှဉ်ခြင်း ကို dataset တစ်ခုကိုဖန်တီးပြီး နည်းလမ်းအချို့ (KNeighbors, SVC နှစ်မျိုး, GaussianProcessClassifier, DecisionTreeClassifier, RandomForestClassifier, MLPClassifier, AdaBoostClassifier, GaussianNB နှင့် QuadraticDiscrinationAnalysis) နဲ့ အဆင်ပြေမှုကို မြင်ယောင် ပြထားပါတယ် -

comparison of classifiers

Scikit-learn မှ အထောက်အထားစာတမ်းအတွင်း ဖန်တီးထားသော ပြဇာတ်များ ဖြစ်သည်။

AutoML က ဒီပြဿနာကို သွားရောက်ပြီး ဆန်းစစ်ကာ သင့်ဒေတာအတွက် အကောင်းဆုံး algorithm ကို ရွေးနိုင်စေပါတယ်။ ဒီမှာ ကြိုးစားကြည့်ပါ

ပိုမိုကောင်းမွန်သောနည်းလမ်း

လွဲမှားတွေးတာထက် ပိုကောင်းသောနည်းလမ်းကတော့ ဒီ ML Cheat sheet ကို ဒင်းလိုက်ဒေါင်းလုတ် ယူပြီး အကြံဉာဏ်တွေကို လိုက်နာခြင်းဖြစ်ပါတယ်။ ဒီမှာ ကျွန်တော်တို့ multiclass ပြဿနာအတွက် ရွေးချယ်စရာ အတော်များများ ရှိကြောင်း တွေ့ရှိရပါသည်။

cheatsheet for multiclass problems

Microsoft ၏ Algorithm Cheat Sheet မှ အစိတ်အပိုင်းတစ်ခုဖြစ်ပြီး multiclass classification အတွက် ရွေးချယ်နည်းများ ဖော်ပြထားသည်။

ဒီ cheat sheet ကို ဒေါင်းလုဒ် ယူ၍ ပုံနှိပ်ထားပြီး နံရံပေါ်တွင် ပေါ်လာအောင် တပ်ထားပါ။

အကြောင်းပြချက်များ

ကြည့်ကြပါစို့ မတူညီသော လမ်းစဉ်များကို ငြင်းဆိုရာတွင် ကျွန်တော်တို့ ရှိတဲ့ကန့်သတ်ချက်များအရ -

  • နယူးရာလ်နက်ဝက်များသည် များစွာကြီးလွန်းသည်။ သန့်ရှင်းပြီး သေးငယ်သည့် dataset ဖြင့်၊ သင့်က နောက်ခံနက်ဘုတ်ဖြင့် ထည့်သင်ကြားခြင်း များ ပြုလုပ်နေသောကြောင့် Neural network များသည် အလေးမတင်နိုင်သည်။
  • နှစ်သိမ့်အမျိုးအစား ခွဲခြားသူ မရှိပါ။ နှစ်သိမ့် classifier မသုံးတော့သောကြောင့် one-vs-all ကို မသုံးပါ။
  • Decision tree သို့မဟုတ် logistic regression ကောင်းကောင်းလည်ပတ်နိုင်သည်။ Decision tree သို့မဟုတ် multiclass အချက်အလက်များအတွက် logistic regression အသုံးပြုနိုင်ပါတယ်။
  • Multiclass Boosted Decision Trees သည် အခြားပြဿနာများဖြေရှင်းသည်။ Multiclass boosted decision tree သည် ranking ကို ဖန်တီးရန် ဒီဇိုင်းပြုလုပ်သော nonparametric task များမှသာ အသုံးပြုသင့်သည်၊ သို့င်း ကျွန်ုပ်တို့အတွက် မသင့်တော်ပါ။

Scikit-learn ကို အသုံးပြုခြင်း

ကျွန်တော်တို့ Scikit-learn ကို ဒေတာအား စစ်တမ်းဖော်မြူဆောင်ရန် သုံးမှာ ဖြစ်သည်။ သို့သော် logistic regression တွင် Scikit-learn မှာ parameter များ များစွာ အသုံးပြုနိုင်ပါသည်။ parameter များကြည့်ပါ

အဓိကအားဖြင့် အရေးကြီးသော parameter နှစ်ခုရှိသည် - multi_class နှင့် solver - တိုင်းတာပြီး Scikit-learn ကို logistic regression လုပ်ရန် တောင်းဆိုသည့်အခါ သတ်မှတ်ရမည်။ multi_class သည် မတူညီသော လုပ်ဆောင်ချက်တစ်ခု လုပ်ဆောင်ပြီး၊ solver သည် ဘယ် algorithm ကို သုံးမယ်ဆိုတာ သတ်မှတ်သည်။ အားလုံးသော solver များသည် multi_class အားလုံးနှင့် တွဲဖက် အသုံးပြုလို့ မရပါ။

စာရွက်စာတမ်းအရ၊ multiclass တွင်၊ သင်ကြားရေး algorithm သည် -

  • multi_class ကို ovr သတ်မှတ်ထားလျှင် one-vs-rest (OvR) စနစ်ကို အသုံးပြုသည်
  • multi_class ကို multinomial သတ်မှတ်ထားလျှင် cross-entropy loss ကို အသုံးပြုသည်။ (လောလောဆယ် lbfgs, sag, saga နဲ့ newton-cg solver တွေရဲ့ အတွက်သာ multinomial ကို ထောက်ပံ့သည်)"

🎓 'scheme' ဆိုတာဟာ 'ovr' (one-vs-rest) သို့မဟုတ် 'multinomial' ဖြစ်နိုင်သည်။ Logistic regression သည် ဒုတိယအချိုးချင်း classification အတွက် ရည်ရွယ်ထားပြီး၎င်းဖြင့် multiclass classification ပြဿနာများကို ပိုမိုကောင်းမွန်စွာ ဖြေရှင်းနိုင်စေရန် အဲဒီစနစ်တွေကို အသုံးပြုသည်။ source

🎓 'solver' သည် optimization ပြဿနာတွင် အသုံးပြုသော algorithm ကို သတ်မှတ်ထားသည်။ source.

Scikit-learn သည် solver များသည် ကွာခြားသော ဒေတာဖွဲ့စည်းမှုအမျိုးအစားများကို မည်သို့ ကိုင်တွယ်သည်ဆိုတာကို ရှင်းပြရန် အောက်ပါ အတန်းဇယားကို ပေးထားသည်။

solvers

လေ့ကျင့်ခန်း - ဒေတာခွဲခြမ်းခြားခြင်း

မကြာသေးခင် သင်ခန်းစာတစ်ခုမှာ logistic regression ကို သင်ယူခဲ့တာဖြစ်လို့ ပထမဆုံး သင်ကြားမှုအတွက် logistic regression ကို အဓိကထားပြီး စမ်းသပ်ပါ။ train_test_split() ကို ခေါ်ဆို၍ သင်နှင့် စမ်းသပ် ဘားကိုခွဲပါ -

X_train, X_test, y_train, y_test = train_test_split(cuisines_feature_df, cuisines_label_df, test_size=0.3)

လေ့ကျင့်ခန်း - logistic regression ကို အသုံးပြုပါ

မိမိသည် multiclass ဖြစ်သောကြောင့် ဘယ် scheme ကို အသုံးပြုမလဲ၊ ဘယ် solver ကို သတ်မှတ်မလဲ ဆိုတာ ရွေးဖို့လိုပါသည်။ LogisticRegression ကို multi_class ကို ovr နှင့် solver ကို liblinear သတ်မှတ်၍ သင်ကြားပါ။

  1. multi_class ကို ovr သတ်မှတ်ထားပြီး solver ကို liblinear သတ်မှတ်ထားသော logistic regression ကို ဖန်တီးပါ။

    lr = LogisticRegression(multi_class='ovr',solver='liblinear')
    model = lr.fit(X_train, np.ravel(y_train))
    
    accuracy = model.score(X_test, y_test)
    print ("Accuracy is {}".format(accuracy))
    

    ပုံမှန်အားဖြင့်သတ်မှတ်ထားသော lbfgs ကဲ့သို့ အခြား solver ကို စမ်းသုံးကြည့်ပါ။

    မှတ်ချက် - လိုအပ်လျှင် Pandas ၏ ravel function အသုံးပြုပြီး ဒေတာကို တန်းစီချခြင်း။

    တိကျမှုမှာ ၈၀% ကျော် ဖြစ်ကြောင်း တွေ့နိုင်ပါသည်!

  2. ဒေတာ အတန်းတစ်ခု (#50) ကို စမ်းသပ်ကာ ဒီမော်ဒယ်က ဘယ်လို သွားမလဲ ကြည့်နိုင်ပါသည် -

    print(f'ingredients: {X_test.iloc[50][X_test.iloc[50]!=0].keys()}')
    print(f'cuisine: {y_test.iloc[50]}')
    

    ရလဒ် ကို ဤသို့ ပြသသည် -

    ingredients: Index(['cilantro', 'onion', 'pea', 'potato', 'tomato', 'vegetable_oil'], dtype='object')
    cuisine: indian
    

    အတန်း အရေအတွက် ပြောင်းပြီး ရလဒ်တွေ စစ်ဆေးကြည့်ပါ။

  3. Digging deeper, you can check for the accuracy of this prediction:

    test= X_test.iloc[50].values.reshape(-1, 1).T
    proba = model.predict_proba(test)
    classes = model.classes_
    resultdf = pd.DataFrame(data=proba, columns=classes)
    
    topPrediction = resultdf.T.sort_values(by=[0], ascending = [False])
    topPrediction.head()
    

    The result is printed - Indian cuisine is its best guess, with good probability:

    0
    indian 0.715851
    chinese 0.229475
    japanese 0.029763
    korean 0.017277
    thai 0.007634

    Can you explain why the model is pretty sure this is an Indian cuisine?

  4. Get more detail by printing a classification report, as you did in the regression lessons:

    y_pred = model.predict(X_test)
    print(classification_report(y_test,y_pred))
    
    precision recall f1-score support
    chinese 0.73 0.71 0.72 229
    indian 0.91 0.93 0.92 254
    japanese 0.70 0.75 0.72 220
    korean 0.86 0.76 0.81 242
    thai 0.79 0.85 0.82 254
    accuracy 0.80 1199
    macro avg 0.80 0.80 0.80 1199
    weighted avg 0.80 0.80 0.80 1199

🚀Challenge

ဒီသင်ခန်းစာမှာ သင်ဟာ သန့်ရှင်းပြီးပြင်ဆင်ထားတဲ့ ဒေတာကို အသုံးပြုပြီး ပစ္စည်းများအခြေပြု၍ နိုင်ငံတစ်ကာစားနပ်ရိက္ခာမျိုးကို ခန့်မှန်းနိုင်တဲ့ စက်မှုသင်ယူမှု မော်ဒယ်ကို တည်ဆောက်ခဲ့ပါသည်။ Scikit-learn က ဒေတာကို သတ်မှတ်ဖော်ကြားဖို့ ပေးသည့် အမျိုးအစားများအတွက် ရွေးချယ်စရာများစွာကို အချိန်ယူဖတ်ရှုပါ။ 'solver' အယူအဆိုနောက်က အကြောင်းအရာကို ပိုမိုနက်နဲစွာ လေ့လာပါ။

စာသင်ခန်း နှောင်း အကြံပေး စစ်ဆေးမှု

ပြန်လည်သုံးသပ်ခြင်းနှင့် ကိုယ်တိုင်လေ့လာခြင်း

Logistic regression နောက်က ဖြစ်ပေါ်လာတဲ့ နည်းဗေဒများကို ဒီသင်ခန်းစာ တွင် နည်းပိုမို နက်နဲစွာ လေ့လာပါ။

အလုပ်တာဝန်

Solvers များကို လေ့လာပါ


ကန်တော့ချက်:
ဤစာရွက်စာတမ်းကို AI ဘာသာပြန်ဝန်ဆောင်မှု Co-op Translator ဖြင့် ဘာသာပြန်ထားပါသည်။ ကျွန်ုပ်တို့သည် တိကျမှန်ကန်မှုအတွက် ကြိုးစားနေသော်လည်း စက်ရုပ်ဘာသာပြန်မှုများတွင် အမှားများ သို့မဟုတ် မှန်ကန်မှုမရှိမှုများ ဖြစ်ပေါ်နိုင်ပါသည်။ မူလစာရွက်စာတမ်းကို မူရင်းဘာသာစကားဖြင့်သာ တရားဝင်အရင်းအမြစ်အဖြစ် သတ်မှတ်ရန်လိုအပ်ပါသည်။ အရေးကြီးသောအချက်အလက်များအတွက် ကျွမ်းကျင်သော လူ့ဘာသာ ပြန်ဆိုမှုကို သုံးသင့်ပါသည်။ ဤဘာသာပြန်ချက်ကို အသုံးပြုမှုကြောင့် ဖြစ်ပေါ်လာသော မနားမသာနားလည်မှုများ သို့မဟုတ် အဓိပ္ပာယ်မှားချက်များအတွက် ကျွန်ုပ်တို့ အာမခံမှု မရှိပါ။