आसान 0 हल किए गए 0% स्वीकृति

Min-Max Normalization

Rescale a feature so its smallest value becomes 0 and its largest becomes 1.

आप क्या सीखेंगे

  • Rescale values to the 0-1 range
  • Handle a feature where all values are equal
  • Prepare data for training

समस्या

अनुवाद दिखाएँ

Features measured on different scales (age in years, income in dollars) confuse many models. Min-max normalization rescales a feature to the range 0 to 1:

x' = (x - min) / (max - min)

If all values are equal (max = min), return 0 for every value.

Implement min_max_normalize(values).

Input

values: The values of one feature.

Output

Return the normalized values in the same order.

सीमाएँ

1 ≤ length ≤ 10,000

-1,000,000 ≤ each value ≤ 1,000,000

उदाहरण

उदाहरण 1
इनपुट:
values = [10.0, 20.0, 15.0, 30.0]

अपेक्षित आउटपुट:
expected = [0.0, 0.5, 0.25, 1.0]
इनपुट:
std::vector<double> values = {10.0, 20.0, 15.0, 30.0};

अपेक्षित आउटपुट:
std::vector<double> expected = {0.0, 0.5, 0.25, 1.0};
इनपुट:
double[] values = new double[] {10.0, 20.0, 15.0, 30.0};

अपेक्षित आउटपुट:
double[] expected = new double[] {0.0, 0.5, 0.25, 1.0};

व्याख्या

min = 10 and max = 30, so the range is 20: (10 - 10) / 20 = 0, (20 - 10) / 20 = 0.5, (15 - 10) / 20 = 0.25 and (30 - 10) / 20 = 1.

उदाहरण 2
इनपुट:
values = [5.0, 5.0, 5.0]

अपेक्षित आउटपुट:
expected = [0.0, 0.0, 0.0]
इनपुट:
std::vector<double> values = {5.0, 5.0, 5.0};

अपेक्षित आउटपुट:
std::vector<double> expected = {0.0, 0.0, 0.0};
इनपुट:
double[] values = new double[] {5.0, 5.0, 5.0};

अपेक्षित आउटपुट:
double[] expected = new double[] {0.0, 0.0, 0.0};

व्याख्या

All values are equal, so the range is 0 and every value becomes 0.

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।