Machine Learning de extremo a extremo
Joshua Stapleton
Machine Learning Engineer
Creación de características
Técnicas
Beneficios

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Normalizer
# Divide los datos
X_train, X_test = train_test_split(df, test_size=0.2, random_state=42)
# Crea el objeto normalizador, ajusta en train, normaliza y transforma test
norm = Normalizer()
X_train_norm = norm.fit_transform(X_train)
X_test_norm = norm.transform(X_test)
from sklearn.preprocessing import StandardScaler
# Divide los datos
X_train, X_test = train_test_split(df, test_size=0.2, random_state=42)
# Crea un escalador y ajusta train para estandarizar
sc = StandardScaler()
X_train_stzd = sc.fit_transform(X_train)
# Solo transforma el set de test
X_test_stzd = sc.transform(X_test)


from sklearn.ensemble import RandomForestClassifier from sklearn.feature_selection import SelectFromModel from sklearn.model_selection import train_test_split# Primero divide en train y test para evitar fuga de datos X_train, X_test, y_train, y_test = train_test_split( heart_disease_df_X, heart_disease_df_y, test_size=0.2, random_state=42)
# Define y ajusta el modelo de random forest rf = RandomForestClassifier(n_jobs=-1, class_weight='balanced', max_depth=5) rf.fit(X_train, y_train)# Define y ejecuta la selección de características model = SelectFromModel(rf, prefit=True) features_bool = model.get_support() features = heart_disease_df.columns[features_bool]
Machine Learning de extremo a extremo