简体   繁体   中英

Average of a numpy array after applying a function one column at a time

Given:

  • m models, each with a predict function that takes a numpy array of shape [n_samples, n_features] and returns an array of shape [n_samples], which contains 1 if the model said yes and 0 otherwise.
  • X data points of shape [n_samples, n_features]

Expected output: for each data point how many models emitted yes.

out = np.zeros((n, m))
for i, m in enumerate(m_models):
    out[:, i] = m.predict(X)    # Doesn't seem to work
scores = np.mean(out, axis=1)

You trying assign array of shape n to the column with shape m . Change your out declaration on:

out = np.zeros((m, n))

Or assign predictions to the row:

for i, m in enumerate(m_models):
    out[i, :] = m.predict(X)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM