Skip to content

Instantly share code, notes, and snippets.

@arikaa
arikaa / perceptron.py
Last active July 17, 2018 02:50
Perceptron classifier function
import numpy as np
def perceptron(data, label, iteration, y):
'''
The perceptron classifier
Arguments
data: This is the training data with a certain shape (x, y), meaning there are x samples and each sample has y features.
label: This is the training data's label with shape (x, 1). The 1 corresponds to the correct classification of the data.
iteration: This is the number of times the function will iterate.
@arikaa
arikaa / thirdorderpoly.py
Last active July 17, 2018 03:00
3rd order polynomial transform
def thirdorder(data):
'''
3rd order polynomial transform of data
Arguments
data: The input data is assumed to have shape (:, 3). The first dimension represents
the total samples and the second dimension represents the total features.
Returns
result: A numpy array format of the new data with shape (:,10), where the feature
numbers are extended.
'''
@arikaa
arikaa / logreg.py
Last active July 17, 2018 03:12
Logistic regression classifier
import numpy as np
def logistic_regression(data, label, iteration, learning_rate):
'''
Logistic regression classifier
Arguments
data: This is the training data with shape (n, d), which corresponds to n samples and each sample has d features.
label: This is the training data's label with shape (n,1). The 1 corresponds to the correct classification of the data.
iteration: The number of times to iterate.