Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from sklearn import datasets
- from sklearn import preprocessing
- from sklearn.utils import shuffle
- from matplotlib import pyplot as plt
- import math
- np.set_printoptions(threshold=np.inf)
- # load dataset
- iris = datasets.load_iris()
- X, labels = iris.data, iris.target
- X, labels = shuffle(X, labels)
- onehot_encoder = preprocessing.OneHotEncoder(sparse=False)
- labels = labels.reshape(-1, 1)
- # normalize input data
- X = 2.0 * X / np.max(X) - 1.0
- Y = onehot_encoder.fit_transform(labels)
- # insert activation function and derivative here
- # randomly initialize weights with mean 0
- losses = []
- for epoch in range(100):
- for j in range(len(X)):
- # forward pass
- # error
- error = ...
- # backward pass
- # weights update
- losses.append(np.sum(np.abs(error)))
- plt.plot(losses)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement