
Solve the following programming tasks.
You are cleaning sensor data for temperature-fluctuation anomaly modeling.
You are given:
rawData
of length
n
.
localArea >= 0
.
Index i is a local maximum if:
i
, the sequence
rawData[i], rawData[i-1], rawData[i-2], ...
is
strictly decreasing
for
L = min(localArea, i)
steps, i.e.
rawData[i] > rawData[i-1] > rawData[i-2] > ... > rawData[i-L]
.
i
, the sequence
rawData[i], rawData[i+1], rawData[i+2], ...
is
strictly decreasing
for
R = min(localArea, n-1-i)
steps, i.e.
rawData[i] > rawData[i+1] > rawData[i+2] > ... > rawData[i+R]
.
If there are fewer than localArea elements to the left or right, use all available elements on that side.
Task: Return all indices i (0-based) that are local maxima, in increasing order.
Constraints (typical for OA): Aim for better than when n is large.
Implement missing functions in a provided code skeleton (you may not change existing code besides filling in the ellipses).
You are given:
x_train
: 2D array of floats with shape
(n_train, d)
.
y_train
: 1D array of integer class labels with shape
(n_train,)
.
x_test
: 2D array of floats with shape
(n_test, d)
.
base_classifiers
: an array/list of length
n_estimators
, where each classifier supports:
fit(X, y)
predict(X)
returning integer labels.
Task: Build a Bagging classifier that:
n_train
rows
with replacement
) for each base classifier.
x_test
by
majority vote
across estimators.
Output: Return a 1D array of predicted integer labels of length n_test.
(If there is a voting tie, use the smallest class label as the tie-breaker unless the skeleton specifies otherwise.)
Implement missing functions in a provided k-means skeleton.
You are given:
data
: 2D array of floats with shape
(n, d)
.
k
: number of clusters.
centroids
: initial centroids, 2D array of floats with shape
(k, d)
.
iterations
: number of update steps to perform.
k-means loop:
iterations
iterations.
Output: Return a 1D integer array of length n with the predicted cluster index for each point.
(If a cluster gets zero points in an iteration, keep its centroid unchanged unless the skeleton specifies another rule.)