My problem is that after finishing all of my implementation , i find it hard to do the plotting .
You can say I am just not familiar enough with how it works.
can you please help me with this plotting this implementation, just the linear model? It's an implementation for Logistic Regression .
Beside that please do provide me with some tutorials ,that help me improve my understanding of plotting in general.
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import datasets
import seaborn as sns
import matplotlib.pyplot as plt
def sigmoid(x):
return 1/(1+np.exp(-x))
class LogisticRegression():
def __init__(self, lr=0.001, n_iters=1000):
self.lr = lr
self.n_iters = n_iters
self.weights = None
self.bias = None
def fit(self, X, y):
n_samples, n_features = X.shape
self.weights = np.zeros(n_features)
self.bias = 0
for _ in range(self.n_iters):
linear_pred = np.dot(X, self.weights) + self.bias
predictions = sigmoid(linear_pred)
dw = (1/n_samples) * np.dot(X.T, (predictions - y))
db = (1/n_samples) * np.sum(predictions-y)
self.weights = self.weights - self.lr*dw
self.bias = self.bias - self.lr*db
def predict(self, X):
linear_pred = np.dot(X, self.weights) + self.bias
y_pred = sigmoid(linear_pred)
class_pred = [0 if y<=0.5 else 1 for y in y_pred]
return class_pred
# training
bc = datasets.load_breast_cancer()
X, y = bc.data, bc.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1234)
clf = LogisticRegression(lr=0.01)
clf.fit(X_train,y_train)
y_pred = clf.predict(X_test)
def accuracy(y_pred, y_test):
return np.sum(y_pred==y_test)/len(y_test)
acc = accuracy(y_pred, y_test)
print('implementaion runs with an accuracy equals to :',acc)
#plot
++++