numpy 将Log转换回原始值

xj3cbfub  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(152)

这里我把自变量转换为,因变量转换为,

mask = dtd['value_eur'] > 0  # Create a boolean mask for non-zero values
dtd['value_eur'] = np.log(dtk.loc[mask, 'value_eur'])  # Apply log only to non-zero values
mass = dtd['wage_eur'] > 0  # Create a boolean mask for non-zero values
dtd['wage_eur'] = np.log(dtk.loc[mask, 'wage_eur'])  # Apply log only to non-zero values

字符串
这是用于预测的X和y值

X = dtd.drop(['value_eur' ], axis=1)
y = dtd['value_eur']


这是我的模特试装

regressor =gs.best_estimator_

regressor.fit(X_train, y_train)
regs= regressor.predict(X_test)

mae3 = mean_absolute_error(y_test, regs)

print(f"Mean Absolute Error: {mae3}")


这里我打印了我的值

results1 = pd.DataFrame({ ' grids predicted values':(regs),  '  true values':y_test})

results1.head()
grids predicted values  true values
60199   15.665110   15.761421
23743   12.557003   12.765688
58428   15.386219   15.424948
34538   15.588066   15.226498
108229  14.202580   14.457364

的字符串
如何使上述值显示原始数据集中的原始值

np.exp(y_test)

gstyhher

gstyhher1#

你可以使用np.exp()函数来反转对数变换。如果这有效或者你需要进一步的帮助,请告诉我。

# Reverse the log transformation on the predicted values
predicted_values = np.exp(regs)

# Reverse the log transformation on the true values
true_values = np.exp(y_test)

# Calculate Mean Absolute Error
mae = mean_absolute_error(true_values, predicted_values)
print(f"Mean Absolute Error: {mae}")

# Create a DataFrame to print values
results = pd.DataFrame({'Predicted Values': predicted_values, 'True Values': true_values})
results.head()

字符串

相关问题