【问题标题】:Error on probability calibration in logistic regression : ValueError: could not convert string to float: 'OLIFE'逻辑回归中的概率校准错误:ValueError:无法将字符串转换为浮点数:'OLIFE'
【发布时间】:2021-06-04 01:17:26
【问题描述】:

我已经建立了逻辑回归模型并使用 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)

【问题讨论】:

  • 变量Valid和label(Valid)在你执行calib_clf.fit(Valid, labelValid)之前是什么样子的?
  • 问题在于您的设置和Valid、labelValid 中的数据。您是否正在使用交叉验证寻找最佳参数。尝试使用 GridSearchCV 找到最佳参数
  • 您能否发布指向您的 csv 数据的链接。 scikit-learn.org/stable/modules/generated/… 参见文档以了解 prefit。你为什么选择这个选项

标签: python python-3.x machine-learning scikit-learn logistic-regression


【解决方案1】:

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]]

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

【讨论】:

    猜你喜欢
    • 2020-10-16
    • 1970-01-01
    • 2018-11-19
    • 2021-11-16
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    相关资源
    最近更新 更多