Как проверить оценку качества сети
У меня есть Персептрон с функцией активацией сигмоида. Мне необходимо оценить качество сети. Не могу разобраться с этим.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
iris_x = iris.iloc[:, 2:4].to_numpy()
shape = iris.shape
w0 =np.full((shape[0],1), [1])
iris_x = np.append(iris_x, w0, axis=1)
iris_y = iris.iloc[:, 4].to_numpy()
iris_y = np.where(iris_y== "setosa", 0, 1)
iris_y = np.reshape(iris_y, (-1,1))
shuffling = np.append(iris_x, iris_y, axis=1)
iris_x = shuffling[:,:-1]
iris_y = shuffling[:,-1]
Iters = 1000
no_of_inputs = 2
weights = np.random.randn(no_of_inputs + 1)
print("initial: " + str(weights))
learning_rate = 0.1
correct = 0
for i in range(Iters):
for _input, label in zip(iris_x, iris_y):
summation = np.dot(_input, weights)
# Функция активации (сигмоида)
predicted = 1 / (1 + np.exp(-summation))
if predicted == label:
correct += 1
weights += learning_rate * (label - predicted) * _input
print("trained: ", str(weights))
accuracy = (correct / Iters) / len(iris_x)
print("Accuracy ", str(accuracy))
p1 = abs((weights[2]/weights[1]))
p2 = abs((weights[2]/weights[0]))
iris2 = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
indexsetosa = iris2[iris2['species'] == "setosa"].index
iris2.drop(indexsetosa, inplace=True)
iris_x2 = iris2.iloc[:, 2:4].to_numpy()
shape = iris2.shape
w0 =np.full((shape[0],1), [1])
iris_x2 = np.append(iris_x2, w0, axis=1)
iris_y2 = iris2.iloc[:, 4].to_numpy()
iris_y2 = np.where(iris_y2== "virginica", 1, 0)
iris_y2 = np.reshape (iris_y2,(-1,1))
shuffling = np.append(iris_x2, iris_y2, axis=1)
np.random.shuffle(shuffling)
iris_x2 = shuffling[:,:-1]
iris_y2 = shuffling[:,-1]
Iters = 5000
no_of_inputs = 2
weights2 = np.random.randn(no_of_inputs + 1)
print("initial: " + str(weights2))
learning_rate = 0.1
correct2 = 0
for fdf in range(Iters):
for _input, label in zip(iris_x2, iris_y2):
summation = np.dot(_input, weights2)
# Функция активации (сигмоида)
predicted = 1 / (1 + np.exp(-summation))
if predicted == label:
correct2 += 1
weights2 += learning_rate * (label - predicted) * _input
print("trained: ", str(weights2))
accuracy2 = (correct2 / Iters) / len(iris_x2)
print("Accuracy ", str(accuracy2))
pp1 = abs((weights2[2]/weights2[1]))
pp2 = abs((weights2[2]/weights2[0]))
print("point 1 :", str(pp1))
print("point 2: ", str(pp2))
groups = iris.groupby("species")
for name, group in groups:
plt.plot(group["petal_length"], group["petal_width"], marker="o", linestyle="", label=name)
plt.grid()
plt.rcParams["figure.figsize"] = (10,10)
plt.title("Petal Comparison", fontsize=20)
plt.xlabel('Petal Length', fontsize=15)
plt.ylabel('Petal Width', fontsize=15)
plt.plot([0, pp1], [pp2, 0], c="cyan", label ="perceptron 2")
plt.plot([0, p1], [p2, 0], c="red", label="perceptron 1")
plt.legend(loc="lower right")
plt.show()