# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="T_Qy0mr5TQBN"
# Montando dataframe

# + id="JuYddin9S4q-"
import pandas as pd

# + id="Q_Najr02THuJ"
base = pd.read_csv('house_prices.csv')

# + id="_aUNAdbOTTrk"
x = base.iloc[:, 3:19].values
y = base.iloc[:, 2:3].values

# + [markdown] id="0Yl6XmWYO84L"
# Pré-processamento dos dados

# + id="x014dkJ-EsGX"
from sklearn.preprocessing import StandardScaler
scaler_x = StandardScaler()
x = scaler_x.fit_transform(x)
scaler_y = StandardScaler()
y = scaler_y.fit_transform(y)

# + [markdown] id="Z2u-zV5KU5H2"
# Divisão de dataframe em teste e treinamento

# + id="vpjWQfqyTkvh"
from sklearn.model_selection import train_test_split
x_trein, x_teste, y_trein, y_teste = train_test_split(x, y, test_size=0.3, random_state=0)

# + [markdown] id="F3_Cgi70U9h7"
# Regressão kernel linear

# + id="3jereyo9Uwih" colab={"base_uri": "https://localhost:8080/"} outputId="a112ae28-2944-4634-c2cc-2ca730ea5977"
from sklearn.svm import SVR
regressor_linear = SVR(kernel='linear')
regressor_linear.fit(x_trein, y_trein)

# + colab={"base_uri": "https://localhost:8080/"} id="l9e8fZKgV3I7" outputId="9fab888c-2159-43ac-f529-e4784f218668"
regressor_linear.score(x_trein, y_trein)

# + id="d63m7dSpReWd"
previsoes = regressor_linear.predict(x_teste)
y_teste = scaler_y.inverse_transform(y_teste)
previsoes = scaler_y.inverse_transform(previsoes)

# + colab={"base_uri": "https://localhost:8080/"} id="7QwyAfG4Qi5V" outputId="fa51cdd6-2055-441e-fa1c-89146204f096"
from sklearn.metrics import mean_absolute_error
mae = mean_absolute_error(y_teste, previsoes)
mae

# + [markdown] id="ogP6RbzjP_tT"
# Regressão kernel polinomial

# + id="42T2MqbKWMiR" colab={"base_uri": "https://localhost:8080/"} outputId="09bc14ed-b8c2-4f40-f3ff-957673fe6570"
regressor_poly = SVR(kernel='poly', degree=3)
regressor_poly.fit(x_trein, y_trein)

# + colab={"base_uri": "https://localhost:8080/"} id="PgQ0ErcJQDMA" outputId="70b3a374-2891-4a0e-841f-04873662ae42"
regressor_poly.score(x_trein, y_trein)

# + colab={"base_uri": "https://localhost:8080/"} id="i18dAeA4Q0Ly" outputId="2035f1f9-d6cb-4f3c-bffc-af7a054257cd"
previsoes = regressor_poly.predict(x_teste)
previsoes = scaler_y.inverse_transform(previsoes)
mae = mean_absolute_error(y_teste, previsoes)
mae

# + [markdown] id="PEiHzCwIRAKm"
# Regressão kernel RBF

# + colab={"base_uri": "https://localhost:8080/"} id="Uf4m4E0nQJSe" outputId="7d3e1e0d-e5cf-4161-fa25-681d4f739fa3"
regressor_rbf = SVR(kernel='rbf')
regressor_rbf.fit(x_trein, y_trein)

# + colab={"base_uri": "https://localhost:8080/"} id="0H2llsoaQJG4" outputId="aa871665-e89f-4036-d08a-122057c5dd75"
regressor_rbf.score(x_trein, y_trein)

# + colab={"base_uri": "https://localhost:8080/"} id="g_GliKk1Q0ss" outputId="8e0483e9-3083-4835-d3bc-efbd14cc1f73"
previsoes = regressor_rbf.predict(x_teste)
previsoes = scaler_y.inverse_transform(previsoes)
mae = mean_absolute_error(y_teste, previsoes)
mae

StarcoderdataJupyterScriptsDedupFiltered