Data analysis using Go machine learning Libraries Authoring 3 (average Perceptron)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Catalogue [−]

    1. 1984 U.S. Congressional voting record data set
    2. Average Perceptron
    3. Code
    4. Evaluation results

This time, we use the average Perceptron (Average Perceptron) algorithm to predict the U.S. congressional vote.

1984 U.S. Congressional voting record data set

This time, we use the 1984 congressional voting record to predict the outcome of the poll.

The data set is divided into 16 categories for different voting topics, which document the results of Democratic and Republican lawmakers ' votes.

The format is as follows

123456789101112131415
v16,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,party1,-1,1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,republican- 1,-1,1,-1,1,1,1,-1,-1,- 1,-1,-1,1,1,1,-1, Republican- 1,-1,1,1,-1,1,1,-1,-1,- 1,-1,1,-1,1,1,-1, Democrat1,-1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,1,-1,-1,democrat1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,1,democrat1,-1,1,1,- 1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,democrat1,-1,1,-1,1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,democrat1,-1,1,-1,1,1,1,-1,-1,- 1,-1,-1,-1,1,1,-1,republican1,-1,1,-1,1,1,1,-1,-1,-1,-1,-1,1,1,1,-1,republican- 1,1,1,1,-1,-1,-1,1,1, 1,-1,-1,-1,-1,-1,-1, Democrat- 1,-1,1,-1,1,1,-1,-1,-1,- 1,-1,-1,-1,1,1,-1, Republican- 1,-1,1,-1,1,1,1,-1,-1,- 1,-1,1,-1,1,1,-1, Republican......

This time, we will also divide the dataset into training data and test data to assess the accuracy of the algorithm's prediction results.

Average Perceptron

Perceptron algorithm a two-part classifier for supervised learning is a kind of linear classifier.

Perceptron algorithm is a very good two classification algorithm, the algorithm to get a separation of super-plane, the super-plane is parameterized by W and used to predict, for a sample x, the perceptron algorithm by calculating y = [w,x] to predict the label of the sample, the final prediction label by the calculation of sign (y) to achieve. The algorithm only corrects the weighted w when predicting errors.
The average perceptron and perceptual machine algorithm training method is the same, the difference is that after each training sample XI, retain the weight of the previous training, the average value of ownership after the end of training. Finally, the weighted value of the mean weight is used as the final criterion. The parameter averaging can overcome the oscillation phenomenon in the training process caused by the learning rate too large.

Code

12345678910111213141516171819202122232425262728293031323334
 PackageMainImport("FMT"Base"Github.com/sjwhitworth/golearn/base"Evaluation"Github.com/sjwhitworth/golearn/evaluation"Perceptron"Github.com/sjwhitworth/golearn/perceptron""Math/rand")funcMain () {rand. Seed(4402201) RawData, err: = base. Parsecsvtoinstances (".. /datasets/house-votes-84.csv ",true)ifErr! =Nil{Panic(ERR)}//initialises A new Averageperceptron classifierCLS: = Perceptron. Newaverageperceptron(Ten,1.2,0.5,0.3)//do a training-test splitTraindata, TestData: = base. Instancestraintestsplit (RawData,0.50) FMT. Println (Traindata) fmt. Println (TestData) CLS. Fit (traindata) Predictions: = CLS. Predict (TestData)//Prints Precision/recall metricsConfusionmat, _: = Evaluation. Getconfusionmatrix (testData, predictions) fmt. PRINTLN (evaluation. Getsummary (Confusionmat))}

First read into the congressional voting data set.

Then create an instance of the average perceptron algorithm.

The dataset is then divided into two parts, one training data and one for prediction and evaluation.

Finally, the evaluation results are printed.

Evaluation results

12345
Reference classtrue Positivesfalse positivestrue NegativesPrecisionRecallF1 score---------------------------------------------------------------------------------democrat9824700.80330.68060.7368republican7046980.60340.74470.6667Overall accuracy: 0.7059

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.