<jupyter_start><jupyter_text>Support Vector RegressionAlthough not amazing, support vector regression (SVR) is better at dealing with uneven spatial data than linear regression for example so it will hopefully produce a good model. In order to model using an SVR, we will first load the data.<jupyter_code>### import libraries ###

import pandas as pd
from sklearn.svm import SVR
from sklearn.metrics import r2_score, mean_squared_error
from sklearn.model_selection import GridSearchCV
### importing data ###

# features
features_train = pd.read_csv('data/features_train.csv', index_col = 0)
features_test = pd.read_csv('data/features_test.csv', index_col = 0)

# target
target_train = pd.read_csv('data/target_train.csv', index_col = 0)
target_test = pd.read_csv('data/target_test.csv', index_col = 0)<jupyter_output><empty_output><jupyter_text>Now we will model using SVR but we will use a grid search to find the optimal parameters.<jupyter_code>### building grid search ###

# choosing SVR
model = SVR()

# parameters to search through
parameters = {'kernel' : ('linear', 'rbf'), 'C' : [0.01, 0.1, 1, 10, 100, 1000]}

# fitting grid search
clf = GridSearchCV(model, parameters)
clf.fit(features_train, target_train.values.ravel())

# showing best parameters
clf.best_params_<jupyter_output><empty_output><jupyter_text>We found the best parameters for SVR.<jupyter_code>### checking metrics ###

# choosing best parameters
model = SVR(C = 1, kernel = 'rbf')

# fitting model
model.fit(features_train, target_train.values.ravel())

# predicted target
pred = model.predict(features_test)

print('RMSE is:', mean_squared_error(target_test, pred, squared = False), 'and the r2 is:', r2_score(target_test, pred))<jupyter_output>RMSE is: 1.0633770643225113 and the r2 is: -0.13077078092716254
{'fraction_non_alphanumeric': 0.10899944102850755, 'fraction_numerical': 0.03297931805477921, 'mean_word_length': 6.131474103585657, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '462558', 'license': 'MIT', 'n_tokens_mistral': 623, 'n_tokens_neox': 575, 'n_words': 176, 'path': '4.0_prs_support_vector_regression.ipynb', 'repo_name': 'psohn/Forest_Fires_Regression', 'size': '1789'}