Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -157,10 +157,15 @@ add_password_gate()
|
|
| 157 |
def rmse(y_true, y_pred) -> float:
|
| 158 |
return float(np.sqrt(mean_squared_error(y_true, y_pred)))
|
| 159 |
|
| 160 |
-
def pearson_r(y_true, y_pred) -> float:
|
| 161 |
a = np.asarray(y_true, dtype=float)
|
| 162 |
p = np.asarray(y_pred, dtype=float)
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
return float(np.corrcoef(a, p)[0, 1])
|
| 165 |
|
| 166 |
@st.cache_resource(show_spinner=False)
|
|
|
|
| 157 |
def rmse(y_true, y_pred) -> float:
|
| 158 |
return float(np.sqrt(mean_squared_error(y_true, y_pred)))
|
| 159 |
|
| 160 |
+
def pearson_r(y_true, y_pred) -> float:
|
| 161 |
a = np.asarray(y_true, dtype=float)
|
| 162 |
p = np.asarray(y_pred, dtype=float)
|
| 163 |
+
|
| 164 |
+
# Check for constant arrays, where std dev would be zero.
|
| 165 |
+
# We must check both true and predicted arrays.
|
| 166 |
+
if a.size < 2 or np.all(a == a[0]) or np.all(p == p[0]):
|
| 167 |
+
return float("nan")
|
| 168 |
+
|
| 169 |
return float(np.corrcoef(a, p)[0, 1])
|
| 170 |
|
| 171 |
@st.cache_resource(show_spinner=False)
|