mklearn

mlkit-learn: lightweight machine learning algorithms for learning.


Keywords
machine-learning, python
License
MIT
Install
pip install mklearn==0.0.5

Documentation

mlkit-learn

license pyv pypiv format

mlkit-learn is a lightweight machine learning package designed to be interactive, easy-to-understand, and educational. It implements all of the classic machine learning algorithms from regression to gradient boosting trees. With only two lines of code, users can witness popular Kaggle datasets being preprocessed and predicted in action.

Table of Contents

K-Nearest Neighbors

Multivariate Linear Regression

Naive Bayes

Decision Tree

Logistic Regression

K-Means

Support Vector Machine

Random Forest

Install

pip install mklearn

K-Nearest Neighbors

Demo

  1. download train.csv and put in the directory of your choosing.
  2. run the following code.
from mklearn import knn
knn.demo(5, row=1000) # k [the number of nearest neighbour], dir [default: current directory], row [default: first 5000 rows]

Use

KNN Classifier
from mklearn import knn
model = knn.KNNClassifier(5)
model.fit(train_x, train_y)
size = test_x.shape[0]
predictions = []
for i in range(size):
    result = classifier.predict(test_x[i])
    predictions.append(result)
KNN Regressor
from mklearn import knn
model = knn.KNNRegressor(5)
model.fit(train_x, train_y)
size = test_x.shape[0]
predictions = []
for i in range(size):
    result = classifier.predict(test_x[i])
    predictions.append(result)

Multivariate Linear Regression

Demo

  1. download kc_house_data.csv and put in the directory of your choosing.
  2. run the following code.
from mklearn import mlr
mlr.demo(row=1000) # row [default: first 5000 rows]

Use

from mklearn import mlr
x_train = np.asmatrix(x_train)
x_train = np.append(np.asmatrix(np.tile(1, x_train.shape[0])).transpose(), x_train, axis=1)
x_test = np.append(np.asmatrix(np.tile(1, x_test.shape[0])).transpose(), x_test, axis=1)
y_train = np.ravel(y_train)
y_test = np.ravel(y_test)
model = mlr.MLR()
model.fit(x_train, y_train)
coef = model.coef()
predictions = model.predict(x_test)

Naive Bayes

Decision Tree

Logistic Regression

K-Means

Support Vector Machine

Random Forest