更新於 2024/06/17閱讀時間約 3 分鐘

AI說書 - 從0開始 - 25

我想要一天分享一點「LLM從底層堆疊的技術」,並且每篇文章長度控制在三分鐘以內,讓大家不會壓力太大,但是又能夠每天成長一點。


延續AI說書 - 從0開始 - 24示範了ChatGPT程式的能力,現在我們繼續做下去。


  1. Train a decision tree classifier model

Transformers for Natural Language Processing and Computer VisionWe create a DecisionTreeClassifier object from Scikit-learn's tree module and set the random state to 42. We then train the model on the training data using the fit method.

model = DecisionTreeClassifier(random_state=42) 
model.fit(X_train, y_train)
  1. Evaluate the model on the testing set

We use the score method of the trained model to evaluate the accuracy of the model on the testing set. We then print the accuracy to the console.

score = model.score(X_test, y_test) 
print(f"Accuracy: {score:.2f}")
  1. Compute the confusion matrix
y_pred = model.predict(X_test) 
cm = confusion_matrix(y_test, y_pred)
  1. Plot the confusion matrix
fig, ax = plt.subplots()
im = ax.imshow(cm, interpolation = "nearest", cmap = plt.cm.Blues)
ax. Figure.colorbar(im, ax = ax)
ax.set(xticks = np.arange(cm.shape[1]),
yticks = np.arange(cm.shape[0]),
xticklabels = iris.target_names, yticklabels = iris.target_names,
title = "Confusion matrix",
xlabel = "Predicted label",
ylabel = "True label")

plt.setp(ax.get_xticklabels(), rotation = 45, ha = "right", rotation_mode = "anchor")
for i in range(cm.shape[0]):
for j in range(cm.shape[1]):
ax.text(j, i, format(cm[i, j], "d"), ha = "center", va = "center", color = "white" if cm[i, j] > cm.max() / 2 else "black")

fig.tight_layout()
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.