Description

Sample with given ratio with or without replacement.

Parameters

Name Description Type Required? Default Value
ratio sampling ratio, it should be in range of [0, 1] Double
withReplacement Indicates whether to enable sampling with replacement, default is without replcement Boolean false

Script Example

Script

  1. data = np.array([
  2. ["-0.6264538 0.1836433"],
  3. ["-0.8356286 1.5952808"],
  4. ["0.3295078 -0.8204684"],
  5. ["0.4874291 0.7383247"],
  6. ["0.5757814 -0.3053884"],
  7. ["1.5117812 0.3898432"],
  8. ["-0.6212406 -2.2146999"],
  9. ["11.1249309 9.9550664"],
  10. ["9.9838097 10.9438362"],
  11. ["10.8212212 10.5939013"],
  12. ["10.9189774 10.7821363"],
  13. ["10.0745650 8.0106483"],
  14. ["10.6198257 9.9438713"],
  15. ["9.8442045 8.5292476"],
  16. ["9.5218499 10.4179416"],
  17. ])
  18. df_data = pd.DataFrame({
  19. "features": data[:, 0],
  20. })
  21. data = dataframeToOperator(df_data, schemaStr='features string', op_type='stream')
  22. sampleOp = SampleStreamOp().setRatio(0.3)
  23. data.link(sampleOp).print()
  24. StreamOperator.execute()

Result

features
10.9189774 10.7821363
10.0745650 8.0106483”