# লজিস্টিক রিগ্রেশনঃ মাল্টিনোমিয়াল

গত অধ্যায়েই আমরা জেনেছি মাল্টিনোমিয়াল  লজিস্টিক রিগ্রেশন কি ?প্রেডিকশন ক্লাস যখন দুইয়ের বেশী হয় তখন তাকে মাল্টিনোমিয়াল ক্লাস বলে। এধরনের ডেটায় তিনটি ,চারটি বা এর বেশী যেকোনো সংখ্যক ক্লাস থাকতে পারে। উদাহরন হিসাবে বলা যায় আইরিস ফ্লাওয়ার ডেটাসেটে তিন ধরনের আইরিস ফ্লাওয়ারের ডেটা রয়েছে, অর্থাৎ এর ক্লাস তিন টি। সেক্ষেত্রে এটি একটি মাল্টিনোমিয়াল ক্লাস।&#x20;

> &#x20;আইরিস  হচ্ছে একটি ফুলের নাম। আইরিস ডেটা সেটেকে একারনে আইরিস ফ্লাওয়ার ডেটা সেটও বলা হয়। বিজ্ঞানী R.A. Fisher, ১৯৩৬ সালে এই ডেটা সেটটি প্রকাশ করেন।
>
> আইরিস ডেটা সেটে এই ৩ প্রজাতির আইরিস ফুলের তথ্য সংগ্রহ করা হয়েছে মূলত বৃত্যংশের দৈর্ঘ্য (sepal length) , বৃত্যংশের প্রস্থ (sepal width) , পাপড়ির দৈর্ঘ্য (petal length) এবং পাপড়ির প্রস্থের (petal width) উপর ভিত্তি করে। ফুলটি কোন প্রজাতির সেটা লেবেল হিসাবে রাখা হয়েছে Class Lebel এ। এভাবে ১৫০ টি অবজারভেশন বা রেকর্ড রয়েছে এই ডেটা সেটে।

বাইনোমিয়াল লজিস্টিক রিগ্রেশনের জন্য যে  লাইব্রেরী ইমপোর্ট  করেছিলাম সেই লাইব্রেরীগুলো দিয়েই মাল্টিনোমিয়াল  লজিস্টিক রিগ্রেশন করা যায়। তাই এক্ষেত্রে আমরা শুধুমাত্র  ডেটাসেট লোড করে নিচ্ছি,&#x20;

```
url='https://raw.githubusercontent.com/FazlyRabbiBD/Data-Science-Book/master/data-iris.csv'
df = pd.read_csv(url)
```

আমাদের ডেটাসেটটি দেখতে অনেকটা এরকম

![](/files/-M7X_RcCOYvMTGGx6el4)

এবার ফিচার এবং টার্গেট ভ্যারিয়েবল সেট করে নেব,

```
features=['sepal_length','sepal_width','petal_length','petal_width']
x=df[features]
y=df.species
```

এখন টেস্ট এর জন্য ২৫% ডেটা রেখে বাকি ডেটা দিয়ে মডেল ট্রেইন করবো,

```
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=5)
multilogreg = LogisticRegression(multi_class='multinomial')
multilogreg.fit(x_train, y_train)
```

আমাদের মডেল এখন তৈরি। এবার অ্যাকুরেসি চেক করার পালা।&#x20;

```
print('Coefficients:', multilogreg.coef_)
print('Intercept:', multilogreg.intercept_)
 
predictions = multilogreg.predict(x_test)
print('Classification Report:\n',classification_report(y_test, predictions))
print('Accuracy Score:',accuracy_score(y_test, predictions))
```

![](/files/-M7Xa-RKmXDAU4agS9la)

আমারা দেখতে পাচ্ছি আমাদের মডেল ৯৭.৩৬% নির্ভুল ভাবে প্রিডিকশন করতে পারছে।&#x20;

চলুন নতুন একটি ডেটা দিয়ে প্রিডিকশন করি। মনে করুন আপনার কাছে একটি আইরিস ফুল রয়েছে কিন্তু আপনি জানেন না এটি কোন প্রজাতির। আপনার কাজ হবে আমাদের এই মডেলে ঐ ফুলের sepal\_length, petal\_length, petal\_length, petal\_width এর মাপ মডেলে ইনপুট দেয়া, আর মডেলের কাজ হবে অনুমান করে বলে দেয়া ফুলটি কোন প্রজাতির।

```
new_observation = [[4.6,3.1,2.9,0.2]]
multilogreg.predict(new_observation)
```

array(\['setosa'], dtype=object)&#x20;

মডেল বলছে ফুলটি setosa প্রজাতির।&#x20;

![](/files/-M9cEJDYtqaNhHQuA2ZU)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://datasinsightsbd.gitbook.io/dsbook/supervised-ml/undefined.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
