26
loading...
This website collects cookies to deliver better user experience
import pandas
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.neighbors import KNeighborsClassifier
from sklearn import preprocessing
pip install
or pip3 install
import pandas
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.neighbors import KNeighborsClassifier
from sklearn import preprocessing
df = pandas.read_csv('IRIS.csv')
model = KNeighborsClassifier(n_neighbors=3)
features = list(zip(df["sepal_length"], df["sepal_width"]))
model.fit(features,df["species"])
hue='species'
. and then finally we'll define the data that we're going to be graphing as our Iris dataset by adding data=df
to the end:sns.scatterplot(x='sepal_length', y='sepal_width',
hue='species', data=df, )
# Placing Legend outside the Figure
plt.legend(bbox_to_anchor=(1, 1), loc=1)
plt.show()
import pandas
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.neighbors import KNeighborsClassifier
from sklearn import preprocessing
df = pandas.read_csv('IRIS.csv')
model = KNeighborsClassifier(n_neighbors=3)
features = list(zip(df["sepal_length"], df["sepal_width"]))
model.fit(features,df["species"])
"""sns.scatterplot(x='sepal_length', y='sepal_width',
hue='species', data=df, )
# Placing Legend outside the Figure
plt.legend(bbox_to_anchor=(1, 1), loc=1)
plt.show()
"""
predicted = model.predict([[4.6,5.8]])
print(predicted)
['Iris-setosa']