Untitled

 avatar
unknown
python
2 years ago
819 B
5
Indexable
from sklearn.neural_network import MLPClassifier

def probar(mlp, X_train_new, X_test_new, y_train, y_test):
    f1_macro = evaluate_on_spiral(mlp, X_train_new, X_test_new, y_train, y_test, plot=False)
    print(f"F1-macro = {f1_macro}")

mlp = MLPClassifier()
X_train_new = np.transpose([X_train[:,0], X_train[:,1], X_train[:,0]*X_train[:,1], X_train[:,0]**2, X_train[:,1]**2, np.sin(X_train[:,0], np.sin(X_train[:,1]))])
X_test_new = np.transpose([X_test[:,0], X_test[:,1], X_test[:,0]*X_test[:,1], X_test[:,0]**2, X_test[:,1]**2, np.sin(X_test[:,0], np.sin(X_test[:,1]))])
print(np.shape(X_test), np.shape(y_test))
mlp.fit(X_train_new, y_train)
y_predict = mlp.predict(X_test_new)

f1_macro = evaluate_on_spiral(mlp, X_train_new, X_test_new, y_train, y_test, plot=False)
print(f"F1-macro = {f1_macro}")
Editor is loading...