All changes saved to local database
ML - discrete structures
Instructions

In many Machine Learning algorithms, such as K-Nearest Neighbors or Neural Networks, feature scales can significantly influence the model's performance. Min-Max Scaling is a preprocessing technique used to transform raw data into a fixed range, typically between 00 and 11 . This ensures that no single feature dominates others simply because of its numerical magnitude.

Methodology

To scale a feature vector xx to  a range of [0,1][0, 1], we apply the following mathematical transformation to every element:

Step 1: Identify Extremes Locate the minimum value (minmin) and the maximum value (maxmax) within the dataset.

Step 2: Apply the Scaling Formula Subtract the minimum value from the original value and divide by the range (maxminmax - min)

xscaled=xxminxmaxxminx_{scaled} = \frac{x - x_{min}}{x_{max} - x_{min}}

Implementation

Using NumPy, you can perform this calculation across an entire array without manual iteration. By using np.min() and np.max(), you can find the global extremes of an array and apply the formula using vectorized subtraction and division.

System Note: Your coding environment is already pre-configured to run NumPy. You can access it directly by using the import numpy as np statement.

Validation

To ensure your solution passes our automated verification system (==), you must perform the following formatting steps before returning your result:

  1. Rounding: Round the scaled values to 2 decimal places using np.round(result, 2).
  2. Type Conversion: Convert the resulting NumPy array into a standard Python list using the .tolist() method.

The Challenge

Implement the function min_max_scale(data). It must accept a 1D NumPy array and return a list of values scaled between 0 and 1, rounded to 2 decimal places.

import numpy as np def min_max_scale(data): # Step 1: Find min and max of the array # Step 2: Apply scaling formula # Final Step: Round to 2 decimal places and return .tolist() pass

solution.py
Terminal