Classification
Module for classification tasks. The classes in this module accept a ndarray of the values to be inputted (X) and a ndarray of the classes of the output. Their predict methods output the class of the supplied values.
- class mapyl.classification.SoftMaxClasser(c=2, lr=0.01)[source]
SoftMax classifier instance
- Parameters:
c (int): The number of classes. Defaults to 2
lr (float): The learning rate. Defaults to 0.01
Usage:
>>> X = np.array([[4, -3], [9, -6], [3, -5], [4, -3], [9, -5,]]) >>> y = np.array([[0], [1], [0], [0], [1]]) >>> SMC = SoftMaxClasser(2) >>> SMC.fit(X, y) >>> print(SMC.predict(np.array([[9, -7]]))) >>> [1]
- class mapyl.classification.SVM(lr=0.001, lam=0.01, degree=1)[source]
Support Vector Machine instance
- Parameters:
lr (float): float of the learning rate. Defaults to 0.001
lam (float): float of the regularization parameter. defaults to 0.01
degree (int): int of the poly degree (1 for linear). Defaults to 1
Warning
The SVM instance does a polynomial expansion in order to work when the degree is over 1, so if there are too many degrees or too many features you can have overflow
- Usage:
>>> X = np.array([[4, -3], [9, -6], [3, -5], [4, -3], [9, -5,]]) >>> y = np.array([[0], [1], [0], [0], [1]]) >>> SVM_ = SVM(lr=0.01, lam=0.01, iters=300, degree=1) >>> SVM_.fit(X, y) >>> print(SVM_.predict(np.array([[9, -7]]))) >>> [1]
- class mapyl.classification.KNearestNeighbors(K=5)[source]
KNearest Neighbors instance for classification
- Parameter:
K (int): the number of nearest neighbors. Defaults to 5
- Usage:
>>> X = np.array([[4, -3], [9, -6], [3, -5], [4, -3], [9, -5,]]) >>> y = np.array([[0], [1], [0], [0], [1]]) >>> KNN = KNearestNeighbors(K=3) >>> KNN.fit(X, y) >>> print(KNN.predict(np.array([[9, -7]]))) >>> [1]