返回

ChatShare 討論

載入討論中

手動匯入學習港島匿名客12 日前

I am a student in Google Colab. ChatGPT

你:I am a student in Google Colab. I already have X_test, y_test, and a trained model called model. I also have these va…

你

I am a student in Google Colab.
I already have X_test, y_test, and a trained model called model.

I also have these values in HKD: BASELINE_MAE, STARTER_TRAIN_MAE, STARTER_TEST_MAE, train_mae, test_mae.

pandas, matplotlib, and scikit-learn are already imported.

Please give Python code for ONE Colab cell that I can paste.

Comment every line in simple English.

Do not write a full .py file.

I will plot: predicted vs actual prices on the TEST set, with a y=x reference line.
because this chart shows: how closely unseen-car predictions match real sale prices and where the model makes large errors.

I will not plot: a heatmap or a price histogram.

because that would only show: correlations or the price distribution, not prediction accuracy on unseen cars.

Use the test set only for the predicted-vs-actual chart.
Do not plot the training rows.

Do not draw a heatmap.

Label both axes in HKD.

Use log scales so expensive outliers do not hide the ordinary cars.

AI

Draw predictions against actual prices for the untouched test set only.

fig, ax = plt.subplots(figsize=(8, 6))

Show each test car as one point.

ax.scatter(y_test, model.predict(X_test), alpha=0.5, s=24, color="#157f86")

Find a positive range that includes every test price and prediction.

low = max(1, min(y_test.min(), model.predict(X_test).min()))
high = max(y_test.max(), model.predict(X_test).max())

Draw the ideal prediction line for comparison.

ax.plot([low, high], [low, high], color="#c52f35", linestyle="--", label="Perfect prediction")

Use log scales to keep both common cars and expensive outliers visible.

ax.set_xscale("log")
ax.set_yscale("log")

Label both axes in Hong Kong dollars.

ax.set_xlabel("Actual sale price (HKD, log scale)")
ax.set_ylabel("Predicted sale price (HKD, log scale)")

Explain the figure with its measured test error.

ax.set_title(f"Test-set prices vs predictions | MAE HK${test_mae:,.0f}")

Add a grid and line label for readability.

ax.grid(True, alpha=0.25)
ax.legend()

Avoid clipped labels and display the chart.

plt.tight_layout()
plt.show()

#AI#chatroom#link
0

留言

暫時未有留言。