关于autokera这个自动机器学习算法,进行二分类预测时,除了预测标签,还可以预测每个标签的概率吗?就如同别的机器学习的
predict_proba。下面是我的代码
import pandas as pd
import tensorflow as tf
import autokeras as ak
TRAIN_CSV_DIR="train.csv"
TEST_CSV_DIR="test.csv"
# Initialize the structured data classifier.
clf = ak.StructuredDataClassifier(
overwrite=True, max_trials=3
) # It tries 3 different models.
# Feed the structured data classifier with training data.
clf.fit(
# The path to the train.csv file.
TRAIN_CSV_DIR,
# The name of the label column.
"isDefault",
epochs=10,
)
# Predict with the best model.
predicted_y = clf.predict(TEST_CSV_DIR)
# Evaluate the best model with testing data.
print(clf.evaluate(TEST_CSV_DIR, "isDefault"))
“Devil组”引证GPT后的撰写:
可以在predict()函数中添加参数output_probabilities=True来得到每个标签的概率。修改你的代码如下:
import pandas as pd
import tensorflow as tf
import autokeras as ak
TRAIN_CSV_DIR="train.csv"
TEST_CSV_DIR="test.csv"
Initialize the structured data classifier.
clf = ak.StructuredDataClassifier(
overwrite=True, max_trials=3
) # It tries 3 different models.
Feed the structured data classifier with training data.
clf.fit(
# The path to the train.csv file.
TRAIN_CSV_DIR,
# The name of the label column.
"isDefault",
epochs=10,
)
Predict with the best model and output probabilities.
predicted_y, predicted_prob = clf.predict(TEST_CSV_DIR, output_probabilities=True)
Evaluate the best model with testing data.
print(clf.evaluate(TEST_CSV_DIR, "isDefault"))