2024-11-01 11:04:05 +04:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"|--- T <= 32.50\n",
"| |--- TiO2 <= 0.18\n",
"| | |--- Al2O3 <= 0.18\n",
"| | | |--- T <= 22.50\n",
"| | | | |--- TiO2 <= 0.03\n",
"| | | | | |--- Al2O3 <= 0.03\n",
"| | | | | | |--- value: [3.71]\n",
"| | | | | |--- Al2O3 > 0.03\n",
"| | | | | | |--- value: [4.66]\n",
"| | | | |--- TiO2 > 0.03\n",
"| | | | | |--- value: [4.88]\n",
"| | | |--- T > 22.50\n",
"| | | | |--- TiO2 <= 0.03\n",
"| | | | | |--- Al2O3 <= 0.03\n",
"| | | | | | |--- value: [3.18]\n",
"| | | | | |--- Al2O3 > 0.03\n",
"| | | | | | |--- value: [3.38]\n",
"| | | | |--- TiO2 > 0.03\n",
"| | | | | |--- value: [4.24]\n",
"| | |--- Al2O3 > 0.18\n",
"| | | |--- T <= 22.50\n",
"| | | | |--- value: [6.67]\n",
"| | | |--- T > 22.50\n",
"| | | | |--- T <= 27.50\n",
"| | | | | |--- value: [5.59]\n",
"| | | | |--- T > 27.50\n",
"| | | | | |--- value: [4.73]\n",
"| |--- TiO2 > 0.18\n",
"| | |--- T <= 22.50\n",
"| | | |--- value: [7.13]\n",
"| | |--- T > 22.50\n",
"| | | |--- T <= 27.50\n",
"| | | | |--- value: [5.87]\n",
"| | | |--- T > 27.50\n",
"| | | | |--- value: [4.94]\n",
"|--- T > 32.50\n",
"| |--- T <= 47.50\n",
"| | |--- TiO2 <= 0.18\n",
"| | | |--- Al2O3 <= 0.18\n",
"| | | | |--- T <= 42.50\n",
"| | | | | |--- TiO2 <= 0.03\n",
"| | | | | | |--- Al2O3 <= 0.03\n",
"| | | | | | | |--- value: [2.36]\n",
"| | | | | | |--- Al2O3 > 0.03\n",
"| | | | | | | |--- value: [2.68]\n",
"| | | | | |--- TiO2 > 0.03\n",
"| | | | | | |--- T <= 37.50\n",
"| | | | | | | |--- value: [3.12]\n",
"| | | | | | |--- T > 37.50\n",
"| | | | | | | |--- value: [2.65]\n",
"| | | | |--- T > 42.50\n",
"| | | | | |--- TiO2 <= 0.03\n",
"| | | | | | |--- value: [1.83]\n",
"| | | | | |--- TiO2 > 0.03\n",
"| | | | | | |--- value: [2.40]\n",
"| | | |--- Al2O3 > 0.18\n",
"| | | | |--- T <= 37.50\n",
"| | | | | |--- value: [4.12]\n",
"| | | | |--- T > 37.50\n",
"| | | | | |--- value: [3.56]\n",
"| | |--- TiO2 > 0.18\n",
"| | | |--- T <= 40.00\n",
"| | | | |--- value: [4.35]\n",
"| | | |--- T > 40.00\n",
"| | | | |--- value: [3.56]\n",
"| |--- T > 47.50\n",
"| | |--- TiO2 <= 0.18\n",
"| | | |--- Al2O3 <= 0.18\n",
"| | | | |--- T <= 52.50\n",
"| | | | | |--- TiO2 <= 0.03\n",
"| | | | | | |--- Al2O3 <= 0.03\n",
"| | | | | | | |--- value: [1.63]\n",
"| | | | | | |--- Al2O3 > 0.03\n",
"| | | | | | | |--- value: [1.90]\n",
"| | | | | |--- TiO2 > 0.03\n",
"| | | | | | |--- value: [2.11]\n",
"| | | | |--- T > 52.50\n",
"| | | | | |--- T <= 65.00\n",
"| | | | | | |--- TiO2 <= 0.03\n",
"| | | | | | | |--- value: [1.55]\n",
"| | | | | | |--- TiO2 > 0.03\n",
"| | | | | | | |--- value: [1.66]\n",
"| | | | | |--- T > 65.00\n",
"| | | | | | |--- TiO2 <= 0.03\n",
"| | | | | | | |--- value: [1.19]\n",
"| | | | | | |--- TiO2 > 0.03\n",
"| | | | | | | |--- value: [1.29]\n",
"| | | |--- Al2O3 > 0.18\n",
"| | | | |--- T <= 65.00\n",
"| | | | | |--- T <= 57.50\n",
"| | | | | | |--- value: [2.43]\n",
"| | | | | |--- T > 57.50\n",
"| | | | | | |--- value: [2.16]\n",
"| | | | |--- T > 65.00\n",
"| | | | | |--- value: [1.73]\n",
"| | |--- TiO2 > 0.18\n",
"| | | |--- T <= 65.00\n",
"| | | | |--- T <= 57.50\n",
"| | | | | |--- value: [2.84]\n",
"| | | | |--- T > 57.50\n",
"| | | | | |--- value: [2.54]\n",
"| | | |--- T > 65.00\n",
"| | | | |--- value: [1.91]\n",
"\n"
]
}
],
"source": [
"import pickle\n",
"import pandas as pd\n",
"from sklearn import tree\n",
"\n",
"model = pickle.load(open(\"data/vtree.model.sav\", \"rb\"))\n",
"features = (\n",
" pd.read_csv(\"data/viscosity_train.csv\", sep=\";\", decimal=\",\")\n",
" .drop([\"Viscosity\"], axis=1)\n",
" .columns.values.tolist()\n",
")\n",
"\n",
"rules = tree.export_text(model, feature_names=features)\n",
"print(rules)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"35"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 52.5) and (T > 65.0) and (TiO2 <= 0.025) -> 1.194,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 52.5) and (T > 65.0) and (TiO2 > 0.025) -> 1.289,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 52.5) and (T <= 65.0) and (TiO2 <= 0.025) -> 1.548,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 52.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) -> 1.629,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 52.5) and (T <= 65.0) and (TiO2 > 0.025) -> 1.662,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) and (T > 65.0) -> 1.728,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 42.5) and (TiO2 <= 0.025) -> 1.832,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 52.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) -> 1.897,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 > 0.175) and (T > 65.0) -> 1.91,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 52.5) and (TiO2 > 0.025) -> 2.109,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) and (T <= 65.0) and (T > 57.5) -> 2.16,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 42.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) -> 2.361,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 42.5) and (TiO2 > 0.025) -> 2.402,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) and (T <= 65.0) and (T <= 57.5) -> 2.426,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 > 0.175) and (T <= 65.0) and (T > 57.5) -> 2.538,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 42.5) and (TiO2 > 0.025) and (T > 37.5) -> 2.655,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 42.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) -> 2.682,\n",
" if (T > 32.5) and (T > 47.5) and (TiO2 > 0.175) and (T <= 65.0) and (T <= 57.5) -> 2.838,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 42.5) and (TiO2 > 0.025) and (T <= 37.5) -> 3.121,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 22.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) -> 3.18,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 22.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) -> 3.38,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 > 0.175) and (T > 40.0) -> 3.561,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) and (T > 37.5) -> 3.565,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 22.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) -> 3.707,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) and (T <= 37.5) -> 4.118,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T > 22.5) and (TiO2 > 0.025) -> 4.236,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 > 0.175) and (T <= 40.0) -> 4.354,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 22.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) -> 4.66,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) and (T > 22.5) and (T > 27.5) -> 4.731,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (T <= 22.5) and (TiO2 > 0.025) -> 4.885,\n",
" if (T <= 32.5) and (TiO2 > 0.175) and (T > 22.5) and (T > 27.5) -> 4.944,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) and (T > 22.5) and (T <= 27.5) -> 5.594,\n",
" if (T <= 32.5) and (TiO2 > 0.175) and (T > 22.5) and (T <= 27.5) -> 5.865,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) and (T <= 22.5) -> 6.67,\n",
" if (T <= 32.5) and (TiO2 > 0.175) and (T <= 22.5) -> 7.132]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from src.rules import get_rules\n",
"\n",
"\n",
"rules = get_rules(model, features)\n",
"display(len(rules))\n",
"rules"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"35"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.194,\n",
" if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 1.289,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.548,\n",
" if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.629,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 1.662,\n",
" if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 1.728,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.832,\n",
" if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 1.897,\n",
" if (T > 32.5) and (TiO2 > 0.175) -> 1.91,\n",
" if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 2.109,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 2.16,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 2.361,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 2.402,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 2.426,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 > 0.175) -> 2.538,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 2.655,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 2.682,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 > 0.175) -> 2.838,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 3.121,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 3.18,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 3.38,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 > 0.175) -> 3.561,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 3.565,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 3.707,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 4.118,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 4.236,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 > 0.175) -> 4.354,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 4.66,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 4.731,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 4.885,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 > 0.175) -> 4.944,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 5.594,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 > 0.175) -> 5.865,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 6.67,\n",
" if (T <= 32.5) and (TiO2 > 0.175) -> 7.132]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from src.rules import normalise_rules\n",
"\n",
"\n",
"rules = normalise_rules(rules)\n",
"display(len(rules))\n",
"rules"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"26"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.194,\n",
" if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 1.289,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.548,\n",
" if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.629,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 1.662,\n",
" if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 1.728,\n",
" if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 1.897,\n",
" if (T > 32.5) and (TiO2 > 0.175) -> 1.91,\n",
" if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 2.109,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 2.097,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 2.293,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 2.682,\n",
" if (T > 32.5) and (T <= 65.0) and (TiO2 > 0.175) -> 2.688,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 2.726,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 3.18,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 3.38,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 3.707,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 3.842,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 4.236,\n",
" if (T > 32.5) and (T <= 47.5) and (TiO2 > 0.175) -> 3.958,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 4.66,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 4.885,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 5.162,\n",
" if (T <= 32.5) and (T > 22.5) and (TiO2 > 0.175) -> 5.405,\n",
" if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 6.67,\n",
" if (T <= 32.5) and (TiO2 > 0.175) -> 7.132]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from src.rules import delete_same_rules\n",
"\n",
"\n",
"rules = delete_same_rules(rules)\n",
"display(len(rules))\n",
"rules"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['(Al2O3 <= 0.175)', '(Al2O3 > 0.025)', '(Al2O3 > 0.175)', '(TiO2 <= 0.175)', '(TiO2 > 0.025)', '(TiO2 > 0.175)']\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>(Al2O3 <= 0.175)</th>\n",
" <th>(Al2O3 > 0.025)</th>\n",
" <th>(Al2O3 > 0.175)</th>\n",
" <th>(TiO2 <= 0.175)</th>\n",
" <th>(TiO2 > 0.025)</th>\n",
" <th>(TiO2 > 0.175)</th>\n",
" <th>consequent</th>\n",
" </tr>\n",
" <tr>\n",
" <th>rule</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.194</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1.194</td>\n",
" </tr>\n",
" <tr>\n",
" <th>if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 1.289</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1.289</td>\n",
" </tr>\n",
" <tr>\n",
" <th>if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.548</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1.548</td>\n",
" </tr>\n",
" <tr>\n",
" <th>if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.629</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1.629</td>\n",
" </tr>\n",
" <tr>\n",
" <th>if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 1.662</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1.662</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" (Al2O3 <= 0.175) \\\n",
"rule \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <=... 1 \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0... 1 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 1 \n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.17... 1 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 1 \n",
"\n",
" (Al2O3 > 0.025) \\\n",
"rule \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <=... 0 \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0... 0 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 0 \n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.17... 0 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 0 \n",
"\n",
" (Al2O3 > 0.175) \\\n",
"rule \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <=... 0 \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0... 0 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 0 \n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.17... 0 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 0 \n",
"\n",
" (TiO2 <= 0.175) \\\n",
"rule \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <=... 1 \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0... 1 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 1 \n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.17... 1 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 1 \n",
"\n",
" (TiO2 > 0.025) \\\n",
"rule \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <=... 0 \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0... 1 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 0 \n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.17... 0 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 1 \n",
"\n",
" (TiO2 > 0.175) consequent \n",
"rule \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <=... 0 1.194 \n",
"if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0... 0 1.289 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 0 1.548 \n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.17... 0 1.629 \n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.17... 0 1.662 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from src.rules import get_features, vectorize_rules\n",
"\n",
"features = get_features(rules, [\"T\"])\n",
"print(features)\n",
"\n",
"df_rules = vectorize_rules(rules, features)\n",
"df_rules.head(5)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\user\\Projects\\python\\fuzzy\\.venv\\Lib\\site-packages\\sklearn\\base.py:1473: ConvergenceWarning: Number of distinct clusters (5) found smaller than n_clusters (6). Possibly due to duplicate points in X.\n",
" return fit_method(estimator, *args, **kwargs)\n"
]
},
{
"data": {
"text/plain": [
"{2: 0.42601604060235754,\n",
" 3: 0.7018993361356377,\n",
" 4: 0.8249121250065079,\n",
" 5: 1.0,\n",
2024-11-15 10:58:51 +04:00
" 6: 1.0}"
2024-11-01 11:04:05 +04:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2024-11-15 10:58:51 +04:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAGFCAYAAAAYU4NfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABDaUlEQVR4nO3deXhM1/8H8PckkUmQBZGICCFBbEk0JEL9ohVSVC211RZRWooiFNFWhFb4Ko22iF1rqZTSam3VoKW22mon9i2LLYuoRGbO74/bDCOLmSxzJ5P363nm6Z075+Z+ZujbzblnzlEIIQSIiMgkmcldABERlRyGPBGRCWPIExGZMIY8EZEJY8gTEZkwhjwRkQljyBMRmTCGPBGRCWPIExGZMIY86WTPnj1QKBTYsGGD3KVoDBo0CG5ublr7FAoFpk6dqnk+depUKBQK3Lt3z7DFERkJhnwZplAodHrs2bPHoHXdvXsXo0ePhqenJ6ytreHo6Ag/Pz9MnDgRjx49MmgthvD48WNMnTo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KpFLVq1RK9evUScXFxBdZw8uRJ8dFHH4lXXnlFVK5cWVhYWAhnZ2fRs2dPcezYMa22+gyhvHv3rla7FStWCADi6tWrmn1Pnz4VkZGRonbt2qJcuXLC1dVVhIeHiydPnmgdq1KpxMSJE4WDg4MoX768CA4OFpcuXco1hFIIIdLT00V4eLjw8PAQlpaWwsHBQbRs2VJ88cUXIisrS9Nu//79wtfXV1h
2024-11-01 11:04:05 +04:00
"text/plain": [
"<Figure size 400x400 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'The best clusters count is 5'"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from src.cluster_helper import draw_best_clusters_plot, get_best_clusters_num\n",
"\n",
"random_state = 9\n",
"\n",
"X = df_rules.copy()\n",
"X = X.drop([\"consequent\"], axis=1)\n",
"\n",
"clusters_score = get_best_clusters_num(X, random_state)\n",
"display(clusters_score)\n",
"\n",
"draw_best_clusters_plot(clusters_score)\n",
"\n",
"clusters_num = sorted(clusters_score.items(), key=lambda x: x[1], reverse=True)[0][0]\n",
"display(f\"The best clusters count is {clusters_num}\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Кластер 1 (6):\n",
"if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.194;\n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.548;\n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 1.629;\n",
"if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 2.097;\n",
"if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 3.18;\n",
"if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) -> 3.707\n",
"--------\n",
"Кластер 2 (5):\n",
"if (T > 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 1.728;\n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 2.293;\n",
"if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 3.842;\n",
"if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 5.162;\n",
"if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 > 0.175) -> 6.67\n",
"--------\n",
"Кластер 3 (5):\n",
"if (T > 32.5) and (TiO2 > 0.175) -> 1.91;\n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 > 0.175) -> 2.688;\n",
"if (T > 32.5) and (T <= 47.5) and (TiO2 > 0.175) -> 3.958;\n",
"if (T <= 32.5) and (T > 22.5) and (TiO2 > 0.175) -> 5.405;\n",
"if (T <= 32.5) and (TiO2 > 0.175) -> 7.132\n",
"--------\n",
"Кластер 4 (6):\n",
"if (T > 32.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 1.289;\n",
"if (T > 32.5) and (T <= 65.0) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 1.662;\n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 2.109;\n",
"if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 2.726;\n",
"if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 4.236;\n",
"if (T <= 32.5) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (Al2O3 <= 0.175) -> 4.885\n",
"--------\n",
"Кластер 5 (4):\n",
"if (T > 32.5) and (T <= 52.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 1.897;\n",
"if (T > 32.5) and (T <= 47.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 2.682;\n",
"if (T <= 32.5) and (T > 22.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 3.38;\n",
"if (T <= 32.5) and (TiO2 <= 0.175) and (Al2O3 <= 0.175) and (Al2O3 > 0.025) -> 4.66\n",
"--------\n"
]
}
],
"source": [
"from sklearn import cluster\n",
"\n",
"from src.cluster_helper import print_cluster_result\n",
"\n",
"kmeans = cluster.KMeans(n_clusters=clusters_num, random_state=random_state)\n",
"kmeans.fit(X)\n",
"\n",
"print_cluster_result(X, clusters_num, kmeans.labels_)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>T</th>\n",
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Viscosity</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>20</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>3.707</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>25</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>3.180</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>35</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>2.361</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Viscosity\n",
"0 20 0.0 0.0 3.707\n",
"1 25 0.0 0.0 3.180\n",
"2 35 0.0 0.0 2.361"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>T</th>\n",
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Viscosity</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>30</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>2.716</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>40</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>2.073</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>60</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.329</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Viscosity\n",
"0 30 0.0 0.0 2.716\n",
"1 40 0.0 0.0 2.073\n",
"2 60 0.0 0.0 1.329"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"viscosity_train = pd.read_csv(\"data/viscosity_train.csv\", sep=\";\", decimal=\",\")\n",
"viscosity_test = pd.read_csv(\"data/viscosity_test.csv\", sep=\";\", decimal=\",\")\n",
"\n",
"display(viscosity_train.head(3))\n",
"display(viscosity_test.head(3))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[if (T = 70) and (TiO2 = 0.0) and (Al2O3 = 0.0) -> 1.194,\n",
" if (T = 48.75) and (TiO2 = 0.0) and (Al2O3 = 0.0) -> 1.548,\n",
" if (T = 42.5) and (TiO2 = 0.0) and (Al2O3 = 0.0) -> 1.629,\n",
" if (T = 40.0) and (TiO2 = 0.0) and (Al2O3 = 0.0) -> 2.097,\n",
" if (T = 27.5) and (TiO2 = 0.0) and (Al2O3 = 0.0) -> 3.18,\n",
" if (T = 20) and (TiO2 = 0.0) and (Al2O3 = 0.0) -> 3.707],\n",
" [if (T = 70) and (TiO2 = 0.0) and (Al2O3 = 0.3) -> 1.728,\n",
" if (T = 48.75) and (TiO2 = 0.0) and (Al2O3 = 0.3) -> 2.293,\n",
" if (T = 40.0) and (TiO2 = 0.0) and (Al2O3 = 0.3) -> 3.842,\n",
" if (T = 27.5) and (TiO2 = 0.0) and (Al2O3 = 0.3) -> 5.162,\n",
" if (T = 20) and (TiO2 = 0.0) and (Al2O3 = 0.3) -> 6.67],\n",
" [if (T = 70) and (TiO2 = 0.3) -> 1.91,\n",
" if (T = 48.75) and (TiO2 = 0.3) -> 2.688,\n",
" if (T = 40.0) and (TiO2 = 0.3) -> 3.958,\n",
" if (T = 27.5) and (TiO2 = 0.3) -> 5.405,\n",
" if (T = 20) and (TiO2 = 0.3) -> 7.132],\n",
" [if (T = 70) and (TiO2 = 0.1) and (Al2O3 = 0.0) -> 1.289,\n",
" if (T = 48.75) and (TiO2 = 0.1) and (Al2O3 = 0.0) -> 1.662,\n",
" if (T = 42.5) and (TiO2 = 0.1) and (Al2O3 = 0.0) -> 2.109,\n",
" if (T = 40.0) and (TiO2 = 0.1) and (Al2O3 = 0.0) -> 2.726,\n",
" if (T = 27.5) and (TiO2 = 0.1) and (Al2O3 = 0.0) -> 4.236,\n",
" if (T = 20) and (TiO2 = 0.1) and (Al2O3 = 0.0) -> 4.885],\n",
" [if (T = 42.5) and (TiO2 = 0.0) and (Al2O3 = 0.1) -> 1.897,\n",
" if (T = 40.0) and (TiO2 = 0.0) and (Al2O3 = 0.1) -> 2.682,\n",
" if (T = 27.5) and (TiO2 = 0.0) and (Al2O3 = 0.1) -> 3.38,\n",
" if (T = 20) and (TiO2 = 0.0) and (Al2O3 = 0.1) -> 4.66]]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from src.rules import simplify_and_group_rules\n",
"\n",
"clustered_rules = simplify_and_group_rules(\n",
" viscosity_train, rules, clusters_num, kmeans.labels_\n",
")\n",
"clustered_rules"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\user\\Projects\\python\\fuzzy\\.venv\\Lib\\site-packages\\skfuzzy\\control\\fuzzyvariable.py:125: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown\n",
" fig.show()\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAAGyCAYAAAAMKHu5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAC2L0lEQVR4nOzdeXxU9b3/8ddsmckyk30ne9gSElZBdpAlCQQX7rWttdXaam8Xb7Vef1qvVttatfd2vbfLtVqr7a1tbXuBKpBJAAnIIpAgWwiQCVkgJJnsM9kmk5n5/RFDDQTIMjNnlu/z8cijZZZz3uE45JPv53y/X5nD4XAgCIIgCILgR+RSBxAEQRAEQXA3UQAJgiAIguB3RAEkCIIgCILfEQWQIAiCIAh+RxRAgiAIgiD4HVEACYIgCILgd0QBJAiCIAiC3xEFkCAIgiAIfkcUQIIgCIIg+B2/K4AcDgcmkwmxALYgCIIg+C9JC6D9+/ezadMmEhISkMlkbNu27ZbvKS0tZd68eajVajIzM3nrrbfGdU6z2UxoaChms3lioQVBEARB8HqSFkA9PT3Mnj2bX/7yl2N6fU1NDRs3bmT16tWcOH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bXRkb49Xt/3UpIQAjxwfFibzBB8FAdTT20NXSTucA9LWdRAF2jMDeBD6pa6ewVe/wIgqcxdBoIUASQrE2e0PszwzK5ZL5E/2C/k5MJgjBZVWVGAjQKkrMj3HI+UQBdoyAnDrvDQYlogwmCR3E4HBg6DaTp0lDKJzY7JCMsA4fDQU1XjZPTCYIwWYZyI2mzo1GqXN/+AlEAXSdGq2FRWiTviTaYIHiU9v5
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGyCAYAAAAYveVYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACGwklEQVR4nOzdd1gU59rH8e/SQQVBFCwo9g52VKyxxm5iOcZE06MxxhorggW7JibRaDTJMd2oiVhjLLEilliwYUexgRVQkLr7/jHv4RxjCWXh2XJ/zrXXicvszG9HZr13npnn1hkMBgNCCCGEEBbCRnUAIYQQQghjkuJGCCGEEBZFihshhBBCWBQpboQQQghhUaS4EUIIIYRFkeJGCCGEEBZFihshhBBCWBQpboQQQghhUaS4EUIIIYRFsbrixmAwkJiYiEzMLIQQQlgmpcXN7t276dq1K6VKlUKn0xEWFvaPr9m5cyf16tXD0dGRSpUqsXz58hxt88GDB7i5ufHgwYPchRZCCCGESVNa3CQlJeHv78+iRYuytXx0dDSdO3emdevWHDt2jOHDh/P222/zxx9/5HNSIYQQQpgLnak0ztTpdKxZs4YePXo8c5mxY8eyceNGTp48mfXcv/71L+Lj49m8eXO2tpOYmIibmxsJCQm4urrmNbYQQgghCoDBYECn02VrWbO65iYiIoK2bds+9lyHDh2IiIh45mtSU1NJTEx87AHwICU9X7MKIYQQwnjWXlyb7WXNqriJjY3Fy8vrsee8vLxITEzk0aNHT33NzJkzcXNzy3r4+Pg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2n16pOI4RJydRnEhQehIeTB6MajFIdR4obY+tRpzT
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGyCAYAAAAYveVYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACGqklEQVR4nOzdd1gU59rH8e/SQQFBFCwo9g52VKyxxm5iOcZETdcYY40VwYJdE2s0MckxPZZErDGWWBFLLNiwo9jACqhI3/ePeQ/nGBtl4dlyf86114nL7MxvR2a9d56Z59bp9Xo9QgghhBBmwkp1ACGEEEIIQ5LiRgghhBBmRYobIYQQQpgVKW6EEEIIYVakuBFCCCGEWZHiRgghhBBmRYobIYQQQpgVKW6EEEIIYVakuBFCCCGEWbG44kav15OQkIBMzCyEEEKYJ6XFze7du+nUqRPFixdHp9MRGhr60tfs3LmT2rVrY29vT/ny5Vm+fHm2tvngwQNcXV158OBBzkILIYQQwqgpLW4ePXqEn58fixcvztLyUVFRdOjQgRYtWnDs2DGGDh3Ke++9x59//pnHSYUQQghhKnTG0jhTp9OxZs0aunbt+txlRo8ezcaNGzl58mTmc//617+Ii4tj8+bNWdpOQkICrq6uxMfH4+LiktvYQgghhMgHer0enU6XpWVN6pqb8PBwWrVq9cRzbdu2JTw8/LmvSU5OJiEh4YkHwIOk1DzNKoQQQgjDWXtxbZaXNaniJiYmBk9Pzyee8/T0JCEhgcePHz/zNdOnT8fV1TXz4e3tDcCcP8/meV4hhBBC5F7MoxhmHpyZ5eVNqrjJibFjxxIfH5/5uHr1KgC/HbnOjrO3FKcTQgghxIvo9XqCwoJwsnXK8mtMqrjx8vIiNjb2iediY2NxcXHB0dHxma+xt7fHxcXliQdAo/KFGfPbceITZXhKCCGEMFarzq0i/GY4kxtNzvJrTKq4adiwId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1OUQwozcS7rH5PDJtPBuQaeynfJlm1Lc5EBFT2dGtKnI13ujOHT5nuo4Qpg2vR42DAN9BnSal//DUf9UtAq8Egjhi+FKuNosQpg4vV5PyP4QMvQZBDUMyvPhqP+Q4iaH3mtSltql3Bi5KoLEFJn8S4gcO/kbRK6Djp9BwaKq02gafgze9bVO5CnSPFeInPoj6g+2XtlKYINAPBw98m27UtzkkLWVjjk9/IhNSGLGH2dUxxHCNCXchI0joPrrUK2b6jT/ZWWttXx4EANbg1WnEcIk3U68zdQDU3nV51Xa+rTN121LcZMLZTwKMKZdZb4Pv0LYhTuq4whhWvR6WD9Euw27/RzVaZ5WuBy0ngSHlsHFHarTCGFS9Ho9E8MnYmdtxzj/cfm+fSlucqlvQx8ali3MqNXHSUhKVR1HCNNx9Ec4/yd0mg9O7qrTPFu997UWEGs/hqR41WmEMBmhF0LZfW03wQ2DKeRQKN+3L8VNLllZ6ZjV3Ze4xBRCNpxWHUcI0xAXDZvHQs0+UOlV1Wmez8pKawGRFAd/5v+3TyFM0c2HN5l5aCZdynWhuXdzJRmkuDEAb3cnJnSsysq/r/HXmVjVcYQwbhkZ2pkQB1doN111mpdzKw1tp2lnms5uVp1GCKOWoc8gaF8QznbOjK4/WlkOKW4MpFc9b5pXKsLo304Qlyi9aYR4rr+/gahd0GWhVuCYgtp9oXxrWP8JJMr0D0I8z8qzK9l/cz+TGk3C2c5ZWQ4pbgxEp9Mx4zVfklPTCV53SnUcIYzT3YuwNQjqvgPlXlGdJut0Oui8ANKSYNOnqtMIYZSuJlzls8Of0bNiTxoVb6Q0ixQ3BuTl6sCkLtVYe+wGf5y4qTqOEMYlIx3WDoICRaD1FNVpss+lOLw6G06uhtNrVacRwqikZ6QTGBaIu4M7I+qOUB1HihtD61qzBG2qejI
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGyCAYAAAAYveVYAAA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1Cc8eS1CB9hp79V/fTZROlSH9kMRQjCwpCm58/quN1hYV07duHvavbs4EJHlFdbkKpkpM2O/rOB49AJDcfuTcvEduAg52VzVKHIoxHxWbIXg+a209ZD8l5AOxW17Jwwe8Yag2smLKCEFXIqI4vSC/A5rCx58oeD0cmeIJ5ezFhK1ciDw0d1fE6fQFOq5WuPWK8/VF1uYm02dGog8ZXkgKR3AxJighmQVokH4i9pvzP9RpoPD26ktSgiBSYcpfYa8oP1ZvrqWyrHLZx30gSQhOYGztX7DXlh2x1dfSdPz+qktQgVXIywXPmiIZ+fqjD1ENLvYWsBeMvSYFIbm5w7+xE9l5qobNXlKb8SsUWUIVC9uj/2AGuZKh6F/S2eyYuwSNKjCUEK4NZMWXFmM7TZ+g5eO0gZpsoRfoTc7EBWUgIYSvHNt66DYV079+P3SzG259Ul5tQahQTKkmBSG5ucG9eIgMOJ6UVTVKHIoxFxRaYrgf16EoUQ3IeAMcAXNjukbAEzzAYDeRPySdYGTym89alrcPusLO7freHIhM8wVxcjDY/H3nw2MZbq9fj7O/HsluMtz+pPm4iY3Y0KrViQtcRyc3HxOuCWJQexTZRmvIfLZeg+dzwe0ndiS4R0paI0pQfudx5mUvtl8ZUkhoUFxLH/Pj5YtWUH7Fevoz14sXbNu4biSo+nuAFC0Rpyo+0N3VzvaGLrAmskhokkpubbMxL5GB1K+3dNqlDEUajYjOota7+NuOR+yBcLoOeNreGJXhGibGEUFUoy6Y
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"from skfuzzy import control as ctrl\n",
"import skfuzzy as fuzz\n",
"\n",
"temp = ctrl.Antecedent(viscosity_train[\"T\"].sort_values().unique(), \"temp\")\n",
"al = ctrl.Antecedent(np.arange(0, 0.3, 0.005), \"al\")\n",
"ti = ctrl.Antecedent(np.arange(0, 0.3, 0.005), \"ti\")\n",
"viscosity = ctrl.Consequent(np.arange(1.18, 3.71, 0.00001), \"viscosity\")\n",
"\n",
"temp.automf(5, variable_type=\"quant\")\n",
"temp.view()\n",
"al.automf(3, variable_type=\"quant\")\n",
"al.view()\n",
"ti.automf(3, variable_type=\"quant\")\n",
"ti.view()\n",
"viscosity.automf(5, variable_type=\"quant\")\n",
"viscosity.view()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"19"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[IF (temp[higher] AND ti[low]) AND al[low] THEN viscosity[lower]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[average] AND ti[low]) AND al[low] THEN viscosity[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND ti[low]) AND al[low] THEN viscosity[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[lower] AND ti[low]) AND al[low] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[higher] AND ti[low]) AND al[high] THEN viscosity[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[average] AND ti[low]) AND al[high] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND ti[low]) AND al[high] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[lower] AND ti[low]) AND al[high] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF temp[higher] AND ti[high] THEN viscosity[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF temp[average] AND ti[high] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF temp[low] AND ti[high] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF temp[lower] AND ti[high] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[higher] AND ti[average]) AND al[low] THEN viscosity[lower]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[average] AND ti[average]) AND al[low] THEN viscosity[average]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND ti[average]) AND al[low] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[lower] AND ti[average]) AND al[low] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[average] AND ti[low]) AND al[average] THEN viscosity[average]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND ti[low]) AND al[average] THEN viscosity[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[lower] AND ti[low]) AND al[average] THEN viscosity[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from src.rules import get_fuzzy_rules\n",
"\n",
"fuzzy_variables = {\"Al2O3\": al, \"TiO2\": ti, \"T\": temp, \"consequent\": viscosity}\n",
"fuzzy_rules = get_fuzzy_rules(clustered_rules, fuzzy_variables)\n",
"\n",
"fuzzy_cntrl = ctrl.ControlSystem(fuzzy_rules)\n",
"\n",
"sim = ctrl.ControlSystemSimulation(fuzzy_cntrl, lenient=False)\n",
"\n",
"display(len(fuzzy_rules))\n",
"fuzzy_rules"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=============\n",
" Antecedents \n",
"=============\n",
"Antecedent: temp = 20\n",
" - lower : 1.0\n",
" - low : 0.0\n",
" - average : 0.0\n",
" - high : 0.0\n",
" - higher : 0.0\n",
"Antecedent: ti = 0.0\n",
" - low : 1.0\n",
" - average : 0.0\n",
" - high : 0.0\n",
"Antecedent: al = 0.0\n",
" - low : 1.0\n",
" - average : 0.0\n",
" - high : 0.0\n",
"\n",
"=======\n",
" Rules \n",
"=======\n",
"RULE #0:\n",
" IF (temp[higher] AND ti[low]) AND al[low] THEN viscosity[lower]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[higher] : 0.0\n",
" - ti[low] : 1.0\n",
" - al[low] : 1.0\n",
" (temp[higher] AND ti[low]) AND al[low] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[lower] : 0.0\n",
"\n",
"RULE #1:\n",
" IF (temp[average] AND ti[low]) AND al[low] THEN viscosity[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - ti[low] : 1.0\n",
" - al[low] : 1.0\n",
" (temp[average] AND ti[low]) AND al[low] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[low] : 0.0\n",
"\n",
"RULE #2:\n",
" IF (temp[low] AND ti[low]) AND al[low] THEN viscosity[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 0.0\n",
" - ti[low] : 1.0\n",
" - al[low] : 1.0\n",
" (temp[low] AND ti[low]) AND al[low] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[high] : 0.0\n",
"\n",
"RULE #3:\n",
" IF (temp[lower] AND ti[low]) AND al[low] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[lower] : 1.0\n",
" - ti[low] : 1.0\n",
" - al[low] : 1.0\n",
" (temp[lower] AND ti[low]) AND al[low] = 1.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 1.0\n",
"\n",
"RULE #4:\n",
" IF (temp[higher] AND ti[low]) AND al[high] THEN viscosity[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[higher] : 0.0\n",
" - ti[low] : 1.0\n",
" - al[high] : 0.0\n",
" (temp[higher] AND ti[low]) AND al[high] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[low] : 0.0\n",
"\n",
"RULE #5:\n",
" IF (temp[average] AND ti[low]) AND al[high] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - ti[low] : 1.0\n",
" - al[high] : 0.0\n",
" (temp[average] AND ti[low]) AND al[high] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"RULE #6:\n",
" IF (temp[low] AND ti[low]) AND al[high] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 0.0\n",
" - ti[low] : 1.0\n",
" - al[high] : 0.0\n",
" (temp[low] AND ti[low]) AND al[high] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"RULE #7:\n",
" IF (temp[lower] AND ti[low]) AND al[high] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[lower] : 1.0\n",
" - ti[low] : 1.0\n",
" - al[high] : 0.0\n",
" (temp[lower] AND ti[low]) AND al[high] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"RULE #8:\n",
" IF temp[higher] AND ti[high] THEN viscosity[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[higher] : 0.0\n",
" - ti[high] : 0.0\n",
" temp[higher] AND ti[high] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[low] : 0.0\n",
"\n",
"RULE #9:\n",
" IF temp[average] AND ti[high] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - ti[high] : 0.0\n",
" temp[average] AND ti[high] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"RULE #10:\n",
" IF temp[low] AND ti[high] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 0.0\n",
" - ti[high] : 0.0\n",
" temp[low] AND ti[high] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"RULE #11:\n",
" IF temp[lower] AND ti[high] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[lower] : 1.0\n",
" - ti[high] : 0.0\n",
" temp[lower] AND ti[high] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"RULE #12:\n",
" IF (temp[higher] AND ti[average]) AND al[low] THEN viscosity[lower]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[higher] : 0.0\n",
" - ti[average] : 0.0\n",
" - al[low] : 1.0\n",
" (temp[higher] AND ti[average]) AND al[low] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[lower] : 0.0\n",
"\n",
"RULE #13:\n",
" IF (temp[average] AND ti[average]) AND al[low] THEN viscosity[average]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - ti[average] : 0.0\n",
" - al[low] : 1.0\n",
" (temp[average] AND ti[average]) AND al[low] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[average] : 0.0\n",
"\n",
"RULE #14:\n",
" IF (temp[low] AND ti[average]) AND al[low] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 0.0\n",
" - ti[average] : 0.0\n",
" - al[low] : 1.0\n",
" (temp[low] AND ti[average]) AND al[low] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"RULE #15:\n",
" IF (temp[lower] AND ti[average]) AND al[low] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[lower] : 1.0\n",
" - ti[average] : 0.0\n",
" - al[low] : 1.0\n",
" (temp[lower] AND ti[average]) AND al[low] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"RULE #16:\n",
" IF (temp[average] AND ti[low]) AND al[average] THEN viscosity[average]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - ti[low] : 1.0\n",
" - al[average] : 0.0\n",
" (temp[average] AND ti[low]) AND al[average] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[average] : 0.0\n",
"\n",
"RULE #17:\n",
" IF (temp[low] AND ti[low]) AND al[average] THEN viscosity[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 0.0\n",
" - ti[low] : 1.0\n",
" - al[average] : 0.0\n",
" (temp[low] AND ti[low]) AND al[average] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[high] : 0.0\n",
"\n",
"RULE #18:\n",
" IF (temp[lower] AND ti[low]) AND al[average] THEN viscosity[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[lower] : 1.0\n",
" - ti[low] : 1.0\n",
" - al[average] : 0.0\n",
" (temp[lower] AND ti[low]) AND al[average] = 0.0\n",
" Activation (THEN-clause):\n",
" viscosity[higher] : 0.0\n",
"\n",
"\n",
"==============================\n",
" Intermediaries and Conquests \n",
"==============================\n",
"Consequent: viscosity = 3.499157499995422\n",
" lower:\n",
" Accumulate using accumulation_max : 0.0\n",
" low:\n",
" Accumulate using accumulation_max : 0.0\n",
" average:\n",
" Accumulate using accumulation_max : 0.0\n",
" high:\n",
" Accumulate using accumulation_max : 0.0\n",
" higher:\n",
" Accumulate using accumulation_max : 1.0\n",
"\n"
]
},
{
"data": {
"text/plain": [
"np.float64(3.499157499995422)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sim.input[\"temp\"] = 20\n",
"sim.input[\"al\"] = 0.0\n",
"sim.input[\"ti\"] = 0.0\n",
"sim.compute()\n",
"sim.print_state()\n",
"display(sim.output[\"viscosity\"])"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>T</th>\n",
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Viscosity</th>\n",
" <th>ViscosityPred</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>20</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>3.707</td>\n",
" <td>3.499157</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>25</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>3.180</td>\n",
" <td>3.188565</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>35</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>2.361</td>\n",
" <td>2.732494</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>45</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.832</td>\n",
" <td>1.812498</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>50</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.629</td>\n",
" <td>1.812498</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>55</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.465</td>\n",
" <td>1.812498</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>70</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.194</td>\n",
" <td>1.390833</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>20</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>4.660</td>\n",
" <td>3.481064</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>30</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>3.380</td>\n",
" <td>3.090537</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>35</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>2.874</td>\n",
" <td>2.703435</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>40</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>2.489</td>\n",
" <td>2.365680</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>50</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.897</td>\n",
" <td>2.054459</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>55</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.709</td>\n",
" <td>2.128746</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>60</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.470</td>\n",
" <td>1.465795</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>20</td>\n",
" <td>0.30</td>\n",
" <td>0.0</td>\n",
" <td>6.670</td>\n",
" <td>3.499157</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"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def fuzzy_pred(row):\n",
" sim.input[\"temp\"] = row[\"T\"]\n",
" sim.input[\"al\"] = row[\"Al2O3\"]\n",
" sim.input[\"ti\"] = row[\"TiO2\"]\n",
" sim.compute()\n",
" return sim.output[\"viscosity\"]\n",
"\n",
"result_train = viscosity_train.copy()\n",
"result_train[\"ViscosityPred\"] = result_train.apply(fuzzy_pred, axis=1)\n",
"result_train.head(15)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>T</th>\n",
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Viscosity</th>\n",
" <th>ViscosityPred</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>30</td>\n",
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>2.716</td>\n",
" <td>3.089540</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>40</td>\n",
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>2.073</td>\n",
" <td>2.359522</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>60</td>\n",
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>1.329</td>\n",
" <td>1.465795</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>65</td>\n",
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>1.211</td>\n",
" <td>1.414928</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>25</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>4.120</td>\n",
" <td>3.188565</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>45</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>2.217</td>\n",
" <td>2.045546</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>65</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.315</td>\n",
" <td>1.414928</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>70</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.105</td>\n",
" <td>1.408926</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>45</td>\n",
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>3.111</td>\n",
" <td>3.499157</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>50</td>\n",
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>2.735</td>\n",
" <td>3.475062</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>65</td>\n",
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>1.936</td>\n",
" <td>1.812498</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>30</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>3.587</td>\n",
" <td>3.111691</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>55</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.953</td>\n",
" <td>2.128746</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>65</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.443</td>\n",
" <td>1.414928</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>40</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>3.990</td>\n",
" <td>3.475062</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>50</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>3.189</td>\n",
" <td>3.475062</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>65</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>2.287</td>\n",
" <td>1.812498</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"
]
},
"execution_count": 14,
"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"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'RMSE_train': 1.0977710360150494,\n",
" 'RMSE_test': 0.4076186194536602,\n",
" 'RMAE_test': 0.5797504263400755,\n",
" 'R2_test': 0.813200460937507}"
]
},
"execution_count": 15,
"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",
")\n",
"rmetrics[\"RMSE_test\"] = math.sqrt(\n",
" metrics.mean_squared_error(result_test[\"Viscosity\"], result_test[\"ViscosityPred\"])\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",
")\n",
"\n",
"rmetrics"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}