Python Train Test Split - Machine Learning

Publicado el: 30 noviembre 2022
en el canal de: Data Science with Josh
2,149
63

In this Short, I demonstrate my preferred method for splitting a dataframe into training and test dataframes using pandas and sklearn.

Source code:

Libraries
import pandas as pd
import sqlalchemy
from sqlalchemy import create_engine
import sklearn
from sklearn.model_selection import train_test_split

Creating SQL Alchemy engine object
engine = create_engine('postgresql://postgres:youtube@localhost:5432/eSports.val')

Initiailizing connection to database
conn = engine.connect()

SQL query as a string to pass into pd.read_sql function
sql = 'SELECT * FROM players'

creating a dataframe
df = pd.read_sql_query(sql,conn)

dropping columns that aren't being analyzed
df = df.drop(['player_name','team', 'country'], axis=1)

Independent variables
X = df.drop('kd', axis=1)

Dependent (outcome) variable
y = df['kd']

train-test split
X_train, X_test, y_train, y_test = train_test_split(
X
, y
, test_size=0.3
, random_state=2)


En esta página del sitio puede ver el video en línea Python Train Test Split - Machine Learning de Duración hora minuto segunda en buena calidad , que subió el usuario Data Science with Josh 30 noviembre 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 2,149 veces y le gustó 63 a los espectadores. Disfruta viendo!