Course Content
ML Introduction with scikit-learn
1. Machine Learning Concepts
2. Preprocessing Data with Scikit-learn
ML Introduction with scikit-learn
Evaluate the Model with Cross-Validation
In this challenge, you will build and evaluate a model using both train-test evaluation and cross-validation.
The data is an already preprocessed Penguins dataset.
Some functions you will use:
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a65bbc96-309e-4df9-a790-a1eb8c815a1c/CrossValFunc.png)
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a65bbc96-309e-4df9-a790-a1eb8c815a1c/TrainTestFunc.png)
Task
Build a 4-nearest neighbors classifier and evaluate its performance using the cross-validation score first, then split the data into train-test sets, train the model using the training set, and evaluate it using the test set.
- Initialize a
KNeighborsClassifier
with 4 neighbors. - Calculate the cross-validation scores of this model with the number of folds set to 3.
Note: you can pass an untrained model to across_val_score()
function. - Use a suitable function to split
X, y
. - Train the model using the training set.
- Evaluate the model using the test set.
Everything was clear?
Course Content
ML Introduction with scikit-learn
1. Machine Learning Concepts
2. Preprocessing Data with Scikit-learn
ML Introduction with scikit-learn
Evaluate the Model with Cross-Validation
In this challenge, you will build and evaluate a model using both train-test evaluation and cross-validation.
The data is an already preprocessed Penguins dataset.
Some functions you will use:
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a65bbc96-309e-4df9-a790-a1eb8c815a1c/CrossValFunc.png)
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a65bbc96-309e-4df9-a790-a1eb8c815a1c/TrainTestFunc.png)
Task
Build a 4-nearest neighbors classifier and evaluate its performance using the cross-validation score first, then split the data into train-test sets, train the model using the training set, and evaluate it using the test set.
- Initialize a
KNeighborsClassifier
with 4 neighbors. - Calculate the cross-validation scores of this model with the number of folds set to 3.
Note: you can pass an untrained model to across_val_score()
function. - Use a suitable function to split
X, y
. - Train the model using the training set.
- Evaluate the model using the test set.
Everything was clear?