×

SKLearn Model Selection

  • The model selections of SK learn has many functions with which we can work on.
  • It has functions to cross-validate the model and, it also provides validation and learning curves.
  • It is used for hyperparameters to tune the estimators.
  • Let us consider a list of functions the module provides.

The Splitter Classes

  • ms.GroupKFold([ n_splits ]): It is similar to cross-validation. This function is mainly used to form non – overlapping groups.
  • ms.GroupShuffleSplit([ ... ]): This function is mainly used to shuffle groups outcross validation test.
  • ms.KFold([ n_splits, shuffle, ... ]): We can use this function to perform kformcross-validation test.
  • ms.LeaveOneGroupOut( ): The aim of this function is used to perform the leave one group out cross-validation test.
  • ms.LeavePGroupsOut( n_groups ): This function uses p group out to perform its activity. It used this group to perform the test.
  • ms.LeaveOneOut( ):  The aim of the function is used to perform leave one out cross-validation.
  • ms.LeavePOut( p ): The main aim of this function is to perform the cross validator with leave one out.
  • ms.PredefinedSplit( test_fold ): The main aim of the function is used to perform the test on the p-outcross-validation test. This function is the original version of the leave-one-out test.
  • ms.RepeatedKFold( *[, n_splits, ... ] ): This function is used to perform test on the predefined split and it perform cross-validation test.
  • ms.RepeatedStratifiedKFold( *[, ... ] ): The main purpose of this function is to perform the test on k-fold cross-validation which is repeatedly stratified.
  • ms.ShuffleSplit([n_splits, ... ]): The aim of the function is used to perform tests on datasetsthat are shuffled silt with the help of random permutation.
  • ms.StratifiedKFold([ n_splits, ... ]): This function is used to perform test of stratified k fold cross validation test.
  • ms.StratifiedShuffleSplit([ ... ]): The aim of the function is used to perform a test on a dataset of shuffle split cross-validationtests.
  • ms.StratifiedGroupKFold([ ... ]): The aim of the function is used to perform a test on data of nonoverlappinggroups to perform k fold cross-validation test.
  • ms.TimeSeriesSplit([ n_splits, ... ]): This function is mainly used for time series of cross-validation test.

Splitter Functions

  • ms.check_cv([ cv, y, classifier ]): This function helps in performing cross validation test by checking the utility.
  • ms.train_test_split( *arrays[, ...] ): This function separates the matrices into the training and it tests the data sets based on the random which is used to perform the cross-validation test.

Hyperparameter Optimizers

  • ms.GridSearchCV( estimator, ... ): The main aim of the function is to perform a search for an estimator with the defined parameters.
  • ms.HalvingGridSearchCV( ...[, ...] ): The main aim of the function is to perform the search with the given parameters with the help of successive halving.
  • ms.ParameterGrid( param_grid ): The main aim of the parameter is used to perform the grid of parameters, There is a different range of values for every parameter.
  • msParameterSampler(  ..[, ...] ): This function is taken from the given sample distribution, which works as a generator on samples of parameters.
  • ms.RandomizedSearchCV( ...[, ...] ): This function is used to work on the hyperparameters, which helps to perform a random search.
  • ms.HalvingRandomSearchCV( ...[, ...] ): This function is used to work on the hyperparameters, which helps to perform a random search.

Program:

# Python program onk-fold cross-validation test   
 # Import the library required  
from sklearn.datasets import load_iris  
from sklearn.linear_model import LogisticRegression  
from sklearn.model_selection import cross_val_score, KFold  
 # Loading the dataset  
i = load_iris()    
 # Getting dependent and independent features  
A = i.data  
B= i.target  
print("The size of the Dataset is : ", len( A ))      
# Creating a object of logistic regression
log = LogisticRegression()     
# Perform the logistic regression on dataset of train
log.fit( X, Y )     
# Performing K-fold cross-validation test  
k = KFold(n_splits = 5)  
s= cross_val_score(log, A,B, cv=k)   
# Printing accuracy of the scores  
print("Validation scores ofK-fold Cross :", s)  
print("Validation score of Mean Cross : ", s.mean())

Output:

