<jupyter_start><jupyter_text>Support Vector Regression - Demo---Separates data into two classes so that they are maximally apart. Suppose the data is linearly separable; what is the best line, i.e. with greatest margin, to separate them? While this may initially look like a classification algorithm (which is true! See the Support Vector Machine demo [here](https://github.com/NicoEssi/Machine_Learning_scikit-learn) for more on the classification implementation), this can also be used to do regression - as will be demonstrated in this jupyter notebook.![Image taken from Google; originally from DataCamp](http://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1526288454/index2_ub1uzd.png) Pros*   Easily adaptable*   Works very well on non-linear problems*   Not biased by outliers Cons*   More difficult to understand/explain*   Feature scaling compulsary---  1. Import dependencies and data<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

!wget https://github.com/NicoEssi/Machine_Learning_scikit-learn/raw/master/Position_Salaries.csv<jupyter_output><empty_output><jupyter_text>2. Read CSV and inspect<jupyter_code>data = pd.read_csv('Position_Salaries.csv')

X = data.iloc[:, 1:2]
y = data.iloc[:, 2]

data.head()<jupyter_output><empty_output><jupyter_text>3. Feature scaling<jupyter_code>from sklearn.preprocessing import StandardScaler

sc_X = StandardScaler()
sc_y = StandardScaler()

X = sc_X.fit_transform(X)
y = sc_y.fit_transform(y.values.reshape(-1,1))<jupyter_output><empty_output><jupyter_text>4. Initialize and fit the SVR model<jupyter_code>from sklearn.svm import SVR

regressor = SVR(kernel = 'rbf')
regressor.fit(X, y)<jupyter_output><empty_output><jupyter_text>5. Prediction with the trained model<jupyter_code>y_pred = regressor.predict(sc_X.transform(np.array([6.5]).reshape(1,-1)))
y_pred = sc_y.inverse_transform(y_pred)<jupyter_output><empty_output><jupyter_text>6. Result visualization<jupyter_code>plt.scatter(X, y, color = 'red')
plt.plot(X, regressor.predict(X), color = 'blue')
plt.title('(SVR)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11182696732627703, 'fraction_numerical': 0.013805798435342844, 'mean_word_length': 6.601398601398602, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '409636', 'license': 'MIT', 'n_tokens_mistral': 774, 'n_tokens_neox': 735, 'n_words': 179, 'path': 'Support_Vector_Regression_Demo.ipynb', 'repo_name': 'NicoEssi/Machine_Learning_Python', 'size': '2173'}