Replies: 2 comments
|
The issue is most likely with this part of the remainder=StandardScaler()This applies I would explicitly separate the categorical and numerical columns instead: from sklearn.compose import make_column_transformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.calibration import CalibratedClassifierCV
categorical_cols = [
'PRODUCT_LINE_ID',
'SMOKING_STATUS',
'gender',
'Cover_Type'
]
numeric_cols = [
# Add all your numerical column names here
]
column_trans = make_column_transformer(
(OneHotEncoder(handle_unknown='ignore'), categorical_cols),
(StandardScaler(), numeric_cols)
)
model_pipeline = make_pipeline(
column_trans,
LogisticRegression()
)
model_pipeline.fit(train, labelTrain)
predictions = model_pipeline.predict_proba(test)[:, 1]
calib_clf = CalibratedClassifierCV(
model_pipeline,
method='sigmoid',
cv='prefit'
)
calib_clf.fit(Valid, labelValid)Also, you can find the column containing for col in train.select_dtypes(include='object').columns:
if 'OLIFE' in train[col].values:
print("Found in:", col)If you are using a recent version of scikit-learn, from sklearn.frozen import FrozenEstimator
calib_clf = CalibratedClassifierCV(
FrozenEstimator(model_pipeline),
method='sigmoid'
)
calib_clf.fit(Valid, labelValid)The important part is to make sure every categorical column is passed through |
Uh oh!
There was an error while loading. Please reload this page.
Hi, im trying to calibrate logistic regression classifier and i get the error ValueError: could not convert string to float: 'OLIFE',
I did onehotencode my categorical values using pipeline, it works fine when i test my model but when i calibrate it doesnt work even if im passing the pipeline model in to CalibratedClassifierCV, kindly assist please as im new to machine learning
All reactions