Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introducing Reactive Machine Learning

1,709 views

Published on

Presented at the Reactive New York Meetup on 3/8/16.

Published in: Technology
  • Python Machine Learning --- http://amzn.to/1Zg8QHd
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Fundamentals of Machine Learning for Predictive Data Analytics: Algorithms, Worked Examples, and Case Studies (MIT Press) --- http://amzn.to/1nZc3NI
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Machine Learning: The Art and Science of Algorithms that Make Sense of Data --- http://amzn.to/1R7qOtL
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Introducing Reactive Machine Learning

  1. 1. Introducing Reactive Machine Learning Jeff Smith @jeffksmithjr
  2. 2. x.ai is a personal assistant who schedules meetings for you
  3. 3. You
  4. 4. nom nom, the data dog Scala & Python Spark & Akka Couchbase Machine Learning
  5. 5. Reactive + Machine Learning
  6. 6. Machine Learning Systems
  7. 7. Traits of Reactive Systems
  8. 8. Responsive
  9. 9. Resilient
  10. 10. Elastic
  11. 11. Message-Driven
  12. 12. Reactive Strategies
  13. 13. Reactive Machine Learning
  14. 14. Reactive Machine Learning
  15. 15. Collecting Data
  16. 16. Machine Learning Systems
  17. 17. Uncertainty Interval 27 33
  18. 18. Immutable Facts case class PreyReading(sensorId: Int, locationId: Int, timestamp: Long, animalsLowerBound: Double, animalsUpperBound: Double, percentZebras: Double) implicit val preyReadingFormatter = Json.format[PreyReading]
  19. 19. Distributed Data Storage
  20. 20. Partition Tolerance
  21. 21. Distributed Data Storage
  22. 22. Immutable Facts val reading = PreyReading(36, 12, currentTimeMillis(), 12.0, 18.0, 0.60) val setDoc = bucket.set[PreyReading](readingId(reading), reading)
  23. 23. Scaling with Distributed Databases
  24. 24. Almost Immutable Data Model { "sensor_id": 123, "readings": [ { "sensor_id": 456, "timestamp": 1457403598289, "lower_bound": 12.0, "upper_bound": 18.0, "percent_zebras": 0.60 } ] }
  25. 25. Hot Key
  26. 26. Truly Immutable Data Model { "sensor_id_reading_id": 123456, "timestamp": 1457403598289, "lower_bound": 12.0, "upper_bound": 18.0, "percent_zebras": 0.60 }
  27. 27. Generating Features
  28. 28. Machine Learning Systems
  29. 29. Feature Generation Raw Data FeaturesFeature Generation Pipeline
  30. 30. Microblogging Data
  31. 31. Pipeline Failure Raw Data FeaturesFeature Generation Pipeline Raw Data FeaturesFeature Generation Pipeline
  32. 32. Supervising Feature Generation Raw Data FeaturesFeature Generation Pipeline Supervision
  33. 33. Original Features object SquawkLength extends FeatureType[Int] object Super extends LabelType[Boolean] val originalFeatures: Set[FeatureType] = Set(SquawkLength) val label = Super
  34. 34. Basic Features object PastSquawks extends FeatureType[Int] val basicFeatures = originalFeatures + PastSquawks
  35. 35. More Features object MobileSquawker extends FeatureType[Boolean] val moreFeatures = basicFeatures + MobileSquawker
  36. 36. Feature Collections case class FeatureCollection(id: Int, createdAt: DateTime, features: Set[_ <: FeatureType[_]], label: LabelType[_])
  37. 37. Feature Collections val earlierCollection = FeatureCollection(101, earlier, basicFeatures, label) val latestCollection = FeatureCollection(202, now, moreFeatures, label) val featureCollections = sc.parallelize( Seq(earlierCollection, latestCollection))
  38. 38. Fallback Collections val FallbackCollection = FeatureCollection(404, beginningOfTime, originalFeatures, label)
  39. 39. Fallback Collections def validCollection(collections: RDD[FeatureCollection], invalidFeatures: Set[FeatureType[_]]) = { val validCollections = collections.filter( fc => !fc.features .exists(invalidFeatures.contains)) .sortBy(collection => collection.id) if (validCollections.count() > 0) { validCollections.first() } else FallbackCollection }
  40. 40. Learning Models
  41. 41. Machine Learning Systems
  42. 42. Learning Models Features ModelModel Learning Pipeline
  43. 43. Models of Love
  44. 44. Traits of Spark
  45. 45. Reactive Strategies in Spark
  46. 46. Data Preparation val labelIndexer = new StringIndexer() .setInputCol("label") .setOutputCol("indexedLabel") .fit(instances) val featureIndexer = new VectorIndexer() .setInputCol("features") .setOutputCol("indexedFeatures") .fit(instances) val Array(trainingData, testingData) = instances.randomSplit( Array(0.8, 0.2))
  47. 47. Learning a Model val decisionTree = new DecisionTreeClassifier() .setLabelCol("indexedLabel") .setFeaturesCol("indexedFeatures") val labelConverter = new IndexToString() .setInputCol("prediction") .setOutputCol("predictedLabel") .setLabels(labelIndexer.labels) val pipeline = new Pipeline() .setStages(Array(labelIndexer, featureIndexer, decisionTree, labelConverter))
  48. 48. Evolving Modeling Strategies val randomForest = new RandomForestClassifier() .setLabelCol("indexedLabel") .setFeaturesCol("indexedFeatures") val revisedPipeline = new Pipeline() .setStages(Array(labelIndexer, featureIndexer, randomForest, labelConverter))
  49. 49. Deep Models of Artistic Style
  50. 50. Refactoring Command Line Tools > python neural-art-tf.py -m vgg -mp ./vgg -c ./images/ bear.jpg -s ./images/style.jpg -w 800 def produce_art(content_image_path, style_image_path, model_path, model_type, width, alpha, beta, num_iters):
  51. 51. Exposing a Service class NeuralServer(object): def generate(self, content_image_path, style_image_path, model_path, model_type, width, alpha, beta, num_iters): produce_art(content_image_path, style_image_path, model_path, model_type, width, alpha, beta, num_iters) return True daemon = Pyro4.Daemon() ns = Pyro4.locateNS() uri = daemon.register(NeuralServer) ns.register("neuralserver", uri) daemon.requestLoop()
  52. 52. Encoding Model Types object ModelType extends Enumeration { type ModelType = Value val VGG = Value("VGG") val I2V = Value("I2V") }
  53. 53. Encoding Valid Configuration case class JobConfiguration(contentPath: String, stylePath: String, modelPath: String, modelType: ModelType, width: Integer = 800, alpha: java.lang.Double = 1.0, beta: java.lang.Double = 200.0, iterations: Integer = 5000)
  54. 54. Finding the Service val ns = NameServerProxy.locateNS(null) val remoteServer = new PyroProxy(ns.lookup("neuralserver"))
  55. 55. Calling the Service def callServer(remoteServer: PyroProxy, jobConfiguration: JobConfiguration) = { Future.firstCompletedOf( List( timedOut, Future { remoteServer.call("generate", jobConfiguration.contentPath, jobConfiguration.stylePath, jobConfiguration.modelPath, jobConfiguration.modelType.toString, jobConfiguration.width, jobConfiguration.alpha, jobConfiguration.beta, jobConfiguration.iterations).asInstanceOf[Boolean] }))}
  56. 56. Profiles with Style
  57. 57. Hybrid Model learning Features ModelModel Learning Pipeline
  58. 58. Publishing Models
  59. 59. Machine Learning Systems
  60. 60. Publishing Models Model Predictive Service Publishing Process
  61. 61. Building Lineages val rawData: RawData val featureSet: Set[FeatureType] val model: ClassificationModel val modelMetrics: BinaryClassificationMetrics
  62. 62. Predicting
  63. 63. Machine Learning Systems
  64. 64. Predicting Client Predictive Service Request> <Prediction
  65. 65. Models as Services def predict(model: Features => Prediction) (features: Features): Future[Either[String, Prediction]] = { ??? }
  66. 66. Models as Services val routes = { pathPrefix("model") { (post & entity(as[PredictionRequest])) { context => complete { predict(model: Features => Prediction) (extractFeatures(context)) .map[ToResponseMarshallable] { case Right(prediction) => PredictionSummary(prediction) case Left(errorMessage) => BadRequest -> errorMessage } } } } }
  67. 67. Clojure Functions
  68. 68. Clojure Predictive Service
  69. 69. Predicting Client Predictive Service Request
  70. 70. Summary
  71. 71. Machine Learning Systems
  72. 72. Traits of Reactive Systems
  73. 73. Reactive Strategies
  74. 74. Reactive Machine Learning
  75. 75. For Later
  76. 76. manning.com reactivemachinelearning.com medium.com/data-engineering M A N N I N G Jeff SmithUse the code reactnymu for 39% off!
  77. 77. x.ai @xdotai hello@human.x.ai New York, New York We’re hiring!
  78. 78. Thank You!
  79. 79. Code: reactnymu Jeff Smith @jeffksmithjr reactivemachinelearning.com M A N N I N G Jeff Smith

×