python - 逻辑回归中的概率校准错误:ValueError:无法将字符串转换为浮点数:'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)
解决方案
我使用幸福与抑郁作为数据集。对于交叉折叠的数量,我使用 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]]
概率输出表明数据行为在所有情况下都不一致。它可能是我结合创建二项式的中度抑郁类别。需要对中度抑郁症进行分层,并需要发现一个新的目标变量。
</p>
推荐阅读
- sql - 如何创建“用户组”并设置权限
- python - Python elasticsearch-dsl 动态构建匹配查询
- python - Tokenize words and getting elements right before and after this word
- vue.js - 如何在 Nuxt 中设置 netlify 表单
- php - Deliver Email Based on Field Selection on a Product
- python - Performance difference between positional and keyword arguments in Python?
- python - 追加到对象内的列表也会追加到其他对象中的列表
- javascript - 从 url 中删除锚点 (fullPage.js)
- python - Python - 如何对多列执行相同的操作 - 用前一行计算行
- r - 如何在geom_col中反转对数刻度条?