I would like advice on how to improve my f1_score for classification. I currently have something around 0.57. Dataset:

lotWaferDie - lot, board and chip on which defects were measured

  • string values like W02-D12_11,..

XRel - relative position of the defect in the axis X

YRel - relative position of the defect in the Y axis

XSize - the size of the defect in the X axis

YSize - the size of the defect in the Y axis

DefArea - defect area

DefSize - the size of the defect

dieRow - the row of the defect on the board

dieCol - defect column on the board

xidx - index of the defect line on the board

yidx - index of the defect column on the board

fail - 1/0 what i predict

Here are some steps I've tried I tried to cut the lotWaferDie into 3 parts. As for the xidx and yidx column bars, I'm not sure of their importance, but removing them doesn't make a difference

df[['L', 'W', 'D']] = df['lotWaferDie'].str.split('-|_', expand=True)
df = df.drop(columns=['lotWaferDie'])

# use one-hot encoding
for col in df.select_dtypes(object).columns:
    df = pd.concat([
        df.drop(col, axis=1), pd.get_dummies(df[col], prefix=('d_' + col))
    ], axis=1)

Xtrain, Xrest, ytrain, yrest = train_test_split(
    df.drop(columns=['fail']), df.fail, test_size=0.4, random_state=random_seed, stratify=df.fail

Xtest, Xval, ytest, yval = train_test_split(
    Xrest, yrest, test_size=0.5, random_state=random_seed, stratify=yrest

param_grid = {
    'max_depth': range(1, 40), 
    'criterion': ['entropy']
param_comb = ParameterGrid(param_grid)
from sklearn.metrics import f1_score
val_acc = []
param_f1_pairs = []  

for i,params in enumerate(param_comb):
    dt = DecisionTreeClassifier(max_depth=params['max_depth'], criterion=params['criterion'])
    dt.fit(Xtrain, ytrain)
    val_acc.append(metrics.accuracy_score(yval, dt.predict(Xval)))
    val_score = accuracy_score(yval, dt.predict(Xval))
    print(f"Iteration {i+1}/{len(param_comb)} - Validation Score: {val_score:.4f} - Parameters: {params}")
    predicted_classes = dt.predict(Xtest)
    f1 = f1_score(ytest, predicted_classes)
    param_f1_pairs.append((params, f1))  
    print("F1 skóre:", f1)

all program: https://onecompiler.com/python/42antqzp8 dataset: https://easyupload.io/3y2kou



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.