Python Forum
Need help on scikitLearn StratifiedKFold method
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help on scikitLearn StratifiedKFold method
#1
Objective: To create 5 folds of training and test dataset using StratifiedKFold method.

I am able to print the indices alright but am unable to generate the actual folds. Here follows my code

from sklearn.cross_validation import StratifiedKFold
import pandas as pd
df=pd.read_csv('C:\Comb_features_to_be_used.txt')
 
##Getting only numeric columns
p_input=df._get_numeric_data()
## Considering all the features except labels
p_input_features = p_input.drop('labels',axis=1)
## Considering only labels [single column]
p_input_label = p_input['labels']
skf = StratifiedKFold(p_input_label, n_folds=5, shuffle=True)
i={1,2,3,4,5}
for i,(train_index, test_index) in enumerate(skf):
    ##print("TRAIN:", train_index, "TEST:", test_index)
    p_input_features_train = p_input_features[train_index]
    p_input_features_test =  p_input_features[test_index]
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020