This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sklearn.datasets | |
import numpy as np | |
import pandas as pd | |
breast_cancer = sklearn.datasets.load_breast_cancer() | |
X = breast_cancer.data | |
Y = breast_cancer.target | |
#Converting the data to Pandas dataframe | |
data = pd.DataFrame(breast_cancer.data, columns=breast_cancer.feature_names) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MPNeuron: | |
def __init__(self): | |
self.b = None | |
def model(self, x): | |
return(sum(x) >= self.b) | |
def predict(self, X): | |
Y = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import packages | |
import sklearn.datasets | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from sklearn.model_selection import train_test_split | |
#load the breast cancer data | |
breast_cancer = sklearn.datasets.load_breast_cancer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Perceptron: | |
#constructor | |
def __init__ (self): | |
self.w = None | |
self.b = None | |
#model | |
def model(self, x): | |
return 1 if (np.dot(self.w, x) >= self.b) else 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Perceptron: | |
#constructor | |
def __init__ (self): | |
self.w = None | |
self.b = None | |
#model | |
def model(self, x): | |
return 1 if (np.dot(self.w, x) >= self.b) else 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perceptron = Perceptron() | |
#epochs = 10000 and lr = 0.3 | |
wt_matrix = perceptron.fit(X_train, Y_train, 10000, 0.3) | |
#making predictions on test data | |
Y_pred_test = perceptron.predict(X_test) | |
#checking the accuracy of the model | |
print(accuracy_score(Y_pred_test, Y_test)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#toy data | |
X = [0.5,2.5] | |
Y = [0.2,0.9] | |
import numpy as np | |
import matplotlib.pyplot as plt | |
w_values = [] | |
b_values = [] | |
loss_values = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.colors | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import accuracy_score, mean_squared_error | |
from tqdm import tqdm_notebook | |
from sklearn.preprocessing import OneHotEncoder | |
from sklearn.datasets import make_blobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#creating my own color map for better visualization | |
my_cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", ["red","yellow","green"]) | |
#Generating 1000 observations with 4 labels - multi class | |
data, labels = make_blobs(n_samples=1000, centers=4, n_features=2, random_state=0) | |
print(data.shape, labels.shape) | |
#visualize the data | |
plt.scatter(data[:,0], data[:,1], c=labels, cmap=my_cmap) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SigmoidNeuron: | |
#intialization | |
def __init__(self): | |
self.w = None | |
self.b = None | |
#forward pass | |
def perceptron(self, x): | |
return np.dot(x, self.w.T) + self.b | |
def sigmoid(self, x): |
OlderNewer