The size of the Dataset is: 100
Validation Scores of K-fold Cross: [2.  2  0.86333667 0.91111133 0.89999999]
Validation score of mean cross:  0.95688888889990

Related Topics

Python Typing Module

An Introduction to the Typing Module The typing module is introduced in Python version 3.5 and used to provide hinting method types in order to support static type checkers and linters...

10 minutes read.

GUI to extract lyrics from a song Using Tkinter in Python

GUI: A graphical interface (GUI) is a user interface that lets users interact with electronic devices like computers and smartphones by using menus, icons, and other visual cues (graphics). In contrast...

4 minutes read.

Python EOL (End Of Line)

Introduction An EOL (End Of Line) is defined as a syntax error that indicates that the Python interpreter reached at the end of the line when it tried to scan a...

3 minutes read.

How to develop a game in python

Fun always makes a task interesting and easy to execute. Learning in the same theoretical way at some point reaches the boring spot. In this article, using some Python knowledge,...

13 minutes read.

Python List extend() method

Python List extend() method The list.extend() method extends the list by appending all the items from the iterable. Syntax list.extend(iterable) Parameter iterable: It is a required parameter which represents any iterable unlike list, set, tuple, etc. Example 1 # Python...

1 minute read.

Python Dictionary update() method

Python Dictionary update() method The dictionary.update() method in Python inserts the specified items to the dictionary. Syntax dictionary.update(iterable) Parameter iterable- This parameter represents a dictionary or an iterable object with key value pairs, that will...

1 minute read.

Python Program to Check Leap Year

Python Program to Check Leap Year Leap year: We all know that each year has 365 or 366 days. But whenever a year has 366 days, then the year is said...

2 minutes read.

Closest Pair of Points in Python

We are given an array of n points in the plane, and our task is to find the pair of points in the array that are the closest to each...

3 minutes read.

How to write a program in python?

How to write a program in python? In python, writing programs is not a big deal. What we need to work on is our logic and some basic rules of this...

4 minutes read.

Python Prime factorization

Python Prime factorization In this tutorial, we will design a program where we will find all the prime factors of a number. Then, we will print all these prime factors of...

3 minutes read.

OSError in Python

Python: Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It is said...

4 minutes read.

Python divmod() function

Python divmod() function The divmod() function in Python returns a tuple containing the quotient  and the remainder when parameter ‘a’ (divident) is divided by parameter ‘b’ (divisor). Syntax: divmod(a, b) Parameter a: This parameter represents a number you...

1 minute read.

Python String ljust() method

Python String ljust() method The string.ljust() method in Python will left align the string, where the padding is done using the parameter fillchar (space is default). Syntax String.ljust(width[, fillchar]) Parameter width: This parameter represents the...

2 minutes read.

Python Statistical Module

Python Statistical Module The Python statistical module provides various functions that we can use in our Python program, to perform mathematical statistics operations on the numerical data given to us. The...

8 minutes read.

Python AIOHTTP

Python 3.5 introduced some new syntax that makes it simpler for developers to make asynchronous programmes and packages. Aiohttp, an HTTP client/server for asyncio, is one such package. In essence,...

3 minutes read.

Python Stack

Python Stack: The work Stack is defined as arranging a pile of objects or items on top of another. It is the same method of allocating memory in the stack...

10 minutes read.

Python program to count the number of a substring in a string

Python program to count the number of a substring in a string A part of the string is called a substring. This article explains the Python program to find how many...

1 minute read.

Python frozenset()

Python frozenset() class The frozenset() class in Python returns a new frozenset object, optionally with elements taken from iterable. Syntax class frozenset([iterable]) Parameter iterable: This parameter represents an iterable object, like list, set, tuple etc. Return This class returns an unchangeable...

1 minute read.

Python setattr() function

Python setattr() function The setattr() function sets the value of the specified attribute of the specified object. Syntax setattr(object, name, value) Parameter object: This parameter represents any object. name: This parameter represents the name of the attribute you...

1 minute read.

Palindrome program in Python

Palindrome program in python A number or string is said to be a palindrome if we invert the number or string and the string or number remains the same as the...

3 minutes read.