How to obtain the training error in svm of Scikit-learn?

2024/10/18 15:09:36

My question: How do I obtain the training error in the svm module (SVC class)?

I am trying to do a plot of error of the train set and test set against the number of training data used ( or other features such as C / gamma ). However, according to the SVM documentation , there is no such exposed attribute or method to return such data. I did find that RandomForestClassifier does expose a oob_score_ though.

Answer

Just compute the score on the training data:

>>> model.fit(X_train, y_train).score(X_train, y_train)

You can also use any other performance metrics from the sklearn.metrics module. The doc is here:

http://scikit-learn.org/stable/modules/model_evaluation.html

Also: oob_score_ is an estimate of the test / validation score, not the training score.

https://en.xdnf.cn/q/73127.html

Related Q&A

Flask-Migrate not detecting tables

I have the following project structure:project/__init__.pyfrom flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migratedb = SQLAlchemy() migrate = Migrate()def creat…

Cannot train a neural network solving XOR mapping

I am trying to implement a simple classifier for the XOR problem in Keras. Here is the code:from keras.models import Sequential from keras.layers.core import Dense, Dropout, Activation from keras.optim…

Pyarrow read/write from s3

Is it possible to read and write parquet files from one folder to another folder in s3 without converting into pandas using pyarrow.Here is my code:import pyarrow.parquet as pq import pyarrow as pa imp…

matplotlib draw showing nothing

Im using pythons matplotlib to do some contours using contour and contourf functions. They all work fine when using show, but when I try to use draw() inside a method, I get the matplotlib window but n…

Measure the height of a string in Tkinter Python?

I need the height in pixel of a string in a Tkiner widget. It is the text in a row of a Listbox.I know I can measure the width of a string with tkinter.font.Font.measure. But how can I get the height?…

pandas filter by multiple columns NULL

I have a pandas dataframe like:df = pd.DataFrame({Last_Name: [Smith, None, Brown], First_Name: [John, None, Bill],Age: [35, 45, None]})And could manually filter it using:df[df.Last_Name.isnull() & …

Closed IPython Notebook that was running code

How it works? I got some code running in an IPython Notebook. Some iterative work. Accidentally I closed the browser with the running Notebook, but going back to the IPython Dashboard I see that this …

os.popen().read() - charmap decoding error

I have already read UnicodeDecodeError: charmap codec cant decode byte X in position Y: character maps to <undefined>. While the error message is similar, the code is completely different, becau…

multiprocessing numpy not defined error

I am using the following test code:from pathos.multiprocessing import ProcessingPool as Pool import numpydef foo(obj1, obj2):a = obj1**2b = numpy.asarray(range(1,5))return obj1, bif __name__ == __main_…

Convert mp4 sound to text in python

I want to convert a sound recording from Facebook Messenger to text. Here is an example of an .mp4 file send using Facebooks API: https://cdn.fbsbx.com/v/t59.3654-21/15720510_10211855778255994_5430581…