iris predictor


In [2]:
import pandas as pd
%matplotlib inline
from sklearn import datasets
from pandas.tools.plotting import scatter_matrix
import matplotlib.pyplot as plt
from sklearn import tree

In [3]:
iris = datasets.load_iris()

In [5]:
iris['feature_names']


Out[5]:
['sepal length (cm)',
 'sepal width (cm)',
 'petal length (cm)',
 'petal width (cm)']

In [6]:
x = iris.data[:,2:] 
y = iris.target

In [21]:
def get_class(iris):
    if iris['p_width']<= 0.8:
        return "class 1"
    else:
        if iris['p_width'] <= 1.75:
            if iris['p_length'] <= 4.95:
                if iris['p_width'] <= 1.65:
                    return "class 2"
                else:
                    return "class 3"
            else:
                if iris['p_width'] <= 1.55:
                    return "class 3"
                else:
                    if iris['p_length']<=5.45:
                        return 'class 2'
                    else:
                        return 'class 3'
        else:
            if iris['p_length']<=4.85:
                return "class 3"
            else:
                return "class 3"

In [22]:
test = {
    'p_width': 1.51,
    'p_length' : 4.5
}

get_class(test)


Out[22]:
'class 2'

In [ ]: