# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.9.7 ('base')
#     language: python
#     name: python3
# ---

import pandas as pd
from sklearn.linear_model import Ridge
from sklearn.model_selection import RepeatedKFold, GridSearchCV

# Load the dataset
df = pd.read_csv('auto-insurance.csv', header=None)

# Split the Dataset
data = df.values
X, y = data[:, :-1], data[:, -1]
X.shape, y.shape

# define Model
model = Ridge()

# define evaluation
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=42)

# define search space
space = dict()
space['solver'] = ['svd', 'cholesky', 'lsqr', 'sag']
# space['alpha'] = loguniform(1e-5, 100)  For Random Search
space['alpha'] = [1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1, 10, 100]  # For Grid Search
space['fit_intercept'] = [True, False]
space['normalize'] = [True, False]

# define search
search = GridSearchCV(model, space, cv=cv, scoring='neg_mean_absolute_error', n_jobs=-1)

# execute search
result = search.fit(X,y)

# summarize result
print('Best Score: %s' % result.best_score_)
print('Best Hyperparameters: %s' % result.best_params_)



StarcoderdataJupyterScriptsDedupFiltered