2025 USA-NA-AIO Round 1, Problem 3, Part 9

Problem 9 (5 points, coding task)

Use StandardScaler that has been imported from sklearn.preprocessing (DO NOT IMPORT IT AGAIN) to do the following tasks.

  1. Create an object called scaler.

  2. Use scaler.fit_transform to scale each column in X_train to standard normal. Save the scaled training dataset as X_train_scaled.

  3. Use scaler.transform to scale X_test. Save the scaled test dataset as X_test_scaled.

  4. Add a column to X_train_scaled with all 1s. Do the same thing for X_test_scaled.

  5. Print the types of objects X_train_scaled and X_test_scaled.

  6. Print the shapes of objects X_train_scaled and X_test_scaled.

  7. Print the first five rows of X_train_scaled and X_test_scaled.

### WRITE YOUR SOLUTION HERE ###
scaler = StandardScaler()

X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

X_train_scaled = np.concat([X_train_scaled, np.ones((X_train_scaled.shape[0], 1))], axis=1)
X_test_scaled = np.concat([X_test_scaled, np.ones((X_test_scaled.shape[0], 1))], axis=1)

print(type(X_train_scaled))
print(type(X_test_scaled))

print(X_train_scaled.shape)
print(X_test_scaled.shape)

print(X_train_scaled[:5])
print(X_test_scaled[:5])
""" END OF THIS PART """