Untitled
unknown
python
9 months ago
1.1 kB
3
Indexable
import numpy as np
import pandas as pd
# Given data points for vapor temperature and pressure
data = {
"Temperature (°C)": [10.4, 20.3, 30.2, 39.5, 49.5, 60.9, 68.7, 78, 83, 90.3],
"Pressure (Pa)": [19, 29, 37, 71, 112, 155, 265, 369, 522, 753],
}
# Convert data to DataFrame
df = pd.DataFrame(data)
# Extract temperature and pressure
x = np.array(df["Temperature (°C)"])
y_actual = np.array(df["Pressure (Pa)"])
# Trendline equations
# Linear: y = 7.95x - 189
y_linear = 7.95 * x - 189
# Polynomial: y = 146 - 9.92x + 0.175x^2
y_poly = 146 - 9.92 * x + 0.175 * x ** 2
# Cubic: y = -70.7 + 10.3x - 0.298x^2 + 3.13e-3 * x^3
y_cubic = -70.7 + 10.3 * x - 0.298 * x ** 2 + 3.13e-3 * x ** 3
# Function to calculate RMSE
def calculate_rmse(actual, predicted):
return np.sqrt(np.mean((actual - predicted) ** 2))
# Calculate RMSE for each trendline
rmse_linear = calculate_rmse(y_actual, y_linear)
rmse_poly = calculate_rmse(y_actual, y_poly)
rmse_cubic = calculate_rmse(y_actual, y_cubic)
print(rmse_linear, rmse_poly, rmse_cubic)
Editor is loading...
Leave a Comment