Error on probability calibration in logistic regression : ValueError: could not convert string to float: 'OLIFE'

Error on probability calibration in logistic regression : ValueError: could not convert string to float: 'OLIFE'

我已经建立了逻辑回归模型并使用 scikit 管道进行了预处理。我经过训练和测试,一切都很好,但是当我尝试根据有效数据校准我的模型时,我在 calib_clf.fit(Valid, labelValid)

中遇到错误
ValueError: could not convert string to float: 'OLIFE'

这是我的代码:

column_trans = make_column_transformer(
                                        (OneHotEncoder(), ['PRODUCT_LINE_ID','SMOKING_STATUS','gender','Cover_Type']),
                                        remainder = StandardScaler()
                                       )

column_trans.fit_transform(train)

# Create a pipeline that scales the data then trains a support vector classifier
logreg = LogisticRegression()
model_pipeline = make_pipeline(column_trans, logreg)

# Fitting the model pipeline
model_pipeline.fit(train,labelTrain)

# Testing the model pipeline on new data/test data
predictions = model_pipeline.predict_proba(test)[:,1]


calib_clf = CalibratedClassifierCV(model_pipeline, method="sigmoid", cv="prefit")
calib_clf.fit(Valid, labelValid)

https://github.com/dnishimoto/python-deep-learning/blob/master/Happiness%20and%20Depression%20Logistic%20Regression.ipynb

我使用快乐与沮丧作为数据集。对于交叉折叠的数量,我使用了 3 而不是 prefit。

  calibrated_clf = CalibratedClassifierCV(base_estimator=pipeline['clf'], method="sigmoid", cv=3)
  calibrated_clf.fit(X, y)

  print(calibrated_clf.predict_proba(X)[:5, :])

输出:(发生和不发生的概率。

   [[0.97151521 0.02848479]
   [0.9953179  0.0046821 ]
   [0.01829911 0.98170089]
   [0.99405208 0.00594792]
   [0.82948843 0.17051157]]

概率输出表明数据行为并非在所有情况下都一致。它可能是我合并创建二项式的中度抑郁类别。需要对中度抑郁症进行分层,需要发现新的目标变量。