Regressão de Vetor Suporte

Eai meu povo, tudo bem?

Aqui vai o código usado nos videos abaixo com intuição sobre Maquina e Regressão de Vetor Suporte e a implementação da Regressão em python.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 24 22:55:59 2021

@author: rafaeldontalgoncalez
"""

######################################
# Importando as bibliotecas
######################################

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVR


######################################
# Importa o dataset
######################################

dataset = pd.read_csv('Posicao_Salario.csv')
X = dataset.iloc[:, 1].values.reshape(-1,1)
y = dataset.iloc[:, -1].values.reshape(-1,1)

######################################
# Feature Scalling
######################################
sc_X = StandardScaler()
sc_y = StandardScaler()
X = sc_X.fit_transform(X)
y = sc_y.fit_transform(y)


######################################
# Treinando o modelo para SVR
######################################
regressor = SVR(kernel='rbf')
regressor.fit(X,y)


######################################
# Imprime a regressao SVR
######################################


plt.scatter(X, y, color = 'red')
plt.plot(X, regressor.predict(X), color = 'blue')
plt.title('Regressao SVR')
plt.xlabel('Nivel')
plt.ylabel('Salario')
plt.show()


######################################
# Prevendo resultados para regressao de vetor suporte
######################################

sc_y.inverse_transform(regressor.predict(sc_X.transform([[7.5]])))