<jupyter_start><jupyter_text>Perceptrón simpleClase del perceptrón simple<jupyter_code>import numpy as np
from sklearn.preprocessing import MinMaxScaler

class PerceptronSimple(object):
    def __init__(self,n_inputs,pesos=[],bias=0):
        self.bias = bias
        if len(pesos) == 0:
            self.pesos = np.random.random(n_inputs)
            self.pesos -= 0.5
        elif len(pesos) == n_inputs:
            self.pesos = pesos
        else:
            raise Exception()
            
    def predict(self,data):
        output = np.zeros(data.shape[0])
        for i,sample in enumerate(data):
            # Sumatorio de productos
            out = 0
            for j,inp in enumerate(sample):
                out += inp*self.pesos[j]
            out += self.bias
            # Funcion de activacion
            output[i] = np.sign(out)
        return output
    
    def get_params(self):
        return (self.pesos,self.bias)
    
    def train(self,x,y):
        fail = True
        while fail:
            print(self.get_params())
            fail = False
            # EPOCA
            output = self.predict(x)
            for i in range(x.shape[0]):
                if abs(output[i] - y[i,0]) > 0.1:
                    for j in range(len(self.pesos)):
                        w = y[i,0]*x[i,j]
                        self.pesos[j] += w
                        self.bias += y[i,0]
                    fail = True
            
    
            
            
        
            
original = np.array([
    [1,1,1],
    [2,1,1],
    [2,2,1],
    [1,3,1],
    [-1,1,-1],
    [0,2,-1],
    [-1,3,-1]
])
data = np.zeros(original.shape)
data[:,[0,1]] = MinMaxScaler().fit(original[:,[0,1]]).transform(original[:,[0,1]])
data[:,[2]] = original[:,[2]]
p = PerceptronSimple(2,[0.75,1],-3)
p.train(data[:,[0,1]],data[:,[2]])
p.predict(data[:,[0,1]])
p.get_params()<jupyter_output><empty_output><jupyter_text>Adaline[Dataset computer hardware](http://archive.ics.uci.edu/ml/datasets/Computer+Hardware)<jupyter_code>import numpy as np
import pandas as pd

df = pd.read_csv("machine.data",header=None)
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
from sklearn.preprocessing import MinMaxScaler

X = MinMaxScaler().fit(df[[2,3,4,5,6,7,8]]).transform(df[[2,3,4,5,6,7,8]])

Y = MinMaxScaler().fit(df[9].reshape(-1,1)).transform(df[9].reshape(-1,1))

x_train,x_test,y_train,y_test = train_test_split(X,Y,test_size=0.33)
adaline = MLPRegressor(hidden_layer_sizes=[],solver="sgd",alpha=0.1,batch_size=1,max_iter=5000,momentum=0,verbose=True)
adaline.fit(x_train,y_train)
y_predict = adaline.predict(x_test)
ok_matrix = np.abs(y_predict - y_test[:,0]) < 0.1
success = np.sum(ok_matrix)/ok_matrix.shape[0]
print("Tasa de acierto: %f" % success)
print("Tasa de error: %f" % (1-success))<jupyter_output>Tasa de acierto: 0.855072
Tasa de error: 0.144928
{'fraction_non_alphanumeric': 0.1559380378657487, 'fraction_numerical': 0.0351118760757315, 'mean_word_length': 2.5012048192771084, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '230090', 'license': 'Unlicense', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1061, 'n_words': 174, 'path': 'Perceptron simple y ADALINE.ipynb', 'repo_name': 'aarroyoc/AprendizajeAutomatico', 'size': '2905'}