Add rmse calculation for each result row

This commit is contained in:
Aleksey Filippov 2024-11-27 21:29:46 +04:00
parent 9779bf796c
commit 4ddb6e77a9
2 changed files with 260 additions and 115 deletions

File diff suppressed because one or more lines are too long

View File

@ -1287,12 +1287,13 @@
"sim.input[\"ti\"] = 0.0\n",
"sim.compute()\n",
"sim.print_state()\n",
"\n",
"display(sim.output[\"viscosity\"])"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 18,
"metadata": {},
"outputs": [
{
@ -1320,7 +1321,9 @@
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Viscosity</th>\n",
" <th>ViscosityPred</th>\n",
" <th>Real</th>\n",
" <th>Inferred</th>\n",
" <th>RMSE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
@ -1330,7 +1333,9 @@
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>3.707</td>\n",
" <td>3.707</td>\n",
" <td>3.499157</td>\n",
" <td>0.207843</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
@ -1338,7 +1343,9 @@
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>3.180</td>\n",
" <td>3.180</td>\n",
" <td>3.188565</td>\n",
" <td>0.008565</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
@ -1346,7 +1353,9 @@
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>2.361</td>\n",
" <td>2.361</td>\n",
" <td>2.732494</td>\n",
" <td>0.371494</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
@ -1354,7 +1363,9 @@
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.832</td>\n",
" <td>1.832</td>\n",
" <td>1.812498</td>\n",
" <td>0.019502</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
@ -1362,7 +1373,9 @@
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.629</td>\n",
" <td>1.629</td>\n",
" <td>1.812498</td>\n",
" <td>0.183498</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
@ -1370,7 +1383,9 @@
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.465</td>\n",
" <td>1.465</td>\n",
" <td>1.812498</td>\n",
" <td>0.347498</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
@ -1378,7 +1393,9 @@
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.194</td>\n",
" <td>1.194</td>\n",
" <td>1.390833</td>\n",
" <td>0.196833</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
@ -1386,7 +1403,9 @@
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>4.660</td>\n",
" <td>4.660</td>\n",
" <td>3.481064</td>\n",
" <td>1.178936</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
@ -1394,7 +1413,9 @@
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>3.380</td>\n",
" <td>3.380</td>\n",
" <td>3.090537</td>\n",
" <td>0.289463</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
@ -1402,7 +1423,9 @@
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>2.874</td>\n",
" <td>2.874</td>\n",
" <td>2.703435</td>\n",
" <td>0.170565</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
@ -1410,7 +1433,9 @@
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>2.489</td>\n",
" <td>2.489</td>\n",
" <td>2.365680</td>\n",
" <td>0.123320</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
@ -1418,7 +1443,9 @@
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.897</td>\n",
" <td>1.897</td>\n",
" <td>2.054459</td>\n",
" <td>0.157459</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
@ -1426,7 +1453,9 @@
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.709</td>\n",
" <td>1.709</td>\n",
" <td>2.128746</td>\n",
" <td>0.419746</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
@ -1434,7 +1463,9 @@
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.470</td>\n",
" <td>1.470</td>\n",
" <td>1.465795</td>\n",
" <td>0.004205</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
@ -1442,37 +1473,43 @@
" <td>0.30</td>\n",
" <td>0.0</td>\n",
" <td>6.670</td>\n",
" <td>6.670</td>\n",
" <td>3.499157</td>\n",
" <td>3.170843</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Viscosity ViscosityPred\n",
"0 20 0.00 0.0 3.707 3.499157\n",
"1 25 0.00 0.0 3.180 3.188565\n",
"2 35 0.00 0.0 2.361 2.732494\n",
"3 45 0.00 0.0 1.832 1.812498\n",
"4 50 0.00 0.0 1.629 1.812498\n",
"5 55 0.00 0.0 1.465 1.812498\n",
"6 70 0.00 0.0 1.194 1.390833\n",
"7 20 0.05 0.0 4.660 3.481064\n",
"8 30 0.05 0.0 3.380 3.090537\n",
"9 35 0.05 0.0 2.874 2.703435\n",
"10 40 0.05 0.0 2.489 2.365680\n",
"11 50 0.05 0.0 1.897 2.054459\n",
"12 55 0.05 0.0 1.709 2.128746\n",
"13 60 0.05 0.0 1.470 1.465795\n",
"14 20 0.30 0.0 6.670 3.499157"
" T Al2O3 TiO2 Viscosity Real Inferred RMSE\n",
"0 20 0.00 0.0 3.707 3.707 3.499157 0.207843\n",
"1 25 0.00 0.0 3.180 3.180 3.188565 0.008565\n",
"2 35 0.00 0.0 2.361 2.361 2.732494 0.371494\n",
"3 45 0.00 0.0 1.832 1.832 1.812498 0.019502\n",
"4 50 0.00 0.0 1.629 1.629 1.812498 0.183498\n",
"5 55 0.00 0.0 1.465 1.465 1.812498 0.347498\n",
"6 70 0.00 0.0 1.194 1.194 1.390833 0.196833\n",
"7 20 0.05 0.0 4.660 4.660 3.481064 1.178936\n",
"8 30 0.05 0.0 3.380 3.380 3.090537 0.289463\n",
"9 35 0.05 0.0 2.874 2.874 2.703435 0.170565\n",
"10 40 0.05 0.0 2.489 2.489 2.365680 0.123320\n",
"11 50 0.05 0.0 1.897 1.897 2.054459 0.157459\n",
"12 55 0.05 0.0 1.709 1.709 2.128746 0.419746\n",
"13 60 0.05 0.0 1.470 1.470 1.465795 0.004205\n",
"14 20 0.30 0.0 6.670 6.670 3.499157 3.170843"
]
},
"execution_count": 13,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn import metrics\n",
"import math\n",
"\n",
"\n",
"def fuzzy_pred(row):\n",
" sim.input[\"temp\"] = row[\"T\"]\n",
" sim.input[\"al\"] = row[\"Al2O3\"]\n",
@ -1480,14 +1517,19 @@
" sim.compute()\n",
" return sim.output[\"viscosity\"]\n",
"\n",
"def rmse(row):\n",
" return math.sqrt(metrics.mean_squared_error([row[\"Real\"]], [row[\"Inferred\"]]))\n",
"\n",
"result_train = viscosity_train.copy()\n",
"result_train[\"ViscosityPred\"] = result_train.apply(fuzzy_pred, axis=1)\n",
"result_train[\"Real\"] = result_train[\"Viscosity\"]\n",
"result_train[\"Inferred\"] = result_train.apply(fuzzy_pred, axis=1)\n",
"result_train[\"RMSE\"] = result_train.apply(rmse, axis=1)\n",
"result_train.head(15)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 19,
"metadata": {},
"outputs": [
{
@ -1515,7 +1557,9 @@
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Viscosity</th>\n",
" <th>ViscosityPred</th>\n",
" <th>Real</th>\n",
" <th>Inferred</th>\n",
" <th>RMSE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
@ -1525,7 +1569,9 @@
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>2.716</td>\n",
" <td>2.716</td>\n",
" <td>3.089540</td>\n",
" <td>0.374</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
@ -1533,7 +1579,9 @@
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>2.073</td>\n",
" <td>2.073</td>\n",
" <td>2.359522</td>\n",
" <td>0.287</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
@ -1541,7 +1589,9 @@
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>1.329</td>\n",
" <td>1.329</td>\n",
" <td>1.465795</td>\n",
" <td>0.137</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
@ -1549,7 +1599,9 @@
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>1.211</td>\n",
" <td>1.211</td>\n",
" <td>1.414928</td>\n",
" <td>0.204</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
@ -1557,7 +1609,9 @@
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>4.120</td>\n",
" <td>4.120</td>\n",
" <td>3.188565</td>\n",
" <td>0.931</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
@ -1565,7 +1619,9 @@
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>2.217</td>\n",
" <td>2.217</td>\n",
" <td>2.045546</td>\n",
" <td>0.171</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
@ -1573,7 +1629,9 @@
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.315</td>\n",
" <td>1.315</td>\n",
" <td>1.414928</td>\n",
" <td>0.100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
@ -1581,7 +1639,9 @@
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.105</td>\n",
" <td>1.105</td>\n",
" <td>1.408926</td>\n",
" <td>0.304</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
@ -1589,7 +1649,9 @@
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>3.111</td>\n",
" <td>3.111</td>\n",
" <td>3.499157</td>\n",
" <td>0.388</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
@ -1597,7 +1659,9 @@
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>2.735</td>\n",
" <td>2.735</td>\n",
" <td>3.475062</td>\n",
" <td>0.740</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
@ -1605,7 +1669,9 @@
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>1.936</td>\n",
" <td>1.936</td>\n",
" <td>1.812498</td>\n",
" <td>0.124</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
@ -1613,7 +1679,9 @@
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>3.587</td>\n",
" <td>3.587</td>\n",
" <td>3.111691</td>\n",
" <td>0.475</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
@ -1621,7 +1689,9 @@
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.953</td>\n",
" <td>1.953</td>\n",
" <td>2.128746</td>\n",
" <td>0.176</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
@ -1629,7 +1699,9 @@
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.443</td>\n",
" <td>1.443</td>\n",
" <td>1.414928</td>\n",
" <td>0.028</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
@ -1637,7 +1709,9 @@
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>3.990</td>\n",
" <td>3.990</td>\n",
" <td>3.475062</td>\n",
" <td>0.515</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
@ -1645,7 +1719,9 @@
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>3.189</td>\n",
" <td>3.189</td>\n",
" <td>3.475062</td>\n",
" <td>0.286</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
@ -1653,47 +1729,52 @@
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>2.287</td>\n",
" <td>2.287</td>\n",
" <td>1.812498</td>\n",
" <td>0.475</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Viscosity ViscosityPred\n",
"0 30 0.00 0.00 2.716 3.089540\n",
"1 40 0.00 0.00 2.073 2.359522\n",
"2 60 0.00 0.00 1.329 1.465795\n",
"3 65 0.00 0.00 1.211 1.414928\n",
"4 25 0.05 0.00 4.120 3.188565\n",
"5 45 0.05 0.00 2.217 2.045546\n",
"6 65 0.05 0.00 1.315 1.414928\n",
"7 70 0.05 0.00 1.105 1.408926\n",
"8 45 0.30 0.00 3.111 3.499157\n",
"9 50 0.30 0.00 2.735 3.475062\n",
"10 65 0.30 0.00 1.936 1.812498\n",
"11 30 0.00 0.05 3.587 3.111691\n",
"12 55 0.00 0.05 1.953 2.128746\n",
"13 65 0.00 0.05 1.443 1.414928\n",
"14 40 0.00 0.30 3.990 3.475062\n",
"15 50 0.00 0.30 3.189 3.475062\n",
"16 65 0.00 0.30 2.287 1.812498"
" T Al2O3 TiO2 Viscosity Real Inferred RMSE\n",
"0 30 0.00 0.00 2.716 2.716 3.089540 0.374\n",
"1 40 0.00 0.00 2.073 2.073 2.359522 0.287\n",
"2 60 0.00 0.00 1.329 1.329 1.465795 0.137\n",
"3 65 0.00 0.00 1.211 1.211 1.414928 0.204\n",
"4 25 0.05 0.00 4.120 4.120 3.188565 0.931\n",
"5 45 0.05 0.00 2.217 2.217 2.045546 0.171\n",
"6 65 0.05 0.00 1.315 1.315 1.414928 0.100\n",
"7 70 0.05 0.00 1.105 1.105 1.408926 0.304\n",
"8 45 0.30 0.00 3.111 3.111 3.499157 0.388\n",
"9 50 0.30 0.00 2.735 2.735 3.475062 0.740\n",
"10 65 0.30 0.00 1.936 1.936 1.812498 0.124\n",
"11 30 0.00 0.05 3.587 3.587 3.111691 0.475\n",
"12 55 0.00 0.05 1.953 1.953 2.128746 0.176\n",
"13 65 0.00 0.05 1.443 1.443 1.414928 0.028\n",
"14 40 0.00 0.30 3.990 3.990 3.475062 0.515\n",
"15 50 0.00 0.30 3.189 3.189 3.475062 0.286\n",
"16 65 0.00 0.30 2.287 2.287 1.812498 0.475"
]
},
"execution_count": 14,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result_test = viscosity_test.copy()\n",
"result_test[\"ViscosityPred\"] = result_test.apply(fuzzy_pred, axis=1)\n",
"result_test[\"Real\"] = result_test[\"Viscosity\"]\n",
"result_test[\"Inferred\"] = result_test.apply(fuzzy_pred, axis=1)\n",
"result_test[\"RMSE\"] = result_test.apply(rmse, axis=1)\n",
"result_test = result_test.round({\"RMSE\": 3})\n",
"result_test"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 17,
"metadata": {},
"outputs": [
{
@ -1705,29 +1786,25 @@
" 'R2_test': 0.813200460937507}"
]
},
"execution_count": 15,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"from sklearn import metrics\n",
"\n",
"\n",
"rmetrics = {}\n",
"rmetrics[\"RMSE_train\"] = math.sqrt(\n",
" metrics.mean_squared_error(result_train[\"Viscosity\"], result_train[\"ViscosityPred\"])\n",
" metrics.mean_squared_error(result_train[\"Real\"], result_train[\"Inferred\"])\n",
")\n",
"rmetrics[\"RMSE_test\"] = math.sqrt(\n",
" metrics.mean_squared_error(result_test[\"Viscosity\"], result_test[\"ViscosityPred\"])\n",
" metrics.mean_squared_error(result_test[\"Real\"], result_test[\"Inferred\"])\n",
")\n",
"rmetrics[\"RMAE_test\"] = math.sqrt(\n",
" metrics.mean_absolute_error(result_test[\"Viscosity\"], result_test[\"ViscosityPred\"])\n",
")\n",
"rmetrics[\"R2_test\"] = metrics.r2_score(\n",
" result_test[\"Viscosity\"], result_test[\"ViscosityPred\"]\n",
" metrics.mean_absolute_error(result_test[\"Real\"], result_test[\"Inferred\"])\n",
")\n",
"rmetrics[\"R2_test\"] = metrics.r2_score(result_test[\"Real\"], result_test[\"Inferred\"])\n",
"\n",
"rmetrics"
]