IIS_2023_1/abanin_danill_lab_6/lab6.py
BossMouseFire 0e5a5ad282 lab6
2023-10-29 00:29:45 +04:00

46 lines
1.2 KiB
Python

from matplotlib import pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
import pandas as pd
import numpy as np
def test_iter(iters_num, x_train, x_test, y_train, y_test):
print("Количество итераций: ", iters_num)
scores = []
for i in range(10):
neuro = MLPClassifier(max_iter=iters_num)
neuro.fit(x_train, y_train.values.ravel())
score = neuro.score(x_test, y_test)
print(f'Оценка №{i + 1} - {score}')
scores.append(score)
mean_value = np.mean(scores)
print(f"Средняя оценка - {mean_value}")
return mean_value
def start():
data = pd.read_csv('loan.csv')
x = data[['ApplicantIncome', 'LoanAmount', 'Credit_History', 'Self_Employed', 'Education', 'Married']]
y = data[['Loan_Status']]
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.1, random_state=42)
iters = [200, 400, 600, 800, 1000]
iters_means = []
for i in range(len(iters)):
mean_value = test_iter(iters[i], x_train, x_test, y_train, y_test)
iters_means.append(mean_value)
plt.figure(1, figsize=(16, 9))
plt.plot(iters, iters_means, c='r')
plt.show()
start()