0% found this document useful (0 votes)
7 views

Remarque Sur L'effect Des Different Valeurs C

GridSearchCV is a method in scikit-learn that performs exhaustive searches over predefined hyperparameter grids to find the best hyperparameters and model. It works by defining a hyperparameter grid, performing cross-validation to evaluate models for each hyperparameter combination, selecting the best model based on performance, and providing attributes to access results.

Uploaded by

Unknowen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Remarque Sur L'effect Des Different Valeurs C

GridSearchCV is a method in scikit-learn that performs exhaustive searches over predefined hyperparameter grids to find the best hyperparameters and model. It works by defining a hyperparameter grid, performing cross-validation to evaluate models for each hyperparameter combination, selecting the best model based on performance, and providing attributes to access results.

Uploaded by

Unknowen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

GridSearchCV is a method provided by scikit-learn for hyperparameter tuning and model selection

through exhaustive search over a predefined grid of hyperparameters.

Here's a breakdown of how GridSearchCV works:

Hyperparameter Grid: You define a dictionary where keys are hyperparameters and values are lists of
values to try. This grid represents the hyperparameter space you want to search.

Cross-Validation: GridSearchCV splits the data into 'k' folds (specified by the cv parameter) and
performs cross-validation. It iterates through each combination of hyperparameters and for each
combination, it trains the model on k-1 folds and evaluates on the remaining fold. This process is
repeated 'k' times (once for each fold) and the average performance metric (e.g., accuracy, F1-score)
is calculated.

Model Fitting and Evaluation: For each combination of hyperparameters, GridSearchCV fits the model
using the training data and evaluates its performance using cross-validation.

Best Model Selection: After evaluating all combinations, GridSearchCV selects the model with the
best average performance metric across all folds. It can be accessed using the best_estimator_
attribute.

Parameter Access: You can also access other attributes such as best_params_ (the hyperparameters
that resulted in the best model), cv_results_ (a dictionary containing detailed information about the
cross-validation results for each combination of hyperparameters), and more.

Scoring: You can specify the scoring metric to optimize using the scoring parameter. Common choices
include accuracy, precision, recall, F1-score, etc.

Remarque sur l’effect des different valeurs C :

Importing Libraries and Loading Data:

You start by importing necessary libraries and loading the Iris dataset.

Data Preparation:
You select a subset of the Iris dataset containing only the 'versicolor' and 'virginica' classes.

Features are extracted from the dataset, and a train-test split is performed.

Visualization Functions:

Visualiser_data: Visualizes the dataset with training and test samples.

Visualiser_surface_decision: Visualizes decision boundaries.

Visualiser_hyperplans: Visualizes the hyperplane and margins.

Visualiser_VS: Visualizes support vectors.

Training and Visualization:

SVM classifiers with linear kernels are trained for different values of C (100, 10, 1, 0.1).

For each value of C, decision boundaries, hyperplanes, and margins are plotted.

Training and test accuracies for each C value are printed.

Let's delve deeper into the significance of C:

C Parameter in SVM:

C is the regularization parameter in SVM.

It controls the trade-off between maximizing the margin and minimizing the classification error.

A small C leads to a larger margin but may misclassify more points (soft margin).

A large C penalizes the misclassification heavily, resulting in a smaller margin (hard margin).

Effect of C:

High C (Low Bias, High Variance):

The model tries to classify all training examples correctly.

It may result in overfitting, especially when training data is noisy.

Decision boundary tends to be more complex, fitting closely to data points.

Low C (High Bias, Low Variance):

Emphasizes a larger margin, allowing some misclassifications.

Results in a simpler decision boundary, less prone to overfitting.

More robust to noisy data but might underfit if the data is complex.
Observations:

As C decreases, the decision boundary becomes smoother and less affected by individual data points.

Higher values of C lead to more complex decision boundaries, fitting the training data more closely.

The choice of C impacts the bias-variance trade-off and generalization performance.

By experimenting with different values of C, you can find an optimal balance between bias and
variance, ensuring good generalization to unseen data.

Si on utilise tous les 4 features de iris data base :

Increased Feature Dimensionality:

Currently, the code selects only two features, sepal length and petal length, for training and
visualization (X = df.iloc[50:150, [0, 2]].values). If you were to include all four features, you would
modify this line to include all four features (X = df.iloc[50:150, :4].values).

This change would result in working with a higher-dimensional feature space, affecting model
complexity and computational requirements.

Visualization Challenges:

Visualizing decision boundaries and data points in four dimensions becomes challenging.

You would need to explore techniques like dimensionality reduction (e.g., PCA) to visualize the data
effectively.

Alternatively, you might consider visualizing pairwise combinations of features or using advanced
visualization techniques.

Model Training and Evaluation:

Training SVM models with all four features increases the complexity of the optimization problem.

It may require longer training times and more computational resources.

Model evaluation becomes more critical, and techniques like cross-validation might be necessary to
assess model performance effectively.

Parameter Tuning:
The choice of parameters, particularly C, becomes more crucial with increased feature
dimensionality.

You might need to perform a more extensive parameter search using techniques like grid search
(GridSearchCV) to find the optimal parameter values.

Generalization Performance:

Using all four features may improve the model's ability to capture complex patterns in the data.

However, it also increases the risk of overfitting, especially if some features are noisy or irrelevant.

Regularization parameters like C become essential for controlling overfitting.

Code Modification:

The visualization functions (Visualiser_surface_decision, Visualiser_hyperplans, etc.) might need


modifications to handle the additional feature dimensions and adapt to the higher-dimensional
space.

Interpretability:

With more features, the interpretability of the model and decision boundaries may decrease.

Understanding the contributions of individual features to the classification becomes more


challenging.

Polynomial Kernel (degree parameter):

The degree parameter determines the degree of the polynomial used by the polynomial kernel.

Increasing the degree parameter typically increases the complexity of the decision boundary.

Higher polynomial degrees allow the model to capture more complex relationships in the data.

However, increasing the degree excessively can lead to overfitting, especially if the dataset is not very
large or noisy.

Conversely, using a lower degree may lead to underfitting, as the model may not capture enough
complexity to accurately represent the data.

RBF Kernel (gamma parameter):

The gamma parameter defines the influence of a single training example, with low values meaning
'far' and high values meaning 'close'.
A small gamma value means that points farther away from the decision boundary have more
influence.

Conversely, a large gamma value means that points closer to the decision boundary have more
influence.

Increasing gamma can lead to a more complex decision boundary, potentially resulting in overfitting.

Conversely, decreasing gamma can make the decision boundary smoother, which might prevent
overfitting but could lead to underfitting if set too low.

Observations:

Polynomial Kernel (degree):

Increasing degree can result in more complex decision boundaries, potentially improving
performance on complex datasets.

However, it may also increase the risk of overfitting, especially if the dataset is not large enough or
noisy.

RBF Kernel (gamma):

Increasing gamma can make the decision boundary more flexible, potentially improving performance
on non-linear datasets.

However, it may also increase the risk of overfitting, especially if the dataset is not large enough or
contains noise.

Overall, selecting appropriate values for degree and gamma involves a trade-off between model
complexity and generalization performance. Experimenting with different values and evaluating
performance on a validation set can help determine the optimal settings for these hyperparameters.

You might also like