anchor.diff:  
   You need to implment readTraining() of [PDataSource](https://docs.prediction.io/api/current/#io.prediction.controller.PDataSource), where you can use the [PEventStore Engine API](https://docs.prediction.io/api/current/#io.prediction.data.store.PEventStore$) to read the events and create the TrainingData based on the events.
   
  -The following code is example of reading user "view" and "buy" item events, and then filtered specific type of events for future processing and return TrainingData accordingly.
  -
  -```scala
  -
  +The following code example reads user "view" and "buy" item events, filters specific type of events for future processing and returns TrainingData accordingly.
  +
  +```scala
   class DataSource(val dsp: DataSourceParams)
     extends PDataSource[TrainingData,
         EmptyEvaluationInfo, Query, EmptyActualResult] {
  
positive.code: Example:
  
  - [Algorithm of Recommendation Template](/templates/recommendation/dase/#algorithm): it implements PAlgorithm and the IPersistentModel and IPersistentModelLoader.
  - [Algorithm of Vanilla Template](/templates/vanilla/dase): it walks through example of P2LAlgorithm and P2Algorithm.
  
  ## using LEventStore Engine API in predict()
  
  You may use [LEventStore.findByEntity()](https://docs.prediction.io/api/current/#io.prediction.data.store.LEventStore$) to retrieve events of the specific entity. For example, retrieve recent events of the user() which is specificed in query) and use this recent events to make prediction in real time.
  
  
  For example, the following code read the recent 10 view events of the `query.user`:
  
  ```scala
  
      val recentEvents = try {
        LEventStore.findByEntity(
          appName = ap.appName,
  
negative.code: Example:
  
  - [Preparator of Leading Scoring Template](/templates/leadscoring/dase/#data): it pre-processes the TrainingData and generate the feature vectors needed for the algorithm.
  - [Preparator of Similar Product Template](/templates/similarproduct/dase/#data): it simply passes the TrainingData as PreparedData for the algorithm.
  
  # Algorithm
  
  The two methods of the Algorithm class are train() and predict():
  
  ## train()
  
  train() is responsible for training a predictive model. It is called when you run `pio train`. PredictionIO will store this model.
  
  ## predict()
  
  predict() is responsible for using this model to make prediction. It is called when you send a JSON query to the engine. Note that predict() is called in real time.
  
  PredictionIO supports two types of algorithms:
  
  