Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 866 Bytes

applications.org

File metadata and controls

34 lines (26 loc) · 866 Bytes

Applications

Perceptron example

import importlib
import pandas as pd
import numpy as np
from sklearn import datasets

import mle.classifiers as melc
importlib.reload(melc)

iris = datasets.load_iris()
names = ["Class"] + iris.feature_names
df = pd.DataFrame(np.hstack((iris.target.reshape(len(iris.data), 1), iris.data)), columns = names)
df = df[df.Class <= 1]
df.Class = df.Class.apply(lambda x: 1 if x == 0.0 else -1)

p = melc.Perceptron(eta = 0.01, N = 25)
p.fit(df.drop("Class", axis = 1).to_numpy(), df.Class.to_numpy())
print(p.w)
print(p.errors)