Cheguei num trecho do código que dá erro e não consigo sair disso.. já conferi e copiei o código do modelo, mas não resolve.
NameError Traceback (most recent call last) in () 12 13 #amostras aleatorias de 70% do conjunto para treino ---> 14 train_idxs = sample(list(X_normal.index), int(0.7*X_normal.shape[0])) 15 X_train = X_normal.loc[train_idxs] 16
NameError: name 'sample' is not defined
Código completo:
X['fraude'] = Y
X_anomalias = X[X['fraude'] == 1] X_normal = X[X['fraude'] == 0]
train_idxs = sample(list(X_normal.index), int(0.7*X_normal.shape[0])) X_train = X_normal.loc[train_idxs]
X_testing = X_normal.drop(train_idxs)
X_testing = pd.concat([X_testing, X_anomalias], axis=0)
X_train = X_train.sample(frac=1).reset_index(drop=True) X_testing = X_testing.sample(frac=1).reset_index(drop=True)
Y_testing = X_testing['fraude'] X_testing = X_testing [ [col for col in X_testing.columns if col != 'fraude']]
X_cv, X_eval, Y_cv, Y_eval = train_test_split(X_testing, Y_testing, train_size = 0.7, random_state=23)
Y_cv = Y_cv.apply(lambda x: 1 if x==0 else -1) Y_eval = Y_eval.apply(lambda x: 1 if x==0 else -1)
X_train = X_train[ [col for col in X_testing.columns if col != 'fraude']]