2024-11-01 11:04:05 +04:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"|--- Al2O3 <= 0.18\n",
"| |--- TiO2 <= 0.18\n",
"| | |--- T <= 32.50\n",
"| | | |--- TiO2 <= 0.03\n",
"| | | | |--- Al2O3 <= 0.03\n",
"| | | | | |--- T <= 22.50\n",
"| | | | | | |--- value: [1.06]\n",
"| | | | | |--- T > 22.50\n",
"| | | | | | |--- value: [1.06]\n",
"| | | | |--- Al2O3 > 0.03\n",
"| | | | | |--- value: [1.09]\n",
"| | | |--- TiO2 > 0.03\n",
"| | | | |--- T <= 27.50\n",
"| | | | | |--- T <= 22.50\n",
"| | | | | | |--- value: [1.09]\n",
"| | | | | |--- T > 22.50\n",
"| | | | | | |--- value: [1.09]\n",
"| | | | |--- T > 27.50\n",
"| | | | | |--- value: [1.08]\n",
"| | |--- T > 32.50\n",
"| | | |--- TiO2 <= 0.03\n",
"| | | | |--- Al2O3 <= 0.03\n",
"| | | | | |--- T <= 55.00\n",
"| | | | | | |--- T <= 47.50\n",
"| | | | | | | |--- value: [1.05]\n",
"| | | | | | |--- T > 47.50\n",
"| | | | | | | |--- value: [1.04]\n",
"| | | | | |--- T > 55.00\n",
"| | | | | | |--- T <= 62.50\n",
"| | | | | | | |--- value: [1.04]\n",
"| | | | | | |--- T > 62.50\n",
"| | | | | | | |--- value: [1.03]\n",
"| | | | |--- Al2O3 > 0.03\n",
"| | | | | |--- T <= 60.00\n",
"| | | | | | |--- T <= 52.50\n",
"| | | | | | | |--- value: [1.07]\n",
"| | | | | | |--- T > 52.50\n",
"| | | | | | | |--- value: [1.06]\n",
"| | | | | |--- T > 60.00\n",
"| | | | | | |--- T <= 67.50\n",
"| | | | | | | |--- value: [1.06]\n",
"| | | | | | |--- T > 67.50\n",
"| | | | | | | |--- value: [1.05]\n",
"| | | |--- TiO2 > 0.03\n",
"| | | | |--- T <= 50.00\n",
"| | | | | |--- T <= 37.50\n",
"| | | | | | |--- value: [1.08]\n",
"| | | | | |--- T > 37.50\n",
"| | | | | | |--- value: [1.08]\n",
"| | | | |--- T > 50.00\n",
"| | | | | |--- T <= 67.50\n",
"| | | | | | |--- T <= 62.50\n",
"| | | | | | | |--- value: [1.06]\n",
"| | | | | | |--- T > 62.50\n",
"| | | | | | | |--- value: [1.06]\n",
"| | | | | |--- T > 67.50\n",
"| | | | | | |--- value: [1.06]\n",
"| |--- TiO2 > 0.18\n",
"| | |--- T <= 40.00\n",
"| | | |--- T <= 30.00\n",
"| | | | |--- value: [1.22]\n",
"| | | |--- T > 30.00\n",
"| | | | |--- value: [1.21]\n",
"| | |--- T > 40.00\n",
"| | | |--- T <= 60.00\n",
"| | | | |--- T <= 52.50\n",
"| | | | | |--- T <= 47.50\n",
"| | | | | | |--- value: [1.20]\n",
"| | | | | |--- T > 47.50\n",
"| | | | | | |--- value: [1.19]\n",
"| | | | |--- T > 52.50\n",
"| | | | | |--- value: [1.19]\n",
"| | | |--- T > 60.00\n",
"| | | | |--- value: [1.18]\n",
"|--- Al2O3 > 0.18\n",
"| |--- T <= 35.00\n",
"| | |--- T <= 22.50\n",
"| | | |--- value: [1.19]\n",
"| | |--- T > 22.50\n",
"| | | |--- T <= 27.50\n",
"| | | | |--- value: [1.18]\n",
"| | | |--- T > 27.50\n",
"| | | | |--- value: [1.18]\n",
"| |--- T > 35.00\n",
"| | |--- T <= 52.50\n",
"| | | |--- T <= 42.50\n",
"| | | | |--- value: [1.17]\n",
"| | | |--- T > 42.50\n",
"| | | | |--- T <= 47.50\n",
"| | | | | |--- value: [1.17]\n",
"| | | | |--- T > 47.50\n",
"| | | | | |--- value: [1.16]\n",
"| | |--- T > 52.50\n",
"| | | |--- T <= 65.00\n",
"| | | | |--- T <= 57.50\n",
"| | | | | |--- value: [1.16]\n",
"| | | | |--- T > 57.50\n",
"| | | | | |--- value: [1.15]\n",
"| | | |--- T > 65.00\n",
"| | | | |--- value: [1.14]\n",
"\n"
]
}
],
"source": [
"import pickle\n",
"import pandas as pd\n",
"from sklearn import tree\n",
"\n",
"model = pickle.load(open(\"data/dtree.model.sav\", \"rb\"))\n",
"features = (\n",
" pd.read_csv(\"data/density_train.csv\", sep=\";\", decimal=\",\")\n",
" .drop([\"Density\"], 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": [
"34"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) and (T > 55.0) and (T > 62.5) -> 1.033,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) and (T > 55.0) and (T <= 62.5) -> 1.038,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) and (T <= 55.0) and (T > 47.5) -> 1.045,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) and (T <= 55.0) and (T <= 47.5) -> 1.051,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) and (T > 60.0) and (T > 67.5) -> 1.053,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 > 0.025) and (T > 50.0) and (T > 67.5) -> 1.056,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) and (T > 60.0) and (T <= 67.5) -> 1.057,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) and (T > 22.5) -> 1.06,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 > 0.025) and (T > 50.0) and (T <= 67.5) and (T > 62.5) -> 1.06,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (TiO2 <= 0.025) and (Al2O3 <= 0.025) and (T <= 22.5) -> 1.062,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 > 0.025) and (T > 50.0) and (T <= 67.5) and (T <= 62.5) -> 1.064,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) and (T <= 60.0) and (T > 52.5) -> 1.064,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) and (T <= 60.0) and (T <= 52.5) -> 1.069,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 > 0.025) and (T <= 50.0) and (T > 37.5) -> 1.078,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (TiO2 > 0.025) and (T <= 50.0) and (T <= 37.5) -> 1.081,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (TiO2 > 0.025) and (T > 27.5) -> 1.084,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (TiO2 <= 0.025) and (Al2O3 > 0.025) -> 1.088,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (TiO2 > 0.025) and (T <= 27.5) and (T > 22.5) -> 1.088,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (TiO2 > 0.025) and (T <= 27.5) and (T <= 22.5) -> 1.091,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T > 52.5) and (T > 65.0) -> 1.144,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T > 52.5) and (T <= 65.0) and (T > 57.5) -> 1.152,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T > 52.5) and (T <= 65.0) and (T <= 57.5) -> 1.157,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 52.5) and (T > 42.5) and (T > 47.5) -> 1.161,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 52.5) and (T > 42.5) and (T <= 47.5) -> 1.166,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 52.5) and (T <= 42.5) -> 1.17,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T > 60.0) -> 1.178,\n",
" if (Al2O3 > 0.175) and (T <= 35.0) and (T > 22.5) and (T > 27.5) -> 1.179,\n",
" if (Al2O3 > 0.175) and (T <= 35.0) and (T > 22.5) and (T <= 27.5) -> 1.184,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T <= 60.0) and (T > 52.5) -> 1.187,\n",
" if (Al2O3 > 0.175) and (T <= 35.0) and (T <= 22.5) -> 1.189,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T <= 60.0) and (T <= 52.5) and (T > 47.5) -> 1.193,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T <= 60.0) and (T <= 52.5) and (T <= 47.5) -> 1.198,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T <= 40.0) and (T > 30.0) -> 1.208,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T <= 40.0) and (T <= 30.0) -> 1.219]"
]
},
"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": [
"34"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) -> 1.033,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 62.5) -> 1.038,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 55.0) -> 1.045,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 55.0) -> 1.051,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) -> 1.053,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) -> 1.056,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 67.5) -> 1.057,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (T > 22.5) -> 1.06,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) and (T <= 67.5) -> 1.06,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) -> 1.062,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) and (T <= 67.5) -> 1.064,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 60.0) -> 1.064,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 60.0) -> 1.069,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) and (T <= 50.0) -> 1.078,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) and (T <= 50.0) -> 1.081,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) and (T > 27.5) -> 1.084,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T <= 32.5) -> 1.088,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) and (T > 22.5) -> 1.088,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) -> 1.091,\n",
" if (Al2O3 > 0.175) and (T > 35.0) -> 1.144,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 65.0) -> 1.152,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 65.0) -> 1.157,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 52.5) -> 1.161,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 52.5) -> 1.166,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 52.5) -> 1.17,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) -> 1.178,\n",
" if (Al2O3 > 0.175) and (T <= 35.0) and (T > 22.5) -> 1.179,\n",
" if (Al2O3 > 0.175) and (T <= 35.0) and (T > 22.5) -> 1.184,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T <= 60.0) -> 1.187,\n",
" if (Al2O3 > 0.175) and (T <= 35.0) -> 1.189,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T <= 60.0) -> 1.193,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T <= 60.0) -> 1.198,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T <= 40.0) and (T > 30.0) -> 1.208,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T <= 40.0) -> 1.219]"
]
},
"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": [
"24"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) -> 1.033,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 62.5) -> 1.038,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 55.0) -> 1.048,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) -> 1.053,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) -> 1.056,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 67.5) -> 1.057,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (T > 22.5) -> 1.06,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) -> 1.062,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) and (T <= 67.5) -> 1.062,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 60.0) -> 1.067,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) and (T <= 50.0) -> 1.079,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) and (T > 27.5) -> 1.084,\n",
" if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T <= 32.5) -> 1.088,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) and (T > 22.5) -> 1.088,\n",
" if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) -> 1.091,\n",
" if (Al2O3 > 0.175) and (T > 35.0) -> 1.144,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 65.0) -> 1.155,\n",
" if (Al2O3 > 0.175) and (T > 35.0) and (T <= 52.5) -> 1.166,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) -> 1.178,\n",
" if (Al2O3 > 0.175) and (T <= 35.0) and (T > 22.5) -> 1.182,\n",
" if (Al2O3 > 0.175) and (T <= 35.0) -> 1.189,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T <= 60.0) -> 1.193,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T <= 40.0) and (T > 30.0) -> 1.208,\n",
" if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T <= 40.0) -> 1.219]"
]
},
"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 (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) -> 1.033</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.0333299999999999</td>\n",
" </tr>\n",
" <tr>\n",
" <th>if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 62.5) -> 1.038</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.03826</td>\n",
" </tr>\n",
" <tr>\n",
" <th>if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 55.0) -> 1.048</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.0478999999999998</td>\n",
" </tr>\n",
" <tr>\n",
" <th>if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) -> 1.053</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1.05291</td>\n",
" </tr>\n",
" <tr>\n",
" <th>if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) -> 1.056</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.05601</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" (Al2O3 <= 0.175) \\\n",
"rule \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1 \n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (Ti... 1 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (Ti... 1 \n",
"\n",
" (Al2O3 > 0.025) \\\n",
"rule \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (Ti... 1 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (Ti... 0 \n",
"\n",
" (Al2O3 > 0.175) \\\n",
"rule \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (Ti... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (Ti... 0 \n",
"\n",
" (TiO2 <= 0.175) \\\n",
"rule \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1 \n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (Ti... 1 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (Ti... 1 \n",
"\n",
" (TiO2 > 0.025) \\\n",
"rule \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (Ti... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (Ti... 1 \n",
"\n",
" (TiO2 > 0.175) \\\n",
"rule \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 0 \n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (Ti... 0 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (Ti... 0 \n",
"\n",
" consequent \n",
"rule \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1.0333299999999999 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1.03826 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T ... 1.0478999999999998 \n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (Ti... 1.05291 \n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (Ti... 1.05601 "
]
},
"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.5483575964237912,\n",
" 3: 0.602943554055511,\n",
" 4: 0.8221763769597347,\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": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAGFCAYAAAAYU4NfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABAdUlEQVR4nO3dfXzN9f/H8cc2NsM2l5urZS7SCJvmIuRHUUJSKkq5KpXowjUT5rKhiEq5KrryTUTpAkkUuUooSsxVhM1FtjEZO+fz++OTw2xjh+18zs6e99vt3PY57/M557zOB0+fvc/78357GYZhICIiHsnb6gJERCT3KORFRDyYQl5ExIMp5EVEPJhCXkTEgynkRUQ8mEJeRMSDKeRFRDyYQl5ExIMp5CVbVq9ejZeXFwsXLrS6FIdu3boRFhaWrs3Ly4uRI0c67o8cORIvLy9OnDjh2uJE3IRCPh/z8vLK1m316tUurev48eO89NJLhIeH4+/vT3BwMPXr12fw4MGcOXPGpbW4wtmzZxk5cmSmx/mbb75J95+WiLMKWF2AWOfDDz9Md/+DDz5gxYoVGdqrV6/Ozp07XVLTP//8Q926dUlOTubJJ58kPDyckydP8ttvv/HOO+/w3HPPUbRoUQBmzZqF3W53SV256ezZs4waNQqAZs2apXvsm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3XJvNZgwePNgoVaqUUbhwYaNly5bGnj17MgyhNAzDOH36tBEdHW1UrVrV8PX1NUqVKmU0atT
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 (5):\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) -> 1.033;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 62.5) -> 1.038;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 55.0) -> 1.048;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) and (T > 22.5) -> 1.06;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (T <= 32.5) -> 1.062\n",
"--------\n",
"Кластер 2 (5):\n",
"if (Al2O3 > 0.175) and (T > 35.0) -> 1.144;\n",
"if (Al2O3 > 0.175) and (T > 35.0) and (T <= 65.0) -> 1.155;\n",
"if (Al2O3 > 0.175) and (T > 35.0) and (T <= 52.5) -> 1.166;\n",
"if (Al2O3 > 0.175) and (T <= 35.0) and (T > 22.5) -> 1.182;\n",
"if (Al2O3 > 0.175) and (T <= 35.0) -> 1.189\n",
"--------\n",
"Кластер 3 (6):\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) -> 1.056;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) and (T <= 67.5) -> 1.062;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T > 32.5) and (T <= 50.0) -> 1.079;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) and (T > 27.5) -> 1.084;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) and (T > 22.5) -> 1.088;\n",
"if (Al2O3 <= 0.175) and (TiO2 <= 0.175) and (TiO2 > 0.025) and (T <= 32.5) -> 1.091\n",
"--------\n",
"Кластер 4 (4):\n",
"if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) -> 1.178;\n",
"if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T > 40.0) and (T <= 60.0) -> 1.193;\n",
"if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T <= 40.0) and (T > 30.0) -> 1.208;\n",
"if (Al2O3 <= 0.175) and (TiO2 > 0.175) and (T <= 40.0) -> 1.219\n",
"--------\n",
"Кластер 5 (4):\n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) -> 1.053;\n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 67.5) -> 1.057;\n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T > 32.5) and (T <= 60.0) -> 1.067;\n",
"if (Al2O3 <= 0.175) and (Al2O3 > 0.025) and (TiO2 <= 0.175) and (T <= 32.5) -> 1.088\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>Density</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>1.06250</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>1.05979</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>1.05404</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Density\n",
"0 20 0.0 0.0 1.06250\n",
"1 25 0.0 0.0 1.05979\n",
"2 35 0.0 0.0 1.05404"
]
},
"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>Density</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.0</td>\n",
" <td>1.05696</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>55</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.04158</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>25</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.08438</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Density\n",
"0 30 0.00 0.0 1.05696\n",
"1 55 0.00 0.0 1.04158\n",
"2 25 0.05 0.0 1.08438"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"density_train = pd.read_csv(\"data/density_train.csv\", sep=\";\", decimal=\",\")\n",
"density_test = pd.read_csv(\"data/density_test.csv\", sep=\";\", decimal=\",\")\n",
"\n",
"display(density_train.head(3))\n",
"display(density_test.head(3))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[if (Al2O3 = 0.0) and (TiO2 = 0.0) and (T = 70) -> 1.033,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.0) and (T = 47.5) -> 1.038,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.0) and (T = 43.75) -> 1.048,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.0) and (T = 27.5) -> 1.06,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.0) and (T = 20) -> 1.062],\n",
" [if (Al2O3 = 0.3) and (T = 70) -> 1.144,\n",
" if (Al2O3 = 0.3) and (T = 50.0) -> 1.155,\n",
" if (Al2O3 = 0.3) and (T = 43.75) -> 1.166,\n",
" if (Al2O3 = 0.3) and (T = 28.75) -> 1.182,\n",
" if (Al2O3 = 0.3) and (T = 20) -> 1.189],\n",
" [if (Al2O3 = 0.0) and (TiO2 = 0.1) and (T = 70) -> 1.056,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.1) and (T = 50.0) -> 1.062,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.1) and (T = 41.25) -> 1.079,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.1) and (T = 30.0) -> 1.084,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.1) and (T = 27.5) -> 1.088,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.1) and (T = 20) -> 1.091],\n",
" [if (Al2O3 = 0.0) and (TiO2 = 0.3) and (T = 70) -> 1.178,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.3) and (T = 50.0) -> 1.193,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.3) and (T = 35.0) -> 1.208,\n",
" if (Al2O3 = 0.0) and (TiO2 = 0.3) and (T = 20) -> 1.219],\n",
" [if (Al2O3 = 0.1) and (TiO2 = 0.0) and (T = 70) -> 1.053,\n",
" if (Al2O3 = 0.1) and (TiO2 = 0.0) and (T = 50.0) -> 1.057,\n",
" if (Al2O3 = 0.1) and (TiO2 = 0.0) and (T = 46.25) -> 1.067,\n",
" if (Al2O3 = 0.1) and (TiO2 = 0.0) and (T = 20) -> 1.088]]"
]
},
"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(density_train, rules, clusters_num, kmeans.labels_)\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": "iVBORw0KGgoAAAANSUhEUgAAAkAAAAGyCAYAAAAMKHu5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACJKUlEQVR4nOzdd1RU19rH8e/QQQFBFCwo9g72hi2xd03UFBNj6tXYS4IFsYFdY4xGo+k31RKx9y5iV+y9YENsgILUmfeP817uNZYADuwpz2etWSs5nDnnB4eDz+x99t46g8FgQAghhBDCitioDiCEEEIIkdekABJCCCGE1ZECSAghhBBWRwogIYQQQlgdKYCEEEIIYXWkABJCCCGE1ZECSAghhBBWRwogIYQQQlgdKYCEEEIIYXWsrgAyGAwkJCQgE2ALIYQQ1ktpAbRz5046duxI0aJF0el0hIeH/+N7tm/fTs2aNXF0dKRs2bL8+OOP2Trnw4cPcXd35+HDhzkLLYQQQgizp7QASkxMJCAggHnz5mVp/8uXL9O+fXteeeUVjh49yuDBg/noo4/YsGFDLicVQgghhCXRmcpiqDqdjuXLl9OlS5fn7hMUFMSaNWs4ceJE5rY333yTuLg41q9fn6XzJCQk4O7uTnx8PG5ubi8bWwghhBB5wGAwoNPpjHY8s3oGKDIykhYtWjyxrXXr1kRGRj73PSkpKSQkJDzxAniYnJarWYUQCpxcDj92gOQE1UmEEEa24uIKox7PrAqgmJgYvL29n9jm7e1NQkICjx8/fuZ7Jk+ejLu7e+bL19cXgBkbzuZ6XiFEHoq/DisHwpVdsDFYdRohhBHFJMYwdf9Uox7TrAqgnBg5ciTx8fGZr2vXrgGw7PANtp2NVZxOCGEUBgOs6A8O+aHFeDj8E5zfpDqVEMIIDAYDIREhuNi7GPW4ZlUA+fj4cPv27Se23b59Gzc3N5ydnZ/5HkdHR9zc3J54ATQsW5ARy44RnyRdYUKYvYPfw6Vt0PkrCB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brhQ3uWRro2Neb3/iElOY9fsZ1XGEME+JN2HjKKj1MtTsqTrNf9nYai0fHsTC1hDVaYQwS7eTbzP9wHRe9H2RDr4dCnTbUtzkQXnPQozrWI3vIq4QfuGO6jhCmBeDAdYP027D7jRPdZonFasI7abAoWVwcYfqNEKYFYPBwOSIyTjYOjAhYEKBb1+Kmzwa0MSXJhWKMWb1cRJT0lXHEcJ8HP0Bzv8BXT8FFw/VaZ6u4TtaC4i1H0BKguo0QpiNsAth7L62m5AmIRR1Klrg25fiJo9sbHTM6eVHfHIaoRtOq44jhHmIj4HN46FOf6j6ouo0z2Zjo7WASImHPwr+26cQ5ujmw5vMPjSb7hW708qnlZIMUtwYgY+HC5O61GDlX9f480yc6jhCmDa9XjsT4uQGHWeqTvPP3MtBhxnamaazm1WnEcKk6Q16gvcFU8ShCGMbjVWWQ4obI+nb0IdWVYsz9tcTxCdLbxohnumvryF6F3T/XCtwzEG9AVCpHaz/EJJl+gchnmXl2ZXsv7mfKU2nUMShiLIcUtwYiU6nY9ZLfqSmZxKy7pTqOEKYprsXYWswNHgTKr6gOk326XTQ7TPISIFNH6lOI4RJupp4lY8Pf0yfKn1oWqqp0ixS3BiRt5sTU7rXZO2xG/x+4qbqOEKYFn0mrB0ChYpDu2mq0+Scayl4cS6cXA2n16pOI4RJydRnEhQehIeTB6MajFIdR4obY+tRpzT
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGyCAYAAAAYveVYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACGqklEQVR4nOzdd1gU59rH8e/SQQFBFCwo9g52VKyxxm5iOcZETdcYY40VwYJdE2s0MckxPZZErDGWWBFLLNiwo9jACqhI3/ePeQ/nGB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8MnYmdtxzj/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": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGyCAYAAAAYveVYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADDlklEQVR4nOzdeVhb95X4/7c2xCax72Yz4AVsvNvxjleEjbP42y1Jm6ZL8munmSZNO0k6aZNuSdqZdtLOdEvSdNJ2ki7TsZ3EMQJv2LHjeME73gAjsDEgdolNCEm/PxRosMFmkXQl8Xk9D8/TiKt7j32LOfqc+zlH5nA4HAiCIAiCIPgJudQBCIIgCIIguJJIbgRBEARB8CsiuREEQRAEwa+I5EYQBEEQBL8ikhtBEARBEPyKSG4EQRAEQfArIrkR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QwlqhZo1yWvG9D5dmo7DNw7TYelwU2SCO5iKipAFBxO6etWY3qfdVEDX++9jM4nSsy+pLDOiVCsmVJICkdwMsTk3gX67g5LyBqlDEcaifBtMy4eA0S1ZD8q+F+z9zmGags/QG/SsTFpJiGps93tj2kZsdhv7asVsMV9i2lWEJi8PeVDQmN6nyc/HYbVi3ifuty+pPGEkfXYUqgDFhM4jkpuPidMGsigtkp1nRUM/n9FcCQ3nxlaSGqBNgNRlojTlQ66ZrlHeUk5++uhLUgNig2OZHzef4hpRmvIVlqoqLFeu3LZx30hU8fEELVggSlM+pK2hi5a6TjInsEtqgEhubrIlN4HDlc20dfVJHYowGuXbISAUsjaO7/0598HVUuhudWlYgnsU1xQTpAxiVdLYShQDdGk
"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(density_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",
"density = ctrl.Consequent(np.arange(1.03, 1.22, 0.00001), \"density\")\n",
"\n",
"temp.automf(3, 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",
"density.automf(5, variable_type=\"quant\")\n",
"density.view()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"15"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[IF (al[low] AND ti[low]) AND temp[high] THEN density[lower]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[low] AND ti[low]) AND temp[average] THEN density[lower]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[low] AND ti[low]) AND temp[low] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF al[high] AND temp[high] THEN density[average]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF al[high] AND temp[average] THEN density[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF al[high] AND temp[low] THEN density[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[low] AND ti[average]) AND temp[high] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[low] AND ti[average]) AND temp[average] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[low] AND ti[average]) AND temp[low] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[low] AND ti[high]) AND temp[high] THEN density[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[low] AND ti[high]) AND temp[average] THEN density[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[low] AND ti[high]) AND temp[low] THEN density[higher]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[average] AND ti[low]) AND temp[high] THEN density[lower]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[average] AND ti[low]) AND temp[average] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (al[average] AND ti[low]) AND temp[low] THEN density[low]\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\": density}\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",
2024-11-18 21:30:22 +04:00
"execution_count": 16,
2024-11-01 11:04:05 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=============\n",
" Antecedents \n",
"=============\n",
"Antecedent: al = 0.0\n",
" - low : 1.0\n",
" - average : 0.0\n",
" - high : 0.0\n",
"Antecedent: ti = 0.0\n",
" - low : 1.0\n",
" - average : 0.0\n",
" - high : 0.0\n",
2024-11-18 21:30:22 +04:00
"Antecedent: temp = 25\n",
" - low : 0.8\n",
" - average : 0.2\n",
2024-11-01 11:04:05 +04:00
" - high : 0.0\n",
"\n",
"=======\n",
" Rules \n",
"=======\n",
"RULE #0:\n",
" IF (al[low] AND ti[low]) AND temp[high] THEN density[lower]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[low] : 1.0\n",
" - temp[high] : 0.0\n",
" (al[low] AND ti[low]) AND temp[high] = 0.0\n",
" Activation (THEN-clause):\n",
" density[lower] : 0.0\n",
"\n",
"RULE #1:\n",
" IF (al[low] AND ti[low]) AND temp[average] THEN density[lower]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[low] : 1.0\n",
2024-11-18 21:30:22 +04:00
" - temp[average] : 0.2\n",
" (al[low] AND ti[low]) AND temp[average] = 0.2\n",
2024-11-01 11:04:05 +04:00
" Activation (THEN-clause):\n",
2024-11-18 21:30:22 +04:00
" density[lower] : 0.2\n",
2024-11-01 11:04:05 +04:00
"\n",
"RULE #2:\n",
" IF (al[low] AND ti[low]) AND temp[low] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[low] : 1.0\n",
2024-11-18 21:30:22 +04:00
" - temp[low] : 0.8\n",
" (al[low] AND ti[low]) AND temp[low] = 0.8\n",
2024-11-01 11:04:05 +04:00
" Activation (THEN-clause):\n",
2024-11-18 21:30:22 +04:00
" density[low] : 0.8\n",
2024-11-01 11:04:05 +04:00
"\n",
"RULE #3:\n",
" IF al[high] AND temp[high] THEN density[average]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[high] : 0.0\n",
" - temp[high] : 0.0\n",
" al[high] AND temp[high] = 0.0\n",
" Activation (THEN-clause):\n",
" density[average] : 0.0\n",
"\n",
"RULE #4:\n",
" IF al[high] AND temp[average] THEN density[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[high] : 0.0\n",
2024-11-18 21:30:22 +04:00
" - temp[average] : 0.2\n",
2024-11-01 11:04:05 +04:00
" al[high] AND temp[average] = 0.0\n",
" Activation (THEN-clause):\n",
" density[high] : 0.0\n",
"\n",
"RULE #5:\n",
" IF al[high] AND temp[low] THEN density[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[high] : 0.0\n",
2024-11-18 21:30:22 +04:00
" - temp[low] : 0.8\n",
2024-11-01 11:04:05 +04:00
" al[high] AND temp[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[high] : 0.0\n",
"\n",
"RULE #6:\n",
" IF (al[low] AND ti[average]) AND temp[high] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[average] : 0.0\n",
" - temp[high] : 0.0\n",
" (al[low] AND ti[average]) AND temp[high] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #7:\n",
" IF (al[low] AND ti[average]) AND temp[average] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[average] : 0.0\n",
2024-11-18 21:30:22 +04:00
" - temp[average] : 0.2\n",
2024-11-01 11:04:05 +04:00
" (al[low] AND ti[average]) AND temp[average] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #8:\n",
" IF (al[low] AND ti[average]) AND temp[low] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[average] : 0.0\n",
2024-11-18 21:30:22 +04:00
" - temp[low] : 0.8\n",
2024-11-01 11:04:05 +04:00
" (al[low] AND ti[average]) AND temp[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #9:\n",
" IF (al[low] AND ti[high]) AND temp[high] THEN density[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[high] : 0.0\n",
" - temp[high] : 0.0\n",
" (al[low] AND ti[high]) AND temp[high] = 0.0\n",
" Activation (THEN-clause):\n",
" density[high] : 0.0\n",
"\n",
"RULE #10:\n",
" IF (al[low] AND ti[high]) AND temp[average] THEN density[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[high] : 0.0\n",
2024-11-18 21:30:22 +04:00
" - temp[average] : 0.2\n",
2024-11-01 11:04:05 +04:00
" (al[low] AND ti[high]) AND temp[average] = 0.0\n",
" Activation (THEN-clause):\n",
" density[higher] : 0.0\n",
"\n",
"RULE #11:\n",
" IF (al[low] AND ti[high]) AND temp[low] THEN density[higher]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[low] : 1.0\n",
" - ti[high] : 0.0\n",
2024-11-18 21:30:22 +04:00
" - temp[low] : 0.8\n",
2024-11-01 11:04:05 +04:00
" (al[low] AND ti[high]) AND temp[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[higher] : 0.0\n",
"\n",
"RULE #12:\n",
" IF (al[average] AND ti[low]) AND temp[high] THEN density[lower]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[average] : 0.0\n",
" - ti[low] : 1.0\n",
" - temp[high] : 0.0\n",
" (al[average] AND ti[low]) AND temp[high] = 0.0\n",
" Activation (THEN-clause):\n",
" density[lower] : 0.0\n",
"\n",
"RULE #13:\n",
" IF (al[average] AND ti[low]) AND temp[average] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[average] : 0.0\n",
" - ti[low] : 1.0\n",
2024-11-18 21:30:22 +04:00
" - temp[average] : 0.2\n",
2024-11-01 11:04:05 +04:00
" (al[average] AND ti[low]) AND temp[average] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #14:\n",
" IF (al[average] AND ti[low]) AND temp[low] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - al[average] : 0.0\n",
" - ti[low] : 1.0\n",
2024-11-18 21:30:22 +04:00
" - temp[low] : 0.8\n",
2024-11-01 11:04:05 +04:00
" (al[average] AND ti[low]) AND temp[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"\n",
"==============================\n",
" Intermediaries and Conquests \n",
"==============================\n",
2024-11-18 21:30:22 +04:00
"Consequent: density = 1.076592785948375\n",
2024-11-01 11:04:05 +04:00
" lower:\n",
2024-11-18 21:30:22 +04:00
" Accumulate using accumulation_max : 0.2\n",
2024-11-01 11:04:05 +04:00
" low:\n",
2024-11-18 21:30:22 +04:00
" Accumulate using accumulation_max : 0.8\n",
2024-11-01 11:04:05 +04:00
" average:\n",
" Accumulate using accumulation_max : 0.0\n",
" high:\n",
" Accumulate using accumulation_max : 0.0\n",
" higher:\n",
" Accumulate using accumulation_max : 0.0\n",
"\n"
]
},
{
"data": {
"text/plain": [
2024-11-18 21:30:22 +04:00
"np.float64(1.076592785948375)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGyCAYAAAAYveVYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADDPUlEQVR4nOzdeVzc9Z348dfcXDPcx0AgkJA7AXIZc5OTIZJq3R6rttZe/tqtW63tql1bbbdV2227dnd7eNTWdldbuxqvGAZySGJizEHMAUkIEI5AgOGe4Rrm+v0xgiaBhGNmvjPD5/l48GgdvvP9vuNXwns+7+/n/Za5XC4XgiAIgiAIQUIudQCCIAiCIAieJJIbQRAEQRCCikhuBEEQBEEIKiK5EQRBEAQhqIjkRhAEQRCEoCKSG0EQBEEQgopIbgRBEARBCCoiuREEQRAEIaiI5EYQBEEQhKAy5ZIbl8uF2WxGNGYWBEEQhOAkaXJz4MABtm/fTnJ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VtxOB3sqxezxQKJeVch2txc5KGh43qfNi8Pl82GZZ+434Gk6riJjEWxqNSKSZ1HJDefkKgLYXl6DDtPi4Z+AaOtCprPjK8kNUSnh+mrRGkqgFwyX6K8vZy8jLGXpIYkhCWwJHEJRXWiNBUorNXVWC9cuG7jvtGokpIIXbpUlKYCSGdzL+2NPWROYpfUEJHcXGV7lp5DVW109g5KHYowFuWvgzoCZm2d2PsXfBoulkBfh0fDEryjqK6IUGUo61LGV6IYYkg3cOTyEboGujwbmOAV5kIj8vBwwteOoX/
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
2024-11-01 11:04:05 +04:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2024-11-18 21:30:22 +04:00
"sim.input[\"temp\"] = 25\n",
2024-11-01 11:04:05 +04:00
"sim.input[\"al\"] = 0.0\n",
"sim.input[\"ti\"] = 0.0\n",
"sim.compute()\n",
"sim.print_state()\n",
2024-11-18 21:30:22 +04:00
"display(sim.output[\"density\"])\n",
"density.view(sim=sim)"
2024-11-01 11:04:05 +04:00
]
},
{
"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>Density</th>\n",
" <th>DensityPred</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>1.06250</td>\n",
" <td>1.077498</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>1.05979</td>\n",
" <td>1.076593</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>1.05404</td>\n",
" <td>1.069156</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>40</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.05103</td>\n",
" <td>1.061106</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>45</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.04794</td>\n",
" <td>1.045833</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>50</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.04477</td>\n",
" <td>1.046360</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>60</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.03826</td>\n",
" <td>1.047642</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>65</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.03484</td>\n",
" <td>1.046360</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>70</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.03182</td>\n",
" <td>1.045833</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>20</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.08755</td>\n",
" <td>1.077498</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>45</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.07105</td>\n",
" <td>1.067145</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.06760</td>\n",
" <td>1.067145</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.06409</td>\n",
" <td>1.067988</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>65</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.05691</td>\n",
" <td>1.062538</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>70</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.05291</td>\n",
" <td>1.047191</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Density DensityPred\n",
"0 20 0.00 0.0 1.06250 1.077498\n",
"1 25 0.00 0.0 1.05979 1.076593\n",
"2 35 0.00 0.0 1.05404 1.069156\n",
"3 40 0.00 0.0 1.05103 1.061106\n",
"4 45 0.00 0.0 1.04794 1.045833\n",
"5 50 0.00 0.0 1.04477 1.046360\n",
"6 60 0.00 0.0 1.03826 1.047642\n",
"7 65 0.00 0.0 1.03484 1.046360\n",
"8 70 0.00 0.0 1.03182 1.045833\n",
"9 20 0.05 0.0 1.08755 1.077498\n",
"10 45 0.05 0.0 1.07105 1.067145\n",
"11 50 0.05 0.0 1.06760 1.067145\n",
"12 55 0.05 0.0 1.06409 1.067988\n",
"13 65 0.05 0.0 1.05691 1.062538\n",
"14 70 0.05 0.0 1.05291 1.047191"
]
},
"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[\"density\"]\n",
"\n",
"result_train = density_train.copy()\n",
"result_train[\"DensityPred\"] = 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>Density</th>\n",
" <th>DensityPred</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>1.05696</td>\n",
" <td>1.073918</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>55</td>\n",
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>1.04158</td>\n",
" <td>1.047642</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>25</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.08438</td>\n",
" <td>1.076518</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>30</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.08112</td>\n",
" <td>1.073918</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>35</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.07781</td>\n",
" <td>1.069156</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>40</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.07446</td>\n",
" <td>1.067145</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>60</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.06053</td>\n",
" <td>1.067988</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>35</td>\n",
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>1.17459</td>\n",
" <td>1.172492</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>65</td>\n",
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>1.14812</td>\n",
" <td>1.136460</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>45</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.07424</td>\n",
" <td>1.067145</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>50</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.07075</td>\n",
" <td>1.067145</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>55</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.06721</td>\n",
" <td>1.067988</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>20</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.22417</td>\n",
" <td>1.204157</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>30</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.21310</td>\n",
" <td>1.202348</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>1.20265</td>\n",
" <td>1.203630</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>60</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.18265</td>\n",
" <td>1.176072</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>70</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.17261</td>\n",
" <td>1.172492</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Density DensityPred\n",
"0 30 0.00 0.00 1.05696 1.073918\n",
"1 55 0.00 0.00 1.04158 1.047642\n",
"2 25 0.05 0.00 1.08438 1.076518\n",
"3 30 0.05 0.00 1.08112 1.073918\n",
"4 35 0.05 0.00 1.07781 1.069156\n",
"5 40 0.05 0.00 1.07446 1.067145\n",
"6 60 0.05 0.00 1.06053 1.067988\n",
"7 35 0.30 0.00 1.17459 1.172492\n",
"8 65 0.30 0.00 1.14812 1.136460\n",
"9 45 0.00 0.05 1.07424 1.067145\n",
"10 50 0.00 0.05 1.07075 1.067145\n",
"11 55 0.00 0.05 1.06721 1.067988\n",
"12 20 0.00 0.30 1.22417 1.204157\n",
"13 30 0.00 0.30 1.21310 1.202348\n",
"14 40 0.00 0.30 1.20265 1.203630\n",
"15 60 0.00 0.30 1.18265 1.176072\n",
"16 70 0.00 0.30 1.17261 1.172492"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result_test = density_test.copy()\n",
"result_test[\"DensityPred\"] = result_test.apply(fuzzy_pred, axis=1)\n",
"result_test"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'RMSE_train': 0.009765373953597112,\n",
" 'RMSE_test': 0.009031443610368107,\n",
" 'RMAE_test': 0.08581225574298121,\n",
" 'R2_test': 0.978451748357252}"
]
},
"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[\"Density\"], result_train[\"DensityPred\"])\n",
")\n",
"rmetrics[\"RMSE_test\"] = math.sqrt(\n",
" metrics.mean_squared_error(result_test[\"Density\"], result_test[\"DensityPred\"])\n",
")\n",
"rmetrics[\"RMAE_test\"] = math.sqrt(\n",
" metrics.mean_absolute_error(result_test[\"Density\"], result_test[\"DensityPred\"])\n",
")\n",
"rmetrics[\"R2_test\"] = metrics.r2_score(\n",
" result_test[\"Density\"], result_test[\"DensityPred\"]\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
}