Giter Club home page Giter Club logo

spark-fm's Introduction

Spark-FM

Factorization Machines is a general predictor like SVMs but is also able to estimate reliable parameters under very high sparsity. However, they are costly to scale to large amounts of data and large numbers of features. Spark-FM is a parallel implementation of factorization machines based on Spark. It aims to utilize Spark's in-memory computing to address above problems.

Highlight

In order to meet users' demands, Spark-FM supports various of optimization methods to train the model as follows.

  • Mini-batch Stochastic Gradient Descent (MLlib)
  • L-BFGS (MLlib)
  • Parallel Stochastic Gradient Descent (spark-optim)
  • Parallel Ftrl (spark-optim)

Examples

Scala API

val spark = SparkSession
  .builder()
  .appName("FactorizationMachinesExample")
  .master("local[*]")
  .getOrCreate()

val train = spark.read.format("libsvm").load("data/a9a.tr")
val test = spark.read.format("libsvm").load("data/a9a.te")

val trainer = new FactorizationMachines()
  .setAlgo(Algo.fromString("binary classification"))
  .setSolver(Solver.fromString("pftrl"))
  .setDim((1, 1, 8))
  .setReParamsL1((0.1, 0.1, 0.1))
  .setRegParamsL2((0.01, 0.01, 0.01))
  .setAlpha((0.1, 0.1, 0.1))
  .setBeta((1.0, 1.0, 1.0))
  .setInitStdev(0.01)
  // .setStepSize(0.1)
  .setTol(0.001)
  .setMaxIter(1)
  .setThreshold(0.5)
  // .setMiniBatchFraction(0.5)
  .setNumPartitions(4)

val model = trainer.fit(train)
val result = model.transform(test)
val predictionAndLabel = result.select("prediction", "label")
val evaluator = new MulticlassClassificationEvaluator().setMetricName("accuracy")
println("Accuracy: " + evaluator.evaluate(predictionAndLabel))
spark.stop()

Requirements

Spark-FM is built against Spark 2.1.1.

Build From Source

sbt package

Licenses

Spark-FM is available under Apache Licenses 2.0.

Contact & Feedback

If you encounter bugs, feel free to submit an issue or pull request. Also you can mail to:

spark-fm's People

Contributors

hibayesian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

spark-fm's Issues

How to save the trained model and load the saved model?

Hi ,hibayesian !Thanks a lot for spark-fm sharing.I have checked the sample code which uses model=train.fit(trainData) and model.transform(testData) for prediction.
My concern is that how can I save the trained model in local txt and load it in future use.
I only found the related weight of the model but the weight can not be reloaded directly as model.
Looking forward to your concern and feedback.Thanks.

some question about the spark-fm

Q1. compare with the https://github.com/Intel-bigdata/imllib-spark,the auc performance of this spark-fm is very bad in my ctr prediction task, i have try mini-batch SGD、L-BFGS、parallel SGD and parallel FTRL, all auc < 0.7,but the same dataset and parameters on imllib-spark is 0.88,is there some fault in the implementation?
Q2. in my opinion, optimizer FTRL is not a good method in FM optimize task,because ftrl will lead to the matrix V is sparse,which will recduce the effect of cross features.

Fatal Bug need to fix

  1. Bug1
    in FactorizationMachinesUpdater, need to use the below code, otherwise, SGD will exist with only 1 iteration.
    val weightsNew = weightsOld.copy.toArray

  2. Bug2
    in FactorizationMachinesGradient, change the code below, for the loss calculation.
    // case Algo.BinaryClassification => -Math.log(1 + 1 / (1 + Math.exp(-p * label)))
    case Algo.BinaryClassification => Math.log(1 + Math.exp(-p * label))
    @hibayesian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.