Python Forum
Jupyter Notebook - Help Needed!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jupyter Notebook - Help Needed!
#1
Exclamation 
Hello!!

I have a dataset with the a dimension of [38355, 257] , and it has 14 classes. I tried to split the data into (70%, 15%, 15%) for training, validation and testing sets. At the same time I used (stratify=y) to make sure that the percentages are taken from each corresponding class correctly.

The split code I used:

from sklearn.model_selection import train_test_split
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size = 0.15, random_state = 1,stratify=y)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_train, y_train, test_size = 0.1764705, random_state = 1, stratify=y)
The problem is ... When applying the second split I got this error:

ValueError: Found input variables with inconsistent numbers of samples: [32601, 38355]
How can I fix the problem?! Cry Cry
Reply
#2
First problem - line 4 is redundant (you have already imported the function once).

Second, try not using the same variables as the parameters and result in line 5. Try
X_t. X_test. y_t, y_test = train_test_split(X_train, y_train, test_size = 0.1764705, random_state = 1, stratify=y) 
BashBedlam likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Jupyter notebooks, jupyter kernels, virtual environment created in Anaconda... bytecrunch 8 2,135 Nov-05-2023, 06:38 PM
Last Post: snippsat
  Jupyter Notebook TypeError Holidays entity loader class bmanning20 0 2,650 Jul-20-2023, 06:52 PM
Last Post: bmanning20
  Why does graph look different in Codecademy and Jupyter Notebook abc123456 1 1,452 Mar-29-2023, 09:22 AM
Last Post: newbieAuggie2019
  Setting up and integrating Jupyter Notebook development environment with VSC Drone4four 3 1,785 Sep-12-2022, 09:18 AM
Last Post: Drone4four
Thumbs Up can't access data from URL in pandas/jupyter notebook aaanoushka 1 1,830 Feb-13-2022, 01:19 PM
Last Post: jefsummers
  Help needed with Jupyter Notebook eyadfr 4 2,083 Jan-04-2022, 08:20 PM
Last Post: snippsat
  HELP! Importing json file into csv into jupyter notebook vilsef 2 2,533 Jan-22-2021, 11:06 AM
Last Post: snippsat
  How can draw a real-time marker on map using folium/leaflet Jupyter notebook C3PO 0 2,389 Dec-22-2020, 07:04 PM
Last Post: C3PO
  Python Custom Module not working in Jupyter Notebook with Pandas fid 0 2,009 Jul-04-2020, 11:05 AM
Last Post: fid
  How to change working directory in Jupyter Notebook? rajeev1729 2 21,034 Aug-25-2019, 07:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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