In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces python how to achieve perceptron learning algorithm, the article introduces in great detail, has a certain reference value, interested friends must read it!
We will study a discriminant classification method, in which we directly learn the w parameters needed to evaluate g (x). We will use perceptrons to learn algorithms.
The perceptron learning algorithm is easy to implement, but to save time, I provide you with an implementation below. This function has several inputs: training data, training label, initial guess of weight, and learning rate. Note that for both classes, the value of the class label must be + 1 and-1.
It will return a tuple that contains:
1. Learning w parameters
two。 Number of iterations performed
3. Number of samples misclassified
Take some time to check the code. If you don't know how each line works, don't worry, just let yourself know what each line is for. There are some comments in the code that can help you.
Def perce (X, y, w_init, rho, max_iter=1000): (n, nfeatures) = X.shape # Augment the feature vectors by adding a 1 to each one. (see lecture notes) X = np.hstack ((X, np.ones ((N, 1) nfeatures + = 1 w = w_init # initialise weights iter = 0 mis_class = N # start by assuming all samples are misclassified while mis_class > 0 and iter < max_iter: iter + = 1 mis_class = 0 gradient = np.zeros (nfeatures) # initaliase the gradients to 0 # loop over every training sample. For i in range (N): # each misclassified point will cause the gradient to change if np.inner (X [I,:], w) * y [I] 0 and iter < max_iter: iter + = 1 # Compute set of misclassified points mc = (np.dot (X, w.transpose ()) * y)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.