forked from ci4s/pipeline-convert
模型优化结果写入文件
This commit is contained in:
parent
0a77fc8850
commit
c2f269961f
|
|
@ -0,0 +1,49 @@
|
|||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
name: juicefs-mount
|
||||
namespace: kube-system
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: juicefs-mount
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: juicefs-mount
|
||||
spec:
|
||||
containers:
|
||||
- name: juicefs
|
||||
image: 172.20.32.187/pipeline-service/juicefs:v2
|
||||
lifecycle:
|
||||
preStop:
|
||||
exec:
|
||||
command: ["/bin/sh", "-c"," echo 'begin to umount juicefs'; umount -l -t fuse.juicefs /platform-data/, echo 'umount /platform-data success'"]
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
- name: mountpoint
|
||||
mountPath: /platform-data
|
||||
mountPropagation: Bidirectional
|
||||
command: ["/bin/sh", "-c"]
|
||||
args:
|
||||
- |
|
||||
mounted=$(findmnt /platform-data/ | grep 'fuse.juicefs')
|
||||
if [ -z "$mounted" ]; then
|
||||
echo "Mounting JuiceFS..."
|
||||
juicefs mount -d redis://172.20.32.185:31202/4 /platform-data
|
||||
else
|
||||
echo "JuiceFS already mounted at /platform-data"
|
||||
fi
|
||||
sleep infinity
|
||||
volumes:
|
||||
- name: mountpoint
|
||||
hostPath:
|
||||
path: /platform-data
|
||||
type: DirectoryOrCreate
|
||||
tolerations:
|
||||
- effect: NoSchedule
|
||||
operator: Exists
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
restartPolicy: Always
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"category_id": 8,
|
||||
"component_name": "auto-sklearn",
|
||||
"component_label": "auto-sklearn自动机器学习",
|
||||
"description": "auto-sklearn自动机器学习",
|
||||
"image": "",
|
||||
"working_directory": "",
|
||||
"command": "",
|
||||
"mount_path": "",
|
||||
"in_parameters": {
|
||||
"--automl_name": {
|
||||
"type": "select",
|
||||
"item_type": "auto-ml",
|
||||
"label": "自动机器学习名称",
|
||||
"require": 1,
|
||||
"choice": [],
|
||||
"default": "",
|
||||
"placeholder": "自动机器学习名称",
|
||||
"describe": "自动机器学习名称",
|
||||
"editable": 1,
|
||||
"condition": ""
|
||||
}
|
||||
},
|
||||
"out_parameters": {
|
||||
"--automl_output": {
|
||||
"type": "str",
|
||||
"label": "输出结果",
|
||||
"path": "",
|
||||
"require": 0
|
||||
}
|
||||
},
|
||||
"env_variables": {}
|
||||
}
|
||||
|
|
@ -494,95 +494,93 @@ with open(args.output_folder + '/result.txt', 'w') as file:
|
|||
# iterations, number of models failed with a time out.
|
||||
print(automl.sprint_statistics(), file=file)
|
||||
|
||||
automl.performance_over_time_.plot(
|
||||
x='Timestamp',
|
||||
kind='line',
|
||||
legend=True,
|
||||
title='Auto-sklearn accuracy over time',
|
||||
grid=True,
|
||||
)
|
||||
plt.savefig(args.output_folder + '/Auto-sklearn_accuracy_over_time.png')
|
||||
plt.close()
|
||||
|
||||
if args.task_type == 'classification':
|
||||
with open(args.output_folder + '/result.txt', 'w') as file:
|
||||
train_predictions = automl.predict(X_train)
|
||||
print("Train Accuracy score", sklearn.metrics.accuracy_score(y_train, train_predictions))
|
||||
|
||||
test_predictions = automl.predict(X_test)
|
||||
print("Test Accuracy score", sklearn.metrics.accuracy_score(y_test, test_predictions))
|
||||
|
||||
# 绘图
|
||||
# 计算混淆矩阵
|
||||
y_train_true = np.argmax(y_train, axis=1)
|
||||
y_train_pred = np.argmax(train_predictions, axis=1)
|
||||
|
||||
cm = confusion_matrix(y_train_true, y_train_pred)
|
||||
|
||||
# 使用Seaborn绘制混淆矩阵
|
||||
plt.figure(figsize=(10, 7))
|
||||
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=target_columns)
|
||||
disp.plot(cmap=plt.cm.Blues)
|
||||
|
||||
# 添加标题和标签
|
||||
plt.title('Train Confusion Matrix')
|
||||
plt.xlabel('Predicted')
|
||||
plt.ylabel('True')
|
||||
plt.savefig(args.output_folder + '/Train_Confusion_Matrix.png')
|
||||
automl.performance_over_time_.plot(
|
||||
x='Timestamp',
|
||||
kind='line',
|
||||
legend=True,
|
||||
title='Auto-sklearn accuracy over time',
|
||||
grid=True,
|
||||
)
|
||||
plt.savefig(args.output_folder + '/Auto-sklearn_accuracy_over_time.png')
|
||||
plt.close()
|
||||
|
||||
y_test_true = np.argmax(y_test, axis=1)
|
||||
y_test_pred = np.argmax(test_predictions, axis=1)
|
||||
|
||||
cm = confusion_matrix(y_test_true, y_test_pred)
|
||||
|
||||
# 使用Seaborn绘制混淆矩阵
|
||||
plt.figure(figsize=(10, 7))
|
||||
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=target_columns)
|
||||
disp.plot(cmap=plt.cm.Blues)
|
||||
|
||||
# 添加标题和标签
|
||||
plt.title('Test Confusion Matrix')
|
||||
plt.xlabel('Predicted')
|
||||
plt.ylabel('True')
|
||||
plt.savefig(args.output_folder + '/Test_Confusion_Matrix.png')
|
||||
|
||||
# plot_values = []
|
||||
# pareto_front = automl.get_pareto_set()
|
||||
# for ensemble in pareto_front:
|
||||
# predictions = ensemble.predict(X_test)
|
||||
# precision = sklearn.metrics.precision_score(y_test, predictions)
|
||||
# recall = sklearn.metrics.recall_score(y_test, predictions)
|
||||
# plot_values.append((precision, recall))
|
||||
# fig = plt.figure()
|
||||
# ax = fig.add_subplot(111)
|
||||
# for precision, recall in plot_values:
|
||||
# ax.scatter(precision, recall, c="blue")
|
||||
# ax.set_xlabel("Precision")
|
||||
# ax.set_ylabel("Recall")
|
||||
# ax.set_title("Pareto set")
|
||||
#
|
||||
# plt.savefig('result.png')
|
||||
# plt.show()
|
||||
else:
|
||||
with open(args.output_folder + '/result.txt', 'w') as file:
|
||||
if args.task_type == 'classification':
|
||||
train_predictions = automl.predict(X_train)
|
||||
print("Train R2 score:", sklearn.metrics.r2_score(y_train, train_predictions))
|
||||
print("Train Accuracy score", sklearn.metrics.accuracy_score(y_train, train_predictions), file=file)
|
||||
|
||||
test_predictions = automl.predict(X_test)
|
||||
print("Test R2 score:", sklearn.metrics.r2_score(y_test, test_predictions))
|
||||
print("Test Accuracy score", sklearn.metrics.accuracy_score(y_test, test_predictions), file=file)
|
||||
|
||||
# 绘图
|
||||
plt.scatter(train_predictions, y_train, label="Train samples", c="#d95f02")
|
||||
plt.scatter(test_predictions, y_test, label="Test samples", c="#7570b3")
|
||||
plt.xlabel("Predicted value")
|
||||
plt.ylabel("True value")
|
||||
plt.legend()
|
||||
plt.plot([30, 400], [30, 400], c="k", zorder=0)
|
||||
plt.xlim([30, 400])
|
||||
plt.ylim([30, 400])
|
||||
plt.tight_layout()
|
||||
plt.savefig(args.output_folder + '/regression.png')
|
||||
# 绘图
|
||||
# 计算混淆矩阵
|
||||
y_train_true = np.argmax(y_train, axis=1)
|
||||
y_train_pred = np.argmax(train_predictions, axis=1)
|
||||
|
||||
cm = confusion_matrix(y_train_true, y_train_pred)
|
||||
|
||||
# 使用Seaborn绘制混淆矩阵
|
||||
plt.figure(figsize=(10, 7))
|
||||
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=target_columns)
|
||||
disp.plot(cmap=plt.cm.Blues)
|
||||
|
||||
# 添加标题和标签
|
||||
plt.title('Train Confusion Matrix')
|
||||
plt.xlabel('Predicted')
|
||||
plt.ylabel('True')
|
||||
plt.savefig(args.output_folder + '/Train_Confusion_Matrix.png')
|
||||
plt.close()
|
||||
|
||||
y_test_true = np.argmax(y_test, axis=1)
|
||||
y_test_pred = np.argmax(test_predictions, axis=1)
|
||||
|
||||
cm = confusion_matrix(y_test_true, y_test_pred)
|
||||
|
||||
# 使用Seaborn绘制混淆矩阵
|
||||
plt.figure(figsize=(10, 7))
|
||||
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=target_columns)
|
||||
disp.plot(cmap=plt.cm.Blues)
|
||||
|
||||
# 添加标题和标签
|
||||
plt.title('Test Confusion Matrix')
|
||||
plt.xlabel('Predicted')
|
||||
plt.ylabel('True')
|
||||
plt.savefig(args.output_folder + '/Test_Confusion_Matrix.png')
|
||||
|
||||
# plot_values = []
|
||||
# pareto_front = automl.get_pareto_set()
|
||||
# for ensemble in pareto_front:
|
||||
# predictions = ensemble.predict(X_test)
|
||||
# precision = sklearn.metrics.precision_score(y_test, predictions)
|
||||
# recall = sklearn.metrics.recall_score(y_test, predictions)
|
||||
# plot_values.append((precision, recall))
|
||||
# fig = plt.figure()
|
||||
# ax = fig.add_subplot(111)
|
||||
# for precision, recall in plot_values:
|
||||
# ax.scatter(precision, recall, c="blue")
|
||||
# ax.set_xlabel("Precision")
|
||||
# ax.set_ylabel("Recall")
|
||||
# ax.set_title("Pareto set")
|
||||
#
|
||||
# plt.savefig('result.png')
|
||||
# plt.show()
|
||||
else:
|
||||
train_predictions = automl.predict(X_train)
|
||||
print("Train R2 score:", sklearn.metrics.r2_score(y_train, train_predictions), file=file)
|
||||
|
||||
test_predictions = automl.predict(X_test)
|
||||
print("Test R2 score:", sklearn.metrics.r2_score(y_test, test_predictions), file=file)
|
||||
|
||||
# 绘图
|
||||
plt.scatter(train_predictions, y_train, label="Train samples", c="#d95f02")
|
||||
plt.scatter(test_predictions, y_test, label="Test samples", c="#7570b3")
|
||||
plt.xlabel("Predicted value")
|
||||
plt.ylabel("True value")
|
||||
plt.legend()
|
||||
plt.plot([30, 400], [30, 400], c="k", zorder=0)
|
||||
plt.xlim([30, 400])
|
||||
plt.ylim([30, 400])
|
||||
plt.tight_layout()
|
||||
plt.savefig(args.output_folder + '/regression.png')
|
||||
|
||||
dump(automl, args.output_folder + '/save_model.joblib')
|
||||
copy_directory_contents(args.tmp_folder, args.output_folder)
|
||||
|
|
|
|||
Loading…
Reference in New Issue