我正在使用Colab中的Pycaret库对这个数据集做一个简单的预测:
https://www.kaggle.com/andrewmvd/fetal-health-classification
当我运行我的代码:
from pycaret.utils import enable_colab
enable_colab()
from google.colab import drive
drive.mount('/content/drive')
import pandas as pd
from pycaret.classification import *
from pandas_profiling import ProfileReport
df= pd.read_csv("/content/drive/MyDrive/Pycaret/fetal_health.csv")
df2 = df.iloc[:,:11]
df2['fetal_health'] = df['fetal_health']
test = df2.sample(frac=0.10, random_state=42, weights='fetal_health')
train = df2.drop(test.index)
test.reset_index(inplace=True, drop=True)
train.reset_index(inplace=True, drop=True)
clf = setup(data =train, target = 'fetal_health', session_id=42,
log_experiment=True, experiment_name='fetal', normalize=True)
best = compare_models(sort="Accuracy")
rf = create_model('rf', fold=30)
tuned_rf = tune_model(rf, optimize='Accuracy')
predict_model(tuned_rf)我得到了这个错误

我认为这是因为我的目标变量不平衡(参见img),并导致预测不正确。

有人能帮我理解吗?Tks预先
发布于 2022-02-01 22:24:41
我发现了问题所在:我的目标变量以值1开头,有3个不同的值。当Pycaret试图进行列表理解时(因为它以零索引开始),这将产生一个错误。为了解决这个问题,我把我的变量从零开始,工作得很好。
发布于 2022-11-11 19:40:01
莱安德罗
非常感谢您的解决方案!我对同一个数据集也有同样的问题!
答: Beal,我尝试了您的解决方案,但是仍然出现了相同的错误消息,所以我尝试了Leandro的解决方案,问题是,实际上,目标以1开头,而不是0。谢谢你对如何减少代码的建议!
https://stackoverflow.com/questions/70900716
复制相似问题