import numpy as np from xgboost import XGBClassifier # train model train_data = np.random.rand(100, 10) train_label = np.random.randint(2, size=100) model = XGBClassifier() model.fit(train_data, train_label) # predict probability x = np.random.rand(1, 10) y_prob = model.predict_proba(x) print(y_prob)
import numpy as np from xgboost import XGBClassifier # train model train_data = np.random.rand(100, 10) train_label = np.random.randint(3, size=100) model = XGBClassifier(num_class=3) model.fit(train_data, train_label) # predict probability for each class x = np.random.rand(1, 10) y_prob = model.predict_proba(x) print(y_prob)In both the examples, the `predict_proba` method is used to get the predicted probabilities for the input samples. The method takes input as the data 'x' and returns the predicted probabilities as an array of shape (n_samples, n_classes).