将日志值转换回numb

2024-10-01 17:37:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是FbProphet,我们应该将数据转换为orer中的日志值,以便像这样规范化数据:df['y'] = np.log(df['y'])但是一旦我预测了这些值,我就会得到这样的数据帧:

      ds        n_tickets   yhat
0 2018-02-17       2202  7.545468
1 2018-02-18       2449  7.703022
2 2018-02-19       2409  7.705301
3 2018-02-20       2364  7.675143
4 2018-02-21       2306  7.693359
5 2018-02-22       2492  7.728534
6 2018-02-23       2300  7.669022
7 2018-02-24       2359  7.534430
8 2018-02-25       2481  7.691983
9 2018-02-26       2446  7.694263

在这里,yhat是我的预测值,但它们是log值,n_tickets是我的实际值。所以,我需要把yhat转换回正常数来做比较。我想弄清楚,但弄糊涂了。在


Tags: 数据logdfnpds规范化tickets预测值
1条回答
网友
1楼 · 发布于 2024-10-01 17:37:58

根据Lambda提供的答案,完整的解决方案是:

from io import StringIO
import numpy as np
import pandas as pd

s = """
      ds        n_tickets   yhat
0 2018-02-17       2202  7.545468
1 2018-02-18       2449  7.703022
2 2018-02-19       2409  7.705301
3 2018-02-20       2364  7.675143
4 2018-02-21       2306  7.693359
5 2018-02-22       2492  7.728534
6 2018-02-23       2300  7.669022
7 2018-02-24       2359  7.534430
8 2018-02-25       2481  7.691983
9 2018-02-26       2446  7.694263
"""

# Load your example
df = pd.read_csv(StringIO(s), delim_whitespace=True)

# Add the exponential of the yhat column as a new column
df['exp_yhat'] = np.exp(df['yhat'])
print(df.head())

#            ds  n_tickets      yhat     exp_yhat
# 0  2018-02-17       2202  7.545468  1892.148056
# 1  2018-02-18       2449  7.703022  2215.031714
# 2  2018-02-19       2409  7.705301  2220.085527
# 3  2018-02-20       2364  7.675143  2154.131705
# 4  2018-02-21       2306  7.693359  2193.730943

相关问题 更多 >

    热门问题