• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

FlorianMuellerklein/Machine-Learning: Machine learning library written in readab ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

FlorianMuellerklein/Machine-Learning

开源软件地址(OpenSource Url):

https://github.com/FlorianMuellerklein/Machine-Learning

开源编程语言(OpenSource Language):

Jupyter Notebook 63.4%

开源软件介绍(OpenSource Introduction):

Machine-Learning

Various machine learning algorithms broken down in basic and readable python code. Useful for studying and learning how the algorithms function.

  • MultiLayerPerceptron.py - Basic multilayer perceptron neural network written with numpy. With weight decay regularization, learning rate decay, softmax or logistic sigmoid output layer, and tanh hidden layer.

  • LinearRegression.py - Gradient descent linear regression with l2 regularization.

  • LogisticRegression.py - Gradient descent logistic regression with l2 regularization.

Usage

MultiLayerPerceptron

Parameters

-input (int): Size of input layer, must match the number of features in the input dataset.

-hidden (int): Size of hidden layer, more hidden neurons can model more complex data at the cost of potentially overfitting.

-output (int): Size of output layers, must match the number of possible classes. Can use 1 for binary classification.

-iterations (int): controls the number of passes over the traning data (aka epochs). Defaults to 50

-learning_rate (float): The learning rate constant controls how much weights are updated on each iteration. Defaults to 0.01.

-l2_in (float): Weight decay regularization term for the input layer weights, keeps weights low to avoid overfitting. Useful when hidden layer is large. Defaults to 0 (off).

-l2_out (float): Weight decay regularization term for the hidden layer weights, keeps weights low to avoid overfitting. Useful when hidden layer is large. Defaults to 0 (off).

-momentum (float): Adds a fraction of the previous weight update to the current weight update. Is used to help system from converging at a local minimum. A high value can increase the learning speed but risks overshooting the minimum. A low momentum can get stuck in a local minimum and decreases the speed of learning. Defaults to 0 (off).

-rate_decay (float): How much to decrease learning rate on each iteration. The idea is to start with a high learning rate to avoid local minima and then slow down as the global minimum is approached. Defaults to 0 (off).

-output_layer (string): Which activation function to use for the output layer. Currently accepts 'logistic' for logistic sigmoid or 'softmax' for softmax. Use softmax when the outputs are mutually exclusive. Defaults to 'logistic'.

-verbose (bool): Whether to print current error rate while training. Defaults to True.

Fitting and predicting

  1. Initialize the network and setting up the size of each layer.
NN = MLP_Classifier(64, 100, 10)
  1. Train the network with the training dataset. The training dataset must be in the following format with y values one hot encoded. There is an example in the demo function of the MLP on how to import data with numpy and get it into the appropriate format.
	[[[x1, x2, x3, ..., xn], [y1, y2, ..., yn]],
    [[[x1, x2, x3, ..., xn], [y1, y2, ..., yn]],
    ...
    [[[x1, x2, x3, ..., xn], [y1, y2, ..., yn]]]
NN.fit(train)
  1. Make predictions on testing dataset. Same format as training dataset without the list of y values. Will return a list of predictions.
NN.predict(X_test)

Linear and Logistic Regression

Parameters

-learning_rate (float): The learning rate constant controls how much weights are updated on each iteration. Defaults to 0.01.

-iterations (int): controls the number of passes over the traning data (aka epochs). Defaults to 50.

-intercept (bool): Whether or not to fit an intercept. Defaults to True.

-L2 (float): Weight decay regularization term for the weights, keeps weights low to avoid overfitting. Defaults to 0 (off).

-tolerance (float): The error value in which to stop training. Defaults to 0 (off).

-verbose (bool): Whether to print current error rate while training. Defaults to True.

Fitting and predicting

  1. Initialize the linear model.
linearReg = LinReg(learning_rate = 0.1, iterations = 500, verbose = True, l2 = 0.001)
  1. Train the model with the training dataset. The training dataset has to be a numpy array, the X and y values must be seperated into two different arrays.
linearReg.fit(X = X_train, y = y_train)
  1. Make predictions on testing dataset. Same format as training dataset without the array of y values. Will return a list of predictions.
linearReg.predict(X_test)

Logistic regression has one extra parameter for .predict. If labels is set to 'True' the predicted class is returned, otherwise the probability of the class being label 1 is returned.

logit.predict(X_test, labels = True)



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap