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.
pip install mklearn
- download train.csv and put in the directory of your choosing.
- 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]
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)
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)
- download kc_house_data.csv and put in the directory of your choosing.
- run the following code.
from mklearn import mlr
mlr.demo(row=1000) # row [default: first 5000 rows]
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)