Answer to Question #154975 in Statistics and Probability for b manoj

Question #154975


We wish to train a machine learning algorithm on an array of floating-point numbers in the

interval [0.0, 1.0). The data is horribly unbalanced (not evenly distributed) and we wish to

filter the dataset to obtain a subset containing an equal number of values from each

interval

[0, 0.2), [0.2, 0.4), ... [0.8, 1.0), throwing away as little data as possible.

Write a program which reads comma-separated floating-point numbers in a single line from

standard input and prints the filtered data to standard output in the same format

Note: Solve this in linear time, if possible. Priority will be given to those who solve in linear

time.

Explanation Example

Input: 0.11,0.12,0.13,0.23,0.34,0.35,0.47,0.59,0.77,0.83,0.85,0.91,0.95

On classifying the above input data from example 4, Subset in each interval will look as below:


Since the interval [0.6 - 0.8) has the minimum subset of size 1. We choose 1 element from

the rest of the intervals.

Output: 0.11,0.23,0.47,0.77,0.83

*if the interval [0.6 - 0.8) had more than 3 elements then we would choose 2 elements from all

subset, since the interval with minimum subset, would be [0.4 - 0.6) and of size 2.

Interval Data

[0 - 0.2) 0.11,0.12,0.13

[0.2 - 0.4) 0.23,0.34,0.35

[0.4 - 0.6) 0.47,0.59

[0.6 - 0.8) 0.77

[0.8 - 1.0) 0.83,0.85,0.91,0.95


Sample Examples:

Example 1

Input: 0.1,0.3,0.5,0.7,0.9

Output: 0.1,0.3,0.5,0.7,0.9

Example 2

Input: 0.1,0.3,0.5,0.7,0.9,0.5

Output: 0.1,0.3,0.5,0.7,0.9


Example 3

Input: 0.15,0.12,0.35,0.38,0.55,0.56,0.57,0.75,0.77,0.9,0.94

Output: 0.15,0.12,0.35,0.38,0.55,0.56,0.75,0.77,0.9,0.94


1
Expert's answer
2021-01-11T12:49:01-0500
Dear b manoj, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS