Using Fregata to realize spark logical regression algorithm _spark

Source: Internet
Author: User
 
Import Fregata.spark.data.LibSvmReader Import fregata.spark.metrics.classification. {Areaunderroc, accuracy} import fregata.spark.model.classification.LogisticRegression import Org.apache.spark.
  {sparkconf, sparkcontext}/** * Created by all on 2016/12/8. */Object Fregatafirsttest {def main (args:array[string]): unit = {val conf=new sparkconf (). Setappname ("Test"). Set Master ("local") Val sc=new sparkcontext (conf)//Read data val (_,traindata) =libsvmreader.read (SC,/fre) via the Fregata API GATADATA/A9A ", 123) Val (_,testdata) =libsvmreader.read (SC,"/FREGATADATA/A9A.T ", 123)//Use training data to build a logical regression model Val model= Logisticregression.run (Traindata)///Use test data prediction category Val Pd=model.classpredict (testData)//Evaluate model Val by AUC or other metrics
      Acc=accuracy.of (pd.map{case (x,l), (p,c) => c-> L}) Val Auc=areaunderroc.of (pd.map{ Case ((x,l), (p,c)) => p-> L}) Val loss = Fregata.spark.loss.log (pd.map{case ((x,l), (P,C))
    =>    if (L = = 1d) {(l,c,p)}else{(L, C, 1-p)}}) println (s) areaunderro c = $auc ") println (S" accuracy = $ACC ") println (S" logloss = $loss ")}}
The API for Fregata training data requires a data type of rdd[(Fregata. Vector,fregata. Num)], the predicted API needs to be the same as the training data type or Rdd[fregata. Vector]
The data format

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.