У меня есть некоторые данные в форме таблицы для задачи классификации. Первые два столбца - это отметки в 1-м и 2-м семестрах, а в 3-м столбце - «да» или «нет», если студент был принят или нет. Я довольно новичок в машинном обучении, и я построил эти базовые c данные, используя pyplot, где код выглядит примерно так: -
plt.scatter(x['Sem1'],x['Sem2'],c=x['Decision'])
Что выводит: - введите описание изображения здесь
После применения градиентного спуска для регрессии Logisti c я получил значения тэты и мои предсказанные значения. Я хочу знать, как я могу подогнать границы моего решения к приведенному выше графику. Не могли бы вы, ребята, сохранить это просто, так как я довольно новичок и не очень разбираюсь в визуализации данных. Для справки, вот весь мой код: -
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(z):
sig=(1/(1+np.exp(-z)))
return sig
def gradient(xtrain,q,ytrain,xtest,ytest):
a=0.01
for i in range(0,1):
h=sigmoid(f @ q.T)
J = (-1/m)*(np.log(h).T.dot(-y)+np.log(1-h).T.dot(1-y)) #COST FUNCTION
q = q - (a/o) * np.sum( (h-y).dot(f),axis=0)
L=[]
''' Predicted values for test set after Gradient execution'''
for i in sigmoid(xtest @ q.T):
if i<0.5 :
L.append(0)
else:
L.append(1)
''' Getting the data '''
x=pd.read_csv('ex2data1.txt',names=['Sem1','Sem2','Decision'])
y=x.iloc[:,2:3].values
m=x['Sem1'].size
x=(x-x.mean())/x.std() #normalize
f=np.stack((np.ones(m),x['Sem1'],x['Sem2']),axis=1) # this is features array
''' Plotting initial data '''
plt.scatter(x['Sem1'],x['Sem2'],c=x['Decision'])
''' this section is ONLY to split the data , sklearn is not used for calculations in this code'''
from sklearn.model_selection import train_test_split
xtrain, xtest, ytrain, ytest = train_test_split( f, y, test_size = 0.25, random_state = 0)
''' '''
o=xtrain.size
f=np.stack((np.ones(m),x['Sem1'],x['Sem2']),axis=1) # this is features array
q=np.zeros(x.shape[1])
gradient(xtrain,q,ytrain,xtest,ytest)