image_output_1.png
from sklearn.metrics import mean_absolute_error

from sklearn.preprocessing import LabelEncoder

from sklearn.preprocessing import StandardScaler

from sklearn.svm import SVR

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
df = pd.read_csv('../input/california-housing-value/housing.csv')
X = df.drop(columns=['median_house_value'])
y = df['median_house_value']

def preprocess_features(X):
    total_bedrooms_mean = round(X['total_bedrooms'].mean(), 3)
    X = X.fillna(total_bedrooms_mean)
    from sklearn.preprocessing import LabelEncoder
    le = LabelEncoder()
    le.fit(X['ocean_proximity'])
    transformed = le.transform(X['ocean_proximity'])
    X['ocean_proximity'] = transformed
    from sklearn.preprocessing import StandardScaler
    scale = StandardScaler()
    X = scale.fit_transform(X)
    return X
def run_reg(regressor, x_train, x_test, y_train, y_test):
    regressor.fit(x_train, y_train)
    prediction = regressor.predict(x_test)
    prediction = np.clip(prediction, 15000, 500000)
    from sklearn.metrics import mean_absolute_error
    mae = mean_absolute_error(y_test, prediction)
    import matplotlib.pyplot as plt
    return mae

from sklearn.svm import SVR
mae_array = np.zeros((5, 6))
cost = [1000, 10000, 100000, 1000000, 10000000]
epsilon = [2000, 5000, 10000, 20000, 50000, 100000]
row = 0
column = 0
for i in cost:
    column = 0
    for j in epsilon:
        svr_reg = SVR(kernel='rbf', C=i, epsilon=j)
        mae = run_reg(svr_reg, X_train, X_test, y_train, y_test)
        mae_array[row][column] = mae
        column = column + 1
    row = row + 1

import matplotlib.pyplot as plt
plt.contourf([2000, 5000, 10000, 20000, 50000, 100000], [1000, 10000, 100000, 1000000, 10000000], mae_array, 100, cmap='pink')
plt.yscale('log')
plt.xscale('log')
plt.colorbar()
plt.xlabel('Epsilon')
plt.ylabel('Cost')
plt.show()