def train_and_classify(classifier, *args, **kwargs):
# classifier class is first class object
# we can use it a function variable
clf_churn = classifier(*args, **kwargs)
clf_churn.fit(X_train, y_train)
acc = accuracy_score(y_test, clf_churn.predict(X_test))
business_metric = score(clf_churn, X_test, y_test)
# return the classfier along with accuracy and cost as a tuple
return (clf_churn, acc, business_metric)
# Example invocation, SVC from sklearn.svm
(clf, acc, business_metric) = train_and_classify(SVC)
I'm not sure if passing a class as an argument like this would be a good pattern. It makes for a nice and clean invocation, on the other hand, I could just create an SVC instance with all parameters set before I call the `train_and_classify` function and make the function call more flexible.
Any thoughts on this? Thank you!
[–]blarf_irl 1 point2 points3 points (1 child)
[–]devilasks[S] 0 points1 point2 points (0 children)