I am trying to save the output from sklearn.smv.SVC training when verbose=True to a log-file. However, since it uses LibSVM in the back-end, I cannot figure out how this works. Copilot hasn't helped.
Here's a brief example. It isn't the exact problem I am trying to solve or the workflow, but gives the idea:
import numpy as np
import sklearn
import os
if __name__ == '__main__':
breast_data = sklearn.datasets.load_breast_cancer()
X = breast_data.data
y = breast_data.target
np_rand_state = np.random.RandomState(0)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, test_size=0.33, random_state=np_rand_state)
model = sklearn.svm.SVC(verbose=True)
model.fit(X_train, y_train)
The console output is here from the model.fit():
*
optimization finished, #iter = 79
obj = -100.327399, rho = -0.702443
nSV = 114, nBSV = 109
Total nSV = 114
I want to save the console output to a log-file, using the integrated python logging functionality
(logging). The output the console is not done by a simple print statement, but through the SVM backend from sklearn.svm.SVC. This means it is not as simple as redirecting the print to a log file.