Note - kamchur/note GitHub Wiki
# ์ฐจํธ ์ฌ์ง์ผ๋ก ์ ์ฅ
plt.savefig('a.png')
# sns.heatmap ์ผ๊ฐํ์ผ๋ก ๋ํ๋ด๊ณ ์ถ์๊ฒฝ์ฐ
upp_mat = np.triu(df.corr()) # parameter : mask = upp_mat
# table ์ปฌ๋ผ์ด๋ฆ์ด ๋ค ์๋ณด์ด๋ ๊ฒฝ์ฐ
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', -1)
# ์ปฌ๋ผ๋ช
์๋ณด์ผ ๋
pd.options.display.max_columns = 30
# ์๊ฐํํฐํธ
plt.rc('font', family='Malgun Gothic')
sns.set(font="Malgun Gothic",#"NanumGothicCoding",
rc={"axes.unicode_minus":False}, # ๋ง์ด๋์ค ๋ถํธ ๊นจ์ง ํ์ ํด๊ฒฐ
style='darkgrid')
# Beep
import datetime
import winsound as wd
def beep():
print(datetime.datetime.now())
sd.Beep(2000, 1000)
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import statsmodels.api as sm
import scipy.stats as spst
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_moons, make_classification
from sklearn.model_selection import RandomizedSearchCV, GridSearchCV
from sklearn.model_selection import learning_curve
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LinearRegression
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier, plot_tree # ์๊ฐํ
from sklearn.tree import DecisionTreeRegressor
from sklearn.svm import SVC
# r2_score, mean_squared_error, mean_absolute_error, mean_absolute_percentage_error
from sklearn.metrics import *
from xgboost import XGBClassifier, plot_tree
plt.hist
sns.kdeplot
plt.boxplot
sns.histplot
sns.kdeplot
sns.boxplot
sns.distplot
plt.stem
mean : ํ๊ท
median : ์ค์๊ฐ
mode : ์ต๋น๊ฐ
np.percentile(๋ฆฌ์คํธ, [0, 25, 50, 75, 100])
hist1 = plt.hist(titanic.Fare, bins = 5, edgecolor = 'gray')
plt.show()
print(hist1)
print(type(hist1))
print('-' * 50)
print('๋น๋์ : ', hist1[0])
print('๊ตฌ๊ฐ๊ฐ : ', hist1[1])
'''
(array([838., 33., 17., 0., 3.]), array([ 0. , 102.46584, 204.93168, 307.39752, 409.86336, 512.3292 ]), <BarContainer object of 5 artists>)
<class 'tuple'>
--------------------------------------------------
๋น๋์ : [838. 33. 17. 0. 3.]
๊ตฌ๊ฐ๊ฐ : [ 0. 102.46584 204.93168 307.39752 409.86336 512.3292 ]
'''
sns.kdeplot(titanic['Fare'])
plt.show()
age = [19,20,23,46,21,25,26,25,28,31,37,24,28,34,38,33,32,29,27,24]
box1 = plt.boxplot(age)
plt.show()
print(type(box1))
print(box1.keys())
print('-'* 50)
print(box1['whiskers'])
print(box1['whiskers'][0].get_ydata()) # ์๋์ชฝ ์์ผ์ max, min
print(box1['whiskers'][1].get_ydata()) # ์์ชฝ ์์ผ์ min, max
'''
<class 'dict'>
dict_keys(['whiskers', 'caps', 'boxes', 'medians', 'fliers', 'means'])
--------------------------------------------------
[<matplotlib.lines.Line2D object at 0x00000252A0A19280>, <matplotlib.lines.Line2D object at 0x00000252A0A195E0>]
[24. 19.]
[32.25 38. ]
'''
# ์๊ณ์ด๋ฐ์ดํฐ
air['Date'] = pd.to_datetime(air['Date']) # ๋ ์ง ํ์์ผ๋ก ๋ณํ
plt.plot('Date', 'Ozone', 'g-', data = air, label = 'Ozone')
plt.plot('Date', 'Temp', 'r-', data = air, label = 'Temp')
plt.xlabel('Date')
plt.legend()
plt.show()
sns.histplot(data = titanic, x='Age', bins = 16)
plt.show()
sns.kdeplot(data = titanic, x = 'Age')
plt.show()
sns.boxplot(data = titanic, y = 'Age')
plt.show()
sns.distplot(titanic['Age'], bins = 16, hist_kws = dict(edgecolor='grey'))
plt.show()
x = np.linspace(0.1, 2 * np.pi, 10)
plt.title("Stem Plot")
plt.stem(x, np.cos(x), '-.')
plt.show()
# reference:๋ฐ์ดํฐ์ฌ์ด์ธ์ค์ค์ฟจ
plt.bar
sns.countplot
plt.pie
# ๋ฆฌ์คํธ ๊ธฐ์ดํต๊ณ๋
gender = ['F','M','F','F','F','M','F','M','M']
f_cnt = gender.count('F')
m_cnt = gender.count('M')
total_cnt = len(gender)
print('F', f_cnt, f_cnt/total_cnt)
print('M', m_cnt, m_cnt/total_cnt)
'''
F 5 0.5555555555555556
M 4 0.4444444444444444
'''
# ํ๋ค์ค ๊ธฐ์ดํต๊ณ๋
print(titanic['Pclass'].value_counts())
print(titanic['Pclass'].value_counts()/titanic.shape[0])
'''
3 491
1 216
2 184
Name: Pclass, dtype: int64
3 0.551066
1 0.242424
2 0.206510
Name: Pclass, dtype: float64
'''
temp = titanic['Pclass'].value_counts()
plt.bar(temp.index, temp.values)
plt.show()
sns.countplot(titanic['Pclass'])
plt.show()
''' pie chart
parameter
--------
startangle = 90 : 90๋ ๋ถํฐ ์์
counterclock = False : ์๊ณ ๋ฐฉํฅ์ผ๋ก
explode = [0.05, 0.05,0.05] : ์ค์ฌ์ผ๋ก ๋ถํฐ 1,2,3 ์ ์ผ๋ง๋งํผ ๋์ธ์ง
shadow = True : ๊ทธ๋ฆผ์ ์ถ๊ฐ
'''
temp = titanic['Pclass'].value_counts()
plt.pie(temp.values, labels = temp.index, autopct = '%.2f%%')
plt.show()
plt.pie(temp.values, labels = temp.index, autopct = '%.2f%%',
startangle=90, counterclock=False,
explode = [0.05, 0.05, 0.05], shadow=True)
plt.show()
์๊ด๋ถ์
sns.jointplot
sns.pairplot
plt.scatter
sns.regplot
sns.lineplot
''' ์๊ด๊ณ์์ p-value
-1 ~ 1 : 1์ ๊ฐ๊น์ธ์๋ก ๊ฐํ ์๊ด๊ด๊ณ
p-value : 5% ๋ฏธ๋ง์ด๋ฉด, ์๊ด๊ด๊ณ(๋๋ฆฝ๊ฐ์ค)๊ฐ ์๋ค
'''
spst.pearsonr(air['Temp'], air['Ozone'])
# ๋ฐ์ดํฐํ๋ ์์ผ๋ก ๋ถํฐ ์์นํ ๋ฐ์ดํฐ์ ๋ํ ์๊ด๊ณ์ ๊ตฌํ๊ธฐ
air.corr()
plt.figure(figsize = (8, 8))
sns.heatmap(air.corr(), annot = True, fmt = '.3f', cmap = 'RdYlBu_r', vmin = -1, vmax = 1)
plt.show()
sns.jointplot(x='Petal.Length', y='Petal.Width', data = iris)
plt.show()
sns.jointplot(x='Petal.Length', y='Petal.Width', data = iris, hue = 'Species')
plt.show()
sns.pairplot(iris, hue = 'Species')
plt.show()
plt.scatter('Temp', 'Ozone', data = air)
plt.show()
sns.regplot(x='Temp', y='Ozone', data=air)
plt.show()
sns.lineplot(x = 'param_learning_rate', y = 'mean_test_score', data = temp )
๋ก์ง์คํฑ ํ๊ท
sns.histplot
sns.kdeplot
sns.boxplot
# ๋ก์ง์คํฑ ๋ชจํ :
# current function value๋ ๊ฐ์ค์น
# '1'์ ๊ฐ๊น์ธ์๋ก ์๋ก ์๊ด์ด ์์์ ์ ์ ์์(๋
๋ฆฝ๋ณ์)
model = sm.Logit(titanic['Survived'], titanic['Age'])
result = model.fit()
print(result.pvalues)
'''
Optimization terminated successfully.
Current function value: 0.661967
Iterations 4
Age 3.932980e-13
dtype: float64
'''
sns.histplot(x='Age', data = titanic, hue = 'Survived')
plt.show()
sns.histplot(x='Age', data = titanic, bins = 16
, hue ='Survived', multiple = 'fill')
plt.axhline(titanic['Survived'].mean(), color = 'r')
plt.show()
'''
โก kdeplot( , hue = 'Survived', common_norm = False)
์์กด์ฌ๋ถ ๊ฐ๊ฐ ์๋ ๋ฉด์ ์ ํฉ์ด 1์ธ ๊ทธ๋ํ
โข kdeplot( , hue = 'Survived', multiple = 'fill')
๋์ด์ ๋ฐ๋ผ ์์กด์ฌ๋ถ ๋น์จ์ ๋น๊ตํด๋ณผ ์ ์์. (์์ ๋น๊ต๊ฐ ์๋ ๋น์จ!)
'''
sns.kdeplot(data = titanic, x = 'Age', hue = 'Survived', common_norm = False)
plt.show()
sns.boxplot(data = titanic, y = 'Age', x = 'Survived')
plt.show()
ttest, anova
sns.barplot
sns.histplot
df.boxplot
plt.bar + plt.barh
''' ํ์คํธ์ฐจ
๊ทธ ์ง๋จ ์์์ ๋ํฏ๊ฐ์ผ๋ก ํ๊ท ์ ๊ตฌํ ๋
๊ฐ๋ค์ด ํ๊ท ์ผ๋ก๋ถํฐ ์ผ๋ง๋ ๋ฒ์ด๋ ์๋์ง(์ดํ๋, deviation)๋ฅผ ๋ํ๋ด๋ ๊ฐ
'''
a = np.array([23,54,47,64,29,15])
print(f'ํ๊ท : {a.mean()}') # ํ๊ท : 38.666666666666664
print(f'ํ์คํธ์ฐจ : {a.std()}') # ํ์คํธ์ฐจ : 17.53726191728787
titanic.groupby('Survived')['Age'].agg(['mean','std'])
''' ํ์ค์ค์ฐจ
ํ๋ณธํ๊ท ์ ๋ชจํ๊ท ๊ณผ ์์ ํ ์ผ์นํ ์๋ ์์ต๋๋ค.
์ด ์ค์ฐจ๋ฅผ ํ์ค์ค์ฐจ ๋ผ๊ณ ํฉ๋๋ค.
'''
# ํ์ค์ค์ฐจ
titanic.groupby('Survived')['Age'].agg(['mean','std','sem'])
'''t ํต๊ณ๋
๋ ํ๊ท ์ ์ฐจ์ด๋ฅผ ํ์ค์ค์ฐจ๋ก ๋๋ ๊ฐ.
๊ธฐ๋ณธ์ ์ผ๋ก๋ ๋ ํ๊ท ์ ์ฐจ์ด๋ก ์ดํดํด๋ ์ข์
๊ฐ์ค(๋๋ฆฝ๊ฐ์ค)์ ์ฐจ์ด๊ฐ ์๋ค๋ ๊ฒ์ด๋ฏ๋ก, t ๊ฐ์ด ํฌ๋์ง ์๋์ง
๋ณดํต, t ๊ฐ์ด -2๋ณด๋ค ์๊ฑฐ๋, 2๋ณด๋ค ํฌ๋ฉด ์ฐจ์ด๊ฐ ์๋ค๊ณ ๋ด
'''
temp = titanic.loc[titanic['Age'].notnull()]
died = temp.loc[temp['Survived']==0, 'Age']
survived = temp.loc[temp['Survived']==1, 'Age']
spst.ttest_ind(died, survived)
'''anova
๋ถ์ฐ ๋ถ์ ANalysis Of VAriance
๊ธฐ์ค์ ์ ์ฒด ํ๊ท
๐น ํต๊ณ๋ = (์ง๋จ ๊ฐ ๋ถ์ฐ)/(์ง๋จ ๋ด ๋ถ์ฐ) = (์ ์ฒด ํ๊ท โ ๊ฐ ์ง๋จ ํ๊ท )/(๊ฐ ์ง๋จ์ ํ๊ท โ ๊ฐ๋ณ ๊ฐ)
๊ฐ์ด ๋๋ต 2~3 ์ด์์ด๋ฉด ์ฐจ์ด๊ฐ ์๋ค๊ณ ํ๋จ
'''
P_1 = titanic.loc[titanic.Pclass == 1, 'Age']
P_2 = titanic.loc[titanic.Pclass == 2, 'Age']
P_3 = titanic.loc[titanic.Pclass == 3, 'Age']
spst.f_oneway(P_1, P_2, P_3) # F_onewayResult(statistic=9.762703872790492, pvalue=9.433803581462056e-05)
# ๊ฐ์ด๋ฐ ์ง์ ์ ์ ๋ขฐ๊ตฌ๊ฐ
sns.barplot(x="Embarked", y="Fare", data = titanic)
plt.show()
s0 = titanic.loc[titanic['Survived']==0, 'Age']
s1 = titanic.loc[titanic['Survived']==1, 'Age']
# ์ฌ๋ง์์ ๋์ด ๋ถํฌ
sns.histplot(s0, bins = 16)
plt.axvline(s0.mean(), color='r')
plt.show()
# ๋ฐ์คํ๋กฏ์ผ๋ก ๋น๊ตํด ๋ด
์๋ค.
titanic.boxplot('Age', 'Survived')
plt.show()
np.random.seed(0)
people = ['๋ชฝ๋ฃก', '์ถํฅ', '๋ฐฉ์', 'ํฅ๋จ']
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))
plt.title("Barh Chart")
plt.barh(y_pos, performance, xerr=error, alpha=0.4)
plt.yticks(y_pos, people)
plt.xlabel('x ๋ผ๋ฒจ')
plt.show()
# reference : ๋ฐ์ดํฐ ์ฌ์ด์ธ์ค ์ค์ฟจ
์นด์ด์ ๊ณฑ๊ฒ์
sns.countplot
sns.heatmap
100% stacked bar
mosaic
# ๋ฒ์ฃผ๋ณ ๋น๋์ ๊ต์ฐจํ
pd.crosstab(titanic['Survived'], titanic['Embarked'], normalize = 'columns')
pd.crosstab(titanic['Survived'], titanic['Embarked'], normalize = 'index')
pd.crosstab(titanic['Survived'], titanic['Embarked'], normalize = 'all')
```python
'''์นด์ด ์ ๊ณฑ ํต๊ณ๋
ํด์๋ก ๊ธฐ๋๋น๋๋ก๋ถํฐ ์ค์ ๊ฐ์ ์ฐจ์ด๊ฐ ํฌ๋ค๋ ์๋ฏธ.
๊ณ์ฐ์์ผ๋ก ๋ณผ ๋, ๋ฒ์ฃผ์ ์๊ฐ ๋์ด๋ ์๋ก ๊ฐ์ ์ปค์ง๊ฒ ๋์ด ์์.
๋ณดํต, ์์ ๋์ 2~3๋ฐฐ ๋ณด๋ค ํฌ๋ฉด, ์ฐจ์ด๊ฐ ์๋ค๊ณ ๋ด.
๋ฒ์ฃผํ ๋ณ์์ ์์ ๋ : ๋ฒ์ฃผ์ ์ - 1
Pclass : ๋ฒ์ฃผ๊ฐ 3๊ฐ, Survived : 2๊ฐ
(3-1) * (2-1) = 2
๊ทธ๋ฌ๋ฏ๋ก, 2์ 2 ~ 3๋ฐฐ์ธ 4 ~ 6 ๋ณด๋ค ์นด์ด์ ๊ณฑ ํต๊ณ๋์ด ํฌ๋ฉด, ์ฐจ์ด๊ฐ ์๋ค๊ณ ๋ณผ์ ์์.
๊ฐ์ด 0์ ๊ฐ๊น์ธ์๋ก ๊ด๋ จ์ด ์๋๊ฒ์ด๊ณ
๊ฐ์ด ํด์๋ก ์ฐจ์ด๊ฐ ํฐ ๊ฒ์์ ์ ์ ์์
'''
# ๋จผ์ ์ง๊ณ
table = pd.crosstab(titanic['Survived'], titanic['Pclass'])
print('๊ต์ฐจํ\n', table)
print('-' * 100)
# ์นด์ด์ ๊ณฑ๊ฒ์
result = spst.chi2_contingency(table)
print('์นด์ด์ ๊ณฑํต๊ณ๋', result[0])
print('p-value', result[1])
print('๊ธฐ๋๋น๋\n',result[3])
'''
๊ต์ฐจํ
Pclass 1 2 3
Survived
0 80 97 372
1 136 87 119
----------------------------------------------------------
์นด์ด์ ๊ณฑํต๊ณ๋ 102.88898875696056
p-value 4.549251711298793e-23
๊ธฐ๋๋น๋
[[133.09090909 113.37373737 302.53535354]
[ 82.90909091 70.62626263 188.46464646]]
'''
# ์๋์ง๊ณ
sns.countplot(x="Embarked", data=titanic, hue = 'Survived')
plt.show()
# pivot : dataframe.pivot(index, colums, values)
temp1 = titanic.groupby(['Embarked','Pclass'], as_index = False)['PassengerId'].count()
temp2 = temp1.pivot('Embarked','Pclass', 'PassengerId')
print(temp2)
sns.heatmap(temp2, annot = True)
plt.show()
# 100% stacked bar, Pclass -> Survived
temp = pd.crosstab(titanic['Pclass'], titanic['Survived'], normalize = 'index')
print(temp)
temp.plot.bar(stacked=True)
plt.axhline(1-titanic['Survived'].mean(), color = 'r')
plt.show()
# mosaic : axhline์ ์ ๋ฒ์ด๋๋ฉด '๊ด๋ จ'์ด ์๋ค๋๊ฒ
mosaic(titanic, [ 'Pclass','Survived'])
# ์์์ ๋ ฌ, mosaic(titanic.sort_values(['Pclass', 'Survived']), [ 'Pclass','Survived'], gap = 0.01)
plt.axhline(1- titanic['Survived'].mean(), color = 'r')
plt.show()
confusion_matrix(y_val, pred
print(classification_report(y_val , pred ))
# ์ ๋ถ๋ฅ์จ
accuracy_score(y_val, pred)
# ์ ๋ฐ๋
print(precision_score(y_val, pred, pos_label = 0))
print(precision_score(y_val, pred, pos_label = 1))
# ์ฌํ์จ
print(recall_score(y_val, pred, pos_label = 0))
print(recall_score(y_val, pred, pos_label = 1))
# f1_score
print(f1_score(y_val, pred, pos_label = 0))
print(f1_score(y_val, pred, pos_label = 1))
learning_curve
roc_curve
cross_val_score
''' learning_curve ํจ์
Input
๋ชจ๋ธ, x, y
train_sizes = ์์ฐจ์ ์ผ๋ก ํ์ต์ํฌ ๋ฐ์ดํฐ ์ฌ์ด์ฆ ๋ฆฌ์คํธ(์ต๋ ํฌ๊ธฐ = ์ ์ฒดํฌ๊ธฐ - (์ ์ฒดํฌ๊ธฐ/cv) )
cv = cross validation ์ค์
Output
tr_size : Input์์ ์ง์ ํ ๊ฐ๋ฆฌ์คํธ(train_sizes)
tr_scores : ํ์ต์ฉ ๋ฐ์ดํฐ์์์ ์ฑ๋ฅ
val_scores : validation ์ฑ๋ฅ
'''
# ๋ฐ์ดํฐ ์์ด ๋ง์ ์๋ก ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆฝ๋๋ค.
tr_size, tr_scores, val_scores = learning_curve(model, x, y
, train_sizes = range(5, 3200, 10)
, cv = 5)
# cvํ ๊ฒฐ๊ณผ๋ฅผ ํ๊ท ์ผ๋ก ์ง๊ณ ํฉ์๋ค.
val_scores_mean = val_scores.mean(axis = 1)
val_scores_std = val_scores.std(axis = 1)
# ์ด์ ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋ด
์๋ค.
# Bias๊ฐ ์ค์ด๋๋๊ฐ? (์ฑ๋ฅ์ด ํฅ์๋๋๊ฐ?)
plt.figure(figsize = (10,6))
plt.plot(tr_size, val_scores_mean)
plt.ylabel('val_accuracy')
plt.xlabel('train_size')
plt.grid()
plt.show()
# Variance๊ฐ ์ค์ด๋๋๊ฐ?(์ฑ๋ฅ์ ํธ์ฐจ๊ฐ ์ค์ด๋๋๊ฐ?)
plt.figure(figsize = (10,6))
plt.plot(tr_size, val_scores_std)
plt.ylabel('Variance(val_accuracy)')
plt.xlabel('train_size')
plt.grid()
plt.show()
from sklearn.metrics import roc_curve
# curve plot
fpr, tpr, thresholds = roc_curve(df.species, result.predict(df.sepal_length))
plt.plot(fpr, tpr)
plt.show()
# ๋ชจ๋ธ ์ ์ธ
model = DecisionTreeClassifier(max_depth = 3)
# train + validation set์ ์ด์ฉํ์ฌ ํ์ต, ์์ธก, ํ๊ฐ๋ฅผ ํ๋ฒ์. (์ฌ๊ธฐ์๋ .fit ์ด ์๋!)
dt_result = cross_val_score(model, x, y, cv=10)
print(dt_result)
print(dt_result.mean(), dt_result.std())
'''
[0.66 0.73 0.64 0.68 0.66 0.72 0.63 0.69 0.61 0.73]
0.675 0.040311288741492736
'''
# KNN
# ์ค์ผ์ผ๋ง
scaler = MinMaxScaler()
x = scaler.fit_transform(x)
model_knn = KNeighborsClassifier()
result = cross_val_score(model_knn, x, y, cv = 10)
print(result)
print(result.mean(), result.std())
'''
[0.58 0.59 0.62 0.59 0.52 0.58 0.57 0.63 0.54 0.59]
0.581 0.03112876483254675
'''
fitting graph
DecisionTree
result_train = [] # train set์ ๊ฐ์ง๊ณ ์์ธกํ ๊ฒฐ๊ณผ
result_val = [] # val set์ ๊ฐ์ง๊ณ ์์ธกํ ๊ฒฐ๊ณผ
depth = list(range(1,21))
for d in depth :
model = DecisionTreeClassifier(max_depth = d)
model.fit(x_train, y_train)
pred_tr, pred_val = model.predict(x_train), model.predict(x_val)
result_train.append(accuracy_score(y_train, pred_tr))
result_val.append(accuracy_score(y_val, pred_val))
pd.DataFrame({'max_depth': list(range(1,21)),'train_acc':result_train, 'val_acc':result_val})
plt.figure(figsize = (12,8))
plt.plot(depth, result_train, label = 'train_acc', marker = 'o')
plt.plot(depth, result_val, label = 'val_acc', marker = 'o')
plt.xlabel('Complexity')
plt.ylabel('Accuracy')
plt.legend()
plt.grid()
plt.show()
KNN
result_train = [] # train set์ ๊ฐ์ง๊ณ ์์ธกํ ๊ฒฐ๊ณผ
result_val = [] # val set์ ๊ฐ์ง๊ณ ์์ธกํ ๊ฒฐ๊ณผ
k_values = list(range(1,101))
for k in k_values :
model = KNeighborsClassifier(n_neighbors= k)
model.fit(x_train_s, y_train)
pred_tr, pred_val = model.predict(x_train_s), model.predict(x_val_s)
result_train.append(accuracy_score(y_train, pred_tr))
result_val.append(accuracy_score(y_val, pred_val))
print(k)
plt.figure(figsize = (12,8))
plt.plot(k_values, result_train, label = 'train_acc', marker = 'o')
plt.plot(k_values, result_val, label = 'val_acc', marker = 'o')
plt.xlabel('Complexity')
plt.ylabel('Accuracy')
plt.legend()
plt.grid()
plt.show()