Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

kfold cross validation sklearn

import numpy as np
from sklearn.model_selection import KFold
X = np.array([[1, 2], [3, 4], [1, 2], [3, 4]])
y = np.array([1, 2, 3, 4])
kf = KFold(n_splits=2)
kf.get_n_splits(X)

print(kf)

for train_index, test_index in kf.split(X):
    print("TRAIN:", train_index, "TEST:", test_index)
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]
Comment

PREVIOUS NEXT
Code Example
Python :: how to write a file in python 
Python :: replace transparent pixels python 
Python :: pytest check exception 
Python :: datetime utcnow 
Python :: python put quotes in string 
Python :: run a loop in tkinter 
Python :: python jokes 
Python :: natural log and log base 10 in python 
Python :: python generate id 
Python :: append record in csv 
Python :: glob list all files in directory 
Python :: Concatenate strings from several rows using Pandas groupby 
Python :: python [remote rejected] master - master (pre-receive hook declined) 
Python :: python remove first item in tuple 
Python :: subprocess print logs 
Python :: strptime 
Python :: dir template 
Python :: python check if nan 
Python :: pandas xlsx to dataframe 
Python :: barplot syntax in python 
Python :: measure execution time in ipython notebook 
Python :: Simple pagination wrapper for discord.py. 
Python :: stock market api python 
Python :: Filter pandas DataFrame by substring criteria 
Python :: join pandas dataframe by column 
Python :: datetime.datetime.fromtimestamp() 
Python :: How to search where a character is in an array in python 
Python :: python creating a dict from a string 
Python :: python selenium get text of div 
Python :: check if camera is being used python 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =