|
84 | 84 | "fun_control" |
85 | 85 | ] |
86 | 86 | }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "execution_count": 2, |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [ |
| 92 | + { |
| 93 | + "name": "stdout", |
| 94 | + "output_type": "stream", |
| 95 | + "text": [ |
| 96 | + " Attribute Name Attribute Value\n", |
| 97 | + "0 age 30\n", |
| 98 | + "1 name John\n", |
| 99 | + "2 salary 50000\n" |
| 100 | + ] |
| 101 | + } |
| 102 | + ], |
| 103 | + "source": [ |
| 104 | + "import pandas as pd\n", |
| 105 | + "\n", |
| 106 | + "def class_attributes_to_dataframe(class_obj):\n", |
| 107 | + " # Get the attributes and their values of the class object\n", |
| 108 | + " attributes = [attr for attr in dir(class_obj) if not callable(getattr(class_obj, attr)) and not attr.startswith(\"__\")]\n", |
| 109 | + " values = [getattr(class_obj, attr) for attr in attributes]\n", |
| 110 | + " \n", |
| 111 | + " # Create a DataFrame from the attributes and values\n", |
| 112 | + " df = pd.DataFrame({'Attribute Name': attributes, 'Attribute Value': values})\n", |
| 113 | + " \n", |
| 114 | + " return df\n", |
| 115 | + "\n", |
| 116 | + "# Example usage:\n", |
| 117 | + "class MyClass:\n", |
| 118 | + " def __init__(self):\n", |
| 119 | + " self.name = \"John\"\n", |
| 120 | + " self.age = 30\n", |
| 121 | + " self.salary = 50000\n", |
| 122 | + "\n", |
| 123 | + "my_instance = MyClass()\n", |
| 124 | + "df = class_attributes_to_dataframe(my_instance)\n", |
| 125 | + "print(df)\n", |
| 126 | + "\n" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "code", |
| 131 | + "execution_count": 3, |
| 132 | + "metadata": {}, |
| 133 | + "outputs": [ |
| 134 | + { |
| 135 | + "name": "stdout", |
| 136 | + "output_type": "stream", |
| 137 | + "text": [ |
| 138 | + "spotPython tuning: 2.3692002778610106e-10 [########--] 80.00% \n", |
| 139 | + "spotPython tuning: 2.3692002778610106e-10 [#########-] 90.00% \n", |
| 140 | + "spotPython tuning: 2.3692002778610106e-10 [##########] 100.00% Done...\n", |
| 141 | + "\n" |
| 142 | + ] |
| 143 | + }, |
| 144 | + { |
| 145 | + "data": { |
| 146 | + "text/plain": [ |
| 147 | + "<spotPython.spot.spot.Spot at 0x17717ddd0>" |
| 148 | + ] |
| 149 | + }, |
| 150 | + "execution_count": 3, |
| 151 | + "metadata": {}, |
| 152 | + "output_type": "execute_result" |
| 153 | + } |
| 154 | + ], |
| 155 | + "source": [ |
| 156 | + "import numpy as np\n", |
| 157 | + "from math import inf\n", |
| 158 | + "from spotPython.fun.objectivefunctions import analytical\n", |
| 159 | + "from spotPython.spot import spot\n", |
| 160 | + "# number of initial points:\n", |
| 161 | + "ni = 7\n", |
| 162 | + "# number of points\n", |
| 163 | + "n = 10\n", |
| 164 | + "\n", |
| 165 | + "fun = analytical().fun_sphere\n", |
| 166 | + "lower = np.array([-1])\n", |
| 167 | + "upper = np.array([1])\n", |
| 168 | + "design_control={\"init_size\": ni}\n", |
| 169 | + "\n", |
| 170 | + "spot_1 = spot.Spot(fun=fun,\n", |
| 171 | + " lower = lower,\n", |
| 172 | + " upper= upper,\n", |
| 173 | + " fun_evals = n,\n", |
| 174 | + " show_progress=True,\n", |
| 175 | + " design_control=design_control,)\n", |
| 176 | + "spot_1.run()\n" |
| 177 | + ] |
| 178 | + }, |
| 179 | + { |
| 180 | + "cell_type": "code", |
| 181 | + "execution_count": 13, |
| 182 | + "metadata": {}, |
| 183 | + "outputs": [ |
| 184 | + { |
| 185 | + "name": "stdout", |
| 186 | + "output_type": "stream", |
| 187 | + "text": [ |
| 188 | + " Attribute Name Attribute Value\n", |
| 189 | + "0 X [[-0.3378148180708981], [0.698908280342222], [0.07989717920782535], [-0.7669633744853341], [0.3783125996899912], [0.7679729980983505], [-0.6923842851505875], [1.5392206722432657e-05], [3.219839249186828e-05], [2.5933080782055762e-05]]\n", |
| 190 | + "1 all_lower [-1]\n", |
| 191 | + "2 all_upper [1]\n", |
| 192 | + "3 all_var_name [x0]\n", |
| 193 | + "4 all_var_type [num]\n", |
| 194 | + "5 counter 10\n", |
| 195 | + "6 de_bounds [[-1, 1]]\n", |
| 196 | + "7 design <spotPython.design.spacefilling.spacefilling object at 0x1773d88d0>\n", |
| 197 | + "8 design_control {'init_size': 7, 'repeats': 1}\n", |
| 198 | + "9 eps 0.0\n", |
| 199 | + "10 fun_control {'sigma': 0, 'seed': None}\n", |
| 200 | + "11 fun_evals 10\n", |
| 201 | + "12 fun_repeats 1\n", |
| 202 | + "13 ident [False]\n", |
| 203 | + "14 infill_criterion y\n", |
| 204 | + "15 k 1\n", |
| 205 | + "16 log_level 50\n", |
| 206 | + "17 lower [-1]\n", |
| 207 | + "18 max_time inf\n", |
| 208 | + "19 mean_X None\n", |
| 209 | + "20 mean_y None\n", |
| 210 | + "21 min_X [1.5392206722432657e-05]\n", |
| 211 | + "22 min_mean_X None\n", |
| 212 | + "23 min_mean_y None\n", |
| 213 | + "24 min_y 0.0\n", |
| 214 | + "25 n_points 1\n", |
| 215 | + "26 noise False\n", |
| 216 | + "27 ocba_delta 0\n", |
| 217 | + "28 optimizer_control {'max_iter': 1000, 'seed': 125}\n", |
| 218 | + "29 red_dim False\n", |
| 219 | + "30 rng Generator(PCG64)\n", |
| 220 | + "31 seed 123\n", |
| 221 | + "32 show_models False\n", |
| 222 | + "33 show_progress True\n", |
| 223 | + "34 spot_writer None\n", |
| 224 | + "35 surrogate <spotPython.build.kriging.Kriging object at 0x17733b090>\n", |
| 225 | + "36 surrogate_control {'noise': False, 'model_optimizer': <function differential_evolution at 0x169b6f420>, 'model_fun_evals': None, 'min_theta': -3.0, 'max_theta': 3.0, 'n_theta': 1, 'n_p': 1, 'optim_p': False, 'cod_type': 'norm', 'var_type': ['num'], 'seed': 124, 'use_cod_y': False}\n", |
| 226 | + "37 tolerance_x 0\n", |
| 227 | + "38 upper [1]\n", |
| 228 | + "39 var_name [x0]\n", |
| 229 | + "40 var_type [num]\n", |
| 230 | + "41 var_y None\n", |
| 231 | + "42 y [0.11411885130827397, 0.48847278433092195, 0.00638355924536736, 0.5882328178019309, 0.14312042308419953, 0.589782525808169, 0.47939599832349, 2.3692002778610106e-10, 1.0367364790603999e-09, 6.725246788486299e-10]" |
| 232 | + ] |
| 233 | + }, |
| 234 | + { |
| 235 | + "data": { |
| 236 | + "text/plain": [ |
| 237 | + "12627" |
| 238 | + ] |
| 239 | + }, |
| 240 | + "execution_count": 13, |
| 241 | + "metadata": {}, |
| 242 | + "output_type": "execute_result" |
| 243 | + } |
| 244 | + ], |
| 245 | + "source": [ |
| 246 | + "from sys import stdout\n", |
| 247 | + "df = spot_1.class_attributes_to_dataframe()\n", |
| 248 | + "stdout.write(df.to_string())" |
| 249 | + ] |
| 250 | + }, |
| 251 | + { |
| 252 | + "cell_type": "code", |
| 253 | + "execution_count": 5, |
| 254 | + "metadata": {}, |
| 255 | + "outputs": [ |
| 256 | + { |
| 257 | + "data": { |
| 258 | + "text/plain": [ |
| 259 | + "Accuracy: 89.28%" |
| 260 | + ] |
| 261 | + }, |
| 262 | + "execution_count": 5, |
| 263 | + "metadata": {}, |
| 264 | + "output_type": "execute_result" |
| 265 | + } |
| 266 | + ], |
| 267 | + "source": [ |
| 268 | + "from river import datasets\n", |
| 269 | + "from river import evaluate\n", |
| 270 | + "from river.linear_model import LogisticRegression\n", |
| 271 | + "from river import metrics\n", |
| 272 | + "from river import optim\n", |
| 273 | + "from river import preprocessing\n", |
| 274 | + "\n", |
| 275 | + "dataset = datasets.Phishing()\n", |
| 276 | + "\n", |
| 277 | + "model = (\n", |
| 278 | + " preprocessing.StandardScaler() |\n", |
| 279 | + " LogisticRegression()\n", |
| 280 | + ")\n", |
| 281 | + "\n", |
| 282 | + "metric = metrics.Accuracy()\n", |
| 283 | + "\n", |
| 284 | + "evaluate.progressive_val_score(dataset, model, metric)\n" |
| 285 | + ] |
| 286 | + }, |
87 | 287 | { |
88 | 288 | "cell_type": "code", |
89 | 289 | "execution_count": null, |
|
0 commit comments