> For the complete documentation index, see [llms.txt](https://mugdha-thanawala.gitbook.io/tkmt_package/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mugdha-thanawala.gitbook.io/tkmt_package/case-study/case-study-4.md).

# Case Study 4

The Iris flower dataset or Fisher's Iris dat set is a multivariate data set introduced by the British statistician and biologist Ronald Fisher. The data set consists of 50 samples from each of three species of Iris (Iris setosa, Iris virginica and Iris versicolor). Four features were measured from each sample: the length and the width of the sepals and petals, in centimeters.&#x20;

Importing the libraries&#x20;

```python
from tkmt_package.preprocessing import Preprocessing
from tkmt_package.ensemble import votingClassifer
from tkmt_package.evaluation import Evaluation
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import ExtraTreesClassifier
from sklearn import metrics
from sklearn.preprocessing import LabelEncoder,MinMaxScaler
from sklearn.model_selection import train_test_split
```

Importing the dataset

```python
from sklearn.datasets import load_iris
data = load_iris()
iris.head()
```

![](/files/fRZ89ZGfuOeM7k0bx3BH)

```python
np.unique(iris.target)
```

![](/files/68dWuEh6MyvYaCvSCMxw)

Data Preprocessing&#x20;

```python
scaled = LabelEncoder().fit_transform(iris.iloc[:,-1])
scaled_x = MinMaxScaler().fit_transform(iris.iloc[:,:-1])
raw_data = pd.DataFrame(scaled_x,columns=iris.columns[:-1])
raw_data['condition']=scaled
labels =['Iris-setosa', 'Iris-versicolor', 'Iris-virginica']
X = raw_data.iloc[:,:-1]
y = raw_data.iloc[:,-1]
```

Train Test Split

```python
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.7)
```

Model Training and Prediction

```python
estimators=[('rfr',RandomForestClassifier()),('lr',LogisticRegression()),('etc',ExtraTreesClassifier())]
estimators
vc = votingClassifer(estimator=estimators)
vc.get_fit(X_train,y_train)
y_pred = vc.get_predict(X_test)
```

Performance Evaluation

```python
metrics.accuracy_score(y_test,y_pred)
```

![](/files/uCM87wPud6S2EQJZeEBO)

```
print(metrics.classification_report(y_test,y_pred))
```

![](/files/oUAD5AsNGrHKNjP6NQ5R)

```python
eva = Evaluation()
eva.get_plot_classification(true = y_test,
            pred = y_pred,
            X_labels = labels,
            y_labels = labels,
            cmap_index=2,
            figsize=(10, 5))
```

![](/files/rHRfWas0rxsmtVW1dJnb)
