def to_vw_format(row): res = f"{int(row.y)} |" for idx, value in row.drop(["y"]).iteritems(): feature_name = idx.replace(" ", "_").replace("(", "").replace(")", "") res += f" {feature_name}:{value}" return res
diplay few rows
for ex in training_data.head(10).apply(to_vw_format, axis=1): print(ex)
Create vowpall workspace
Run training with multiple samples
vw = vowpalwabbit.Workspace("--oaa 3 --quiet")# learn from training set with multiple passes for example in training_data.apply(to_vw_format, axis=1): vw.learn(example)# predict from the testing set predictions = [] for example in testing_data.apply(to_vw_format, axis=1): predicted_class = vw.predict(example) predictions.append(predicted_class)
Data Scientists must think like an artist when finding a solution when creating a piece of code. ⚪️ Artists enjoy working on interesting problems, even if there is no obvious answer ⚪️ linktr.ee/mlearning 🔵 Follow to join our 28K+ Unique DAILY Readers 🟠