34 lines
621 B
Python
34 lines
621 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
#%%
|
|
# AG1a
|
|
import numpy as np
|
|
import nnwplot
|
|
|
|
def neuron(X):
|
|
N = X.shape[1]
|
|
net = np.zeros(N)
|
|
W = [-0.3,1]
|
|
b = 2 # Bias ... ergibt sich aus Aktivierungsschwelle
|
|
for n in range(0,N):
|
|
for j in range(0,X.shape[0]):
|
|
net[n]+= X[n,j] * W[j]
|
|
# b verwenden ...
|
|
return net > b # threshold ....
|
|
|
|
#%%
|
|
iris = np.loadtxt("iris.csv",delimiter=',')
|
|
|
|
# X=iris[:,:2].T # nur die ersten 2 Merkmale anschauen und in Spaltenvektoren umwandeln
|
|
T=iris[-1]
|
|
|
|
# print(X)
|
|
# print(T)
|
|
print(X.shape[0])
|
|
neuron(X)
|
|
|
|
#%%
|
|
# AG1b
|
|
nnwplot.plotTwoFeatures(X[...], T, neuron)
|
|
|
|
# %% |