0

I have the following sample code, where I need to draw 2 lines, as shown in the plot below:

#X = diabetes_data.drop("Outcome",axis = 1)
y = diabetes_data_copy.Outcome

#importing train_test_split
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=1/3,random_state=42, stratify=y)

from sklearn.neighbors import KNeighborsClassifier


test_scores = []
train_scores = []

for i in range(1,15):

    knn = KNeighborsClassifier(i)
    knn.fit(X_train,y_train)
    
    train_scores.append(knn.score(X_train,y_train))
    test_scores.append(knn.score(X_test,y_test))
    
## score that comes from testing on the same datapoints that were used for training
max_train_score = max(train_scores)
train_scores_ind = [i for i, v in enumerate(train_scores) if v == max_train_score]
print('Max train score {} % and k = {}'.format(max_train_score*100,list(map(lambda x: x+1, train_scores_ind))))

## score that comes from testing on the datapoints that were split in the beginning to be used for testing solely
max_test_score = max(test_scores)
test_scores_ind = [i for i, v in enumerate(test_scores) if v == max_test_score]
print('Max test score {} % and k = {}'.format(max_test_score*100,list(map(lambda x: x+1, test_scores_ind))))

plt.figure(figsize=(12,5))
p = sns.lineplot(range(1,15),train_scores,marker='*',label='Train Score')
p = sns.lineplot(range(1,15),test_scores,marker='o',label='Test Score')

But when i run this code i got error :

TypeError: lineplot() takes from 0 to 1 positional arguments but 2 were given

I tried putting x and y at 1 and 15 but nothing

doneforaiur
  • 1,308
  • 7
  • 14
  • 21
  • What is `sns`? Are you importing seaborn as sns somewhere else in the code that you're not showing? – Atalay K. Jul 01 '23 at 05:48
  • `sns.lineplot(data=may_flights, x="year", y="passengers")`. Just remove the `range` and supply the data as `data=(range(1,15), train_scores)`. For more check examples; https://seaborn.pydata.org/generated/seaborn.lineplot.html – doneforaiur Jul 01 '23 at 05:50
  • sns is seabron here the source : from mlxtend.plotting import plot_decision_regions import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set() import warnings – Nur Rokhaini Jul 01 '23 at 05:51
  • @doneforaiur sorry i dont understand, at least i need to change my code like this ? p = sns.lineplot data=(range(1,15),train_scores,marker='*',label='Train Score') and the result error invalid syntax at train_scores. – Nur Rokhaini Jul 01 '23 at 05:59
  • `p = sns.lineplot(data=(range(1,15),train_scores),marker='*',label='Train Score')` – doneforaiur Jul 01 '23 at 06:21
  • @doneforaiur Thank you so much, it solved. – Nur Rokhaini Jul 01 '23 at 06:25
  • Posted the coment as an answer so that more people can access it easily. – doneforaiur Jul 01 '23 at 06:39

1 Answers1

0

You should specify your data and range as a tuple. Like this;

p = sns.lineplot(data=(range(1,15),train_scores),marker='*',label='Train Score')
doneforaiur
  • 1,308
  • 7
  • 14
  • 21