17 lines
620 B
Python
17 lines
620 B
Python
|
import time
|
||
|
from sklearn.neural_network import MLPClassifier
|
||
|
from sklearn.metrics import classification_report, accuracy_score
|
||
|
|
||
|
def MLP(X_train, X_test, y_train, y_test):
|
||
|
start_time = time.time()
|
||
|
# 训练 MLP 分类器
|
||
|
mlp = MLPClassifier(hidden_layer_sizes=(100,), max_iter=300, random_state=42)
|
||
|
mlp.fit(X_train, y_train)
|
||
|
y_pred = mlp.predict(X_test)
|
||
|
end_time = time.time()
|
||
|
# 打印训练时间
|
||
|
print("Training Time:", end_time - start_time, "seconds")
|
||
|
# 评估模型
|
||
|
print("Accuracy:", accuracy_score(y_test, y_pred))
|
||
|
print("Classification Report:")
|
||
|
print(classification_report(y_test, y_pred))
|