How to set up SVM using Optuna

How to set up SVR (Support Vector Regression) using Optuna

Let's set the regression SVR of SVM. The main settings were gamma, C, ʻepsilon. I also put kernelas a comment so as not to forget the setting. It is possible to calculate withkernel included, but as soon as the polypolynomial is entered, the calculation becomes slow, so for the time being, I think it is better to calculate with onlyrbf` (radial basis function). ..

Parameter setting

def objective(trial):
    #kernel = trial.suggest_categorical('kernel', ['linear','rbf','poly','sigmoid','precomputed'])
    gamma = trial.suggest_loguniform('gamma',1e-5,1e5)
    C = trial.suggest_loguniform('C',1e-5,1e5)
    epsilon = trial.suggest_loguniform('epsilon',1e-5,1e5)

    #If you choose a kernel, use the above
    #regr = SVR(kernel = kernel, gamma = gamma, C = C ,epsilon = epsilon)
    regr = SVR(kernel = 'rbf', gamma = gamma, C = C ,epsilon = epsilon)
    score = cross_val_score(regr, X_train_std, y_train, cv=3, scoring="r2")

    r2_mean = score.mean()
    print(r2_mean)

    return r2_mean

Learning with Optuna

#optuna study
study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=100)
 
#Fits tuned hyperparameters

optimised_regr = SVR(kernel = 'rbf' , gamma = study.best_params['gamma'],
                   C = study.best_params['C'],epsilon = study.best_params['epsilon'])
'''
#If you select kernel, use this
optimised_regr = SVR(kernel = study.best_params['kernel'] , gamma = study.best_params['gamma'],
                   C = study.best_params['C'],epsilon = study.best_params['epsilon'])
'''
optimised_regr.fit(X_train_std ,y_train)

The result was like this and I was able to fit with a good feeling.

svm_Figure_1.png

Recommended Posts

How to set up SVM using Optuna
How to set up Random forest using Optuna
How to set xg boost using Optuna
How to set up a Python environment using pyenv
How to set optuna (how to write search space)
How to set up a local development server
How to set up public key authentication in ssh
How to set layer on Lambda using AWS SAM
How to set up and compile your Cython environment
How to set up Ubuntu for Windows Subsystem for Linux 2 (WSL2)
How to import Python library set up in EFS to Lambda
Survey log of how to optimize LightGBM hyperparameters using Optuna
How to install python using anaconda
How to speed up Python calculations
How to set up and use OMC Log Analytics --Linux version -
Set up a node to do MNIST on ROS using Tensorflow
How to set up the development environment of ev3dev [Windows version]
[Blender] How to set shape_key with script
How to speed up instantiation of BeautifulSoup
How to draw a graph using Matplotlib
How to set the server time to Japanese time
How to install a package using a repository
Set up a mail server using Twisted
How to download youtube videos using pytube3
How to set up a jupyter notebook on ssh destination (AWS EC2)
Summary of how to set up major Python Lint (pep8, pylint, flake8)
How to display Map using Google Map API (Android)
How to code a drone using image recognition
How to set browser location in Headless Chrome
How to speed up scikit-learn like conda Numpy
How to set Django DB to mongodb visual studio 2019
How to deal with SessionNotCreatedException when using Selenium
How to get article data using Qiita API
How to search HTML data using Beautiful Soup
How to upload to a shared drive using pydrive
How to uninstall a module installed using setup.py
How to set CPU affinity for process threads
How to set up a Google Colab environment with Coursera's advanced machine learning courses
How to set up a VPN gateway to establish a connection between Alibaba Cloud and AWS
I want to set up a mock server for python-flask in seconds using swagger-codegen.
[Rails] How to get location information using Geolocation API
How to read dynamically generated table definitions using SQLAlchemy
The easiest way to set up Last-Modified in Flask
How to write a GUI using the maya command
How to scrape horse racing data using pandas read_html
How to auto-submit Microsoft Forms using python (Mac version)
Set up a file server on Ubuntu 20.04 using Samba
How to hold a hands-on seminar using Jupyter using docker
How to right click using keyboard input in RPA?
How to make a Python package using VS Code
[Blender] How to dynamically set the selection of EnumProperty
Set PATH equivalent to "sudo su-" using Ansible environment
How to exit when using Python in Terminal (Mac)
[Introduction to Udemy Python3 + Application] 30. How to use the set
How to play Cyberpunk 2077 on Linux/Ubuntu 20.04 using AMD GPU
How to analyze with Google Colaboratory using Kaggle API
How to retrieve multiple arrays using slice in python.
[Introduction to Python] How to stop the loop using break?
How to execute a command using subprocess in Python
How to learn structured SVM of ChainCRF with PyStruct
How to write faster when using numpy like deque