可以按列名称拆分数据集,但是我想按行拆分它,例如我有100行数据,数据将按80:20分为两部分。 80行用于培训,20行用于测试。我如何实现它,到目前为止,按列拆分我得到了不同的结果。
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
X = weather[['City', 'Country', 'Latitude', 'Longitude', 'datetime', 'humidity',
'pressure', 'temperature', 'wind_direction', 'wind_speed']] # Here first : means fetch all rows :-1 means except last column
Y = weather['weather_description'] # : is fetch all rows 3 means 3rd column
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2)