Module2.3 Hyperparameter Optimization
Module2.3 Hyperparameter Optimization
# Load the diabetes dataset (you may need to adjust the path to your dataset).
diabetes_data = pd.read_csv('diabetes.csv')
# Create and train a decision tree classifier with the suggested hyperparameters.
model = DecisionTreeClassifier(
max_depth=max_depth,
min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf,
random_state=42 # for reproducibility
)
# Split the data into training and testing sets.
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
return accuracy
if __name__ == "__main__":
# Create a study object to manage the optimization process.
study = optuna.create_study(direction='maximize') # We want to maximize accuracy.