Здравствуйте, пожалуйста, помогите мне найти ошибку в этой задаче. Вот код, который я использую:
```python
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import seaborn as sns
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
from sklearn import datasets
iris = sns.load_dataset('iris')
x_train, x_test, y_train, y_test = train_test_split(
iris.iloc[:,:-1],
iris.iloc[:,-1],
test_size=0.15
)
def init_model(k, x_train, y_train, x_test):
model = KNeighborsClassifier(n_neighbors=k)
print(model)
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
return y_pred
def grath(y_test, x_test, y_pred):
plt.figure(figsize=(10, 7))
sns.scatterplot(x='petal_width', y='petal_lenght', data=iris, hue='species', s=70)
plt.xlabel('Длина лепестка,см')
plt.ylabel('Ширина лепестка,см')
plt.legend(loc=2)
plt.grid()
for i in range(len(y_test)):
if np.array(y_test)[i] != y_pred[i]:
plt.scatter(x_test.iloc[i,3], x_test.iloc[i,2], color='red', s=150)
x_train.shape, x_test.shape, y_train.shape, y_test.shape
x_train.head()
y_train.head()
k = int(input('Чему равно k? '))
y_pred = init_model(k, x_train, y_train, x_test)
print((f'accuracy:{accuracy_score(y_perd, y_test):.3}'))
grath(y_test, x_test, y_pred)
```
В чем моя ошибка? Заранее спасибо за ответ.