我被 ChatGPT + Code Interpreter 在数据分析上的能力彻底震撼了
我只问了像“tell me something interesting”这种模糊问题,它就立刻给出有洞察的 Treasury 数据图表——这些图我以前手工要花很久才能做出来。
本文写于2023年,部分内容可能已发生变化。
当 Ethan Mollick 写到 chatGPT with Code Interpreter 有多强时,我非常好奇。那时我在度假,直到今天才真正上手。结果,真的把我看傻了!
为了做测试,我用了 Treasury Direct 网站上这份美国国债不同证券发行数据。我选这个数据集,是因为我之前写过一篇 "Why You Shouldn’t Believe the Hype About the TreasuryDirect Website Being Outdated",对这份数据有些熟悉。更重要的是,我大概记得以前自己做这些图要花多久。
上传整份数据集极其简单
点一下按钮,我就能把完整数据集连同 data dictionary 一起上传。关于数据集我几乎没多解释,只贴了官网这段说明:"The Securities Issued in TreasuryDirect dataset details how many of each type of Treasury bonds are issued, redeemed, or outstanding in TreasuryDirect from Fiscal Year (FY) 2002 until present. Outstanding bonds refer to those which are still in circulation, and have not yet been redeemed. The number of outstanding Treasury bonds is determined by taking the difference between the numbers of Treasury bonds issued and redeemed. This dataset does not contain any information on the values or yields of the Treasury bonds."
我很喜欢的一点是:在我没额外提示的情况下,chatGPT 会先高层解释它如何理解这份数据,并展示前几行作为预览。
现在我可以开始和数据“对话”
Can you tell me something interesting about this dataset?
我问了一个很模糊的问题:“can you tell me something interesting about this dataset?” 这非常泛,因为我想测试 chatGPT 是否能直觉判断“人类可能关心什么”。
回复如下:
如你所见,chatGPT 很准确地猜到“总销售额随时间趋势”是我首先会关心的点。接着第二张图又把总销售按 security type 拆开。(如果你仔细看它的描述和图,会发现它把颜色说错了:“orange” 应该是 “darker blue”,不过这不算致命问题。)
接着我又问了另一个模糊问题 :P
"Based on this dataset, do you think that the website treasury direct is getting more popular?"
我很喜欢它的回答语气:“The popularity of the TreasuryDirect website could be inferred by examining the trends in sales and the number of transactions over time. If we see an increase in these metrics, it could suggest that more people are using the website to purchase Treasury bonds. However, it's important to note that this is a rough estimation and might not represent the full picture of the website's popularity, as there might be other factors at play.”
我喜欢这段,因为语气很克制。它明确告诉我自己并不确定,这只是多种可能解释之一。
这是它生成的图:
Iteration 是关键
上面这些图还不错,但不是我最终要发布的版本。所以我继续问它:“I want to include the chart about the number of transactions over time on my blog, can you reformat the chart so that it is easier to read?”
你可以看到它一步步优化:
First improvement
chatGPT 回我:
Absolutely, I can modify the chart to make it easier to read. Some changes that could improve the chart's readability include:
- Increasing the font size of the title, labels, and ticks.
- Adjusting the linewidth of the plot for better visibility.
- Adding a more descriptive title and labels.
- Making the gridlines lighter to avoid distraction.
图如下:
Second improvement
我注意到纵轴有点奇怪,就说:“for the vertical axis, I am not sure if my audience will understand what 1e6 means?”
它给出的结果是:
"Understandable, scientific notation can sometimes be confusing for a general audience. Instead, we can convert the y-axis labels to millions and add that information to the label. This way, the numbers will be more straightforward to understand. Let's make that adjustment."
Third revision
我继续反馈:“yes this graph is getting much better! I notice from the trend that the number of transactions increased significantly over the past few years. How do we show this better to my audience?”
chatGPT 回答:
"One common method for highlighting trends in data over time is to include a trend line in the graph. A trend line (also called a line of best fit) is a line that is used to represent the behavior of a group of data to see if there’s a certain pattern.
In the context of your data, adding a trend line can help visualize whether there's an overall increase in the number of transactions over time, despite any short-term fluctuations.
Let's add a trend line to the graph. We'll use a simple linear regression model to estimate the trend. We'll also include the equation of the trend line and the R-squared value (which measures how closely the data fit the regression line) in the graph's legend to provide more context for the audience."
虽然语气很自信,但你会发现图里其实没有红色趋势线。所以我继续反馈。
Forth revision
"I dont see the red line at all from the above chart"
chatGPT 回答:
"I apologize for the confusion. The red line representing the trend might not be visible due to the large fluctuations in the data. A trend line, especially for a linear regression model, may not adequately represent the data if there are large-scale fluctuations or if the trend is not linear.
An alternative way to highlight the trend could be to use a rolling mean (also known as a moving average). This technique averages out the fluctuations over a certain period to highlight the longer-term trend.
Let's apply a 12-month rolling mean to the data and plot it along with the original data. This should help us better visualize the overall trend."
"A rolling mean smooths out short-term fluctuations and highlights longer-term trends in data. In this case, it's calculated by averaging the number of transactions over 12-month periods.
The rolling mean line shows the general trend of the data despite the monthly fluctuations. As we can see, there's a clear upward trend in the number of transactions, which supports your observation that TreasuryDirect is becoming more popular."
很棒吗?是的。我并没有告诉它我要看 12 个月 rolling mean,但它主动建议了。说实话,我之前也没想到用这个方式去展示“过去几年相对过去 20 年”的结构变化。再次被震撼。
你也会注意到它的配色:趋势线刻意用更深色强调变化,这正是我想要的。
Final revision
虽然我已经很满意了,我又补了一句:“actually, one additional question, do we need the gridlines for the above chart? do you think we can simlify the chart further by eliminating the gridlines?”
它返回了这个:
看这个迭代过程,你可能会以为花了很久,但其实每一步真实耗时都不到 5-10 秒。比我自己手动画图快太多了!
我的图 vs chatGPT 图:直接对比
前面说过,我以前已用这份数据写过一篇博客,也自己做过几张图。现在我想直接比较:用 chatGPT 重做同类型图会快多少。
于是我输入:“can you generate a graph to show the trend of funded account at treasury direct from Jan 2016 to Feb 2023?”
先看我自己以前做的图:
如果我没记错,之前我做这张图花了超过 5-10 分钟。
而用 chatGPT,几秒就出来了(还附带 12 个月 rolling mean)。哪个版本更好你自己判断 :P
Conclusion
我真的被 chatGPT + code interpreter 在“当下”数据分析能力震撼到了,也很期待它后面还能进化到什么程度 :D
你日常最烦、最重复的数据任务是什么?你有试过直接丢给 Code Interpreter 吗?我很好奇它在你所在领域是否也同样有效。
致敬,
Chandler
















