Git Product home page Git Product logo

first-perceptron's Introduction

๐Ÿง  First Perceptron

Description

This is a simple implementation of a Perceptron in Python. ๐Ÿค– Implemented as a class, it can be used to train a Perceptron with a given dataset and then use it to predict the output of a given input.

Usage

The Perceptron class is located in the file perceptron.py and can be imported as follows:

from perceptron import Perceptron

Example

The following example shows how to use the Perceptron class to train a Perceptron with a given dataset and then use it to predict the output of a given input.

import numpy as np
import pandas as pd
from perceptron import Perceptron


def classify(x: list, ppn: Perceptron) -> str:
    """
    Classify the given data
    :param list x: list of data to classify
    :param Perceptron ppn: Perceptron to use
    :return: str - classification
    """
    if ppn.predict(x) == -1:
        return "Iris-setosa"
    else:
        return "Iris-versicolor"


df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', header=None)

df.tail()

y = df.iloc[0:100, 4].values
y = np.where(y == 'Iris-setosa', -1, 1)

X = df.iloc[0:100, [0, 1, 2, 3]].values

ppn = Perceptron(eta=0.01, n_iter=50)
ppn.fit(X, y)

print(ppn.errors_)
print(ppn.w_)
print(classify([5.2, 2.7, 3.9, 1.4], ppn)) # Iris-versicolor

first-perceptron's People

Contributors

eduumach avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.