|
24 | 24 | }, |
25 | 25 | { |
26 | 26 | "cell_type": "code", |
| 27 | + "execution_count": 30, |
27 | 28 | "metadata": { |
28 | 29 | "ExecuteTime": { |
29 | 30 | "end_time": "2025-12-17T19:13:35.353551Z", |
30 | 31 | "start_time": "2025-12-17T19:13:35.349651Z" |
31 | 32 | } |
32 | 33 | }, |
| 34 | + "outputs": [], |
33 | 35 | "source": [ |
34 | 36 | "import os\n", |
35 | 37 | "\n", |
|
38 | 40 | "from sklearn.model_selection import train_test_split\n", |
39 | 41 | "\n", |
40 | 42 | "from faim_sdk import LimiXPredictRequest, TabularClient" |
41 | | - ], |
42 | | - "outputs": [], |
43 | | - "execution_count": 30 |
| 43 | + ] |
44 | 44 | }, |
45 | 45 | { |
46 | 46 | "cell_type": "markdown", |
|
53 | 53 | }, |
54 | 54 | { |
55 | 55 | "cell_type": "code", |
| 56 | + "execution_count": 31, |
56 | 57 | "metadata": { |
57 | 58 | "ExecuteTime": { |
58 | 59 | "end_time": "2025-12-17T19:13:35.382612Z", |
59 | 60 | "start_time": "2025-12-17T19:13:35.367160Z" |
60 | 61 | } |
61 | 62 | }, |
| 63 | + "outputs": [ |
| 64 | + { |
| 65 | + "name": "stdout", |
| 66 | + "output_type": "stream", |
| 67 | + "text": [ |
| 68 | + "Training set size: (426, 30)\n", |
| 69 | + "Test set size: (143, 30)\n", |
| 70 | + "Number of features: 30\n", |
| 71 | + "Classes: [0. 1.]\n" |
| 72 | + ] |
| 73 | + } |
| 74 | + ], |
62 | 75 | "source": [ |
63 | 76 | "# Load breast cancer dataset\n", |
64 | 77 | "X, y = load_breast_cancer(return_X_y=True)\n", |
|
76 | 89 | "print(f\"Test set size: {X_test.shape}\")\n", |
77 | 90 | "print(f\"Number of features: {X_train.shape[1]}\")\n", |
78 | 91 | "print(f\"Classes: {np.unique(y_train)}\")" |
79 | | - ], |
80 | | - "outputs": [ |
81 | | - { |
82 | | - "name": "stdout", |
83 | | - "output_type": "stream", |
84 | | - "text": [ |
85 | | - "Training set size: (426, 30)\n", |
86 | | - "Test set size: (143, 30)\n", |
87 | | - "Number of features: 30\n", |
88 | | - "Classes: [0. 1.]\n" |
89 | | - ] |
90 | | - } |
91 | | - ], |
92 | | - "execution_count": 31 |
| 92 | + ] |
93 | 93 | }, |
94 | 94 | { |
95 | 95 | "cell_type": "markdown", |
|
102 | 102 | }, |
103 | 103 | { |
104 | 104 | "cell_type": "code", |
| 105 | + "execution_count": 32, |
105 | 106 | "metadata": { |
106 | 107 | "ExecuteTime": { |
107 | 108 | "end_time": "2025-12-17T19:13:35.415414Z", |
108 | 109 | "start_time": "2025-12-17T19:13:35.410396Z" |
109 | 110 | } |
110 | 111 | }, |
111 | | - "source": [ |
112 | | - "# Initialize the client\n", |
113 | | - "client = TabularClient(\n", |
114 | | - " base_url=\"https://api.faim.it.com\",\n", |
115 | | - " api_key=os.environ.get(\"FAIM_API_KEY\"), # Replace with your actual API key\n", |
116 | | - " timeout=120.0,\n", |
117 | | - ")\n", |
118 | | - "\n", |
119 | | - "print(\"TabularClient initialized!\")" |
120 | | - ], |
121 | 112 | "outputs": [ |
122 | 113 | { |
123 | 114 | "name": "stdout", |
|
127 | 118 | ] |
128 | 119 | } |
129 | 120 | ], |
130 | | - "execution_count": 32 |
| 121 | + "source": [ |
| 122 | + "# Initialize the client\n", |
| 123 | + "client = TabularClient(\n", |
| 124 | + " base_url=\"https://api.faim.it.com\",\n", |
| 125 | + " api_key=os.environ.get(\"FAIM_API_KEY\"), # Replace with your actual API key\n", |
| 126 | + " timeout=120.0,\n", |
| 127 | + ")\n", |
| 128 | + "\n", |
| 129 | + "print(\"TabularClient initialized!\")" |
| 130 | + ] |
131 | 131 | }, |
132 | 132 | { |
133 | 133 | "cell_type": "markdown", |
|
140 | 140 | }, |
141 | 141 | { |
142 | 142 | "cell_type": "code", |
| 143 | + "execution_count": 33, |
143 | 144 | "metadata": { |
144 | 145 | "ExecuteTime": { |
145 | 146 | "end_time": "2025-12-17T19:13:35.443478Z", |
146 | 147 | "start_time": "2025-12-17T19:13:35.441032Z" |
147 | 148 | } |
148 | 149 | }, |
149 | | - "source": [ |
150 | | - "# Create a LimiX classification request\n", |
151 | | - "request = LimiXPredictRequest(\n", |
152 | | - " X_train=X_train, y_train=y_train, X_test=X_test, task_type=\"Classification\",\n", |
153 | | - ")\n", |
154 | | - "\n", |
155 | | - "print(\"Request prepared:\")\n", |
156 | | - "print(f\" X_train shape: {request.X_train.shape}\")\n", |
157 | | - "print(f\" X_test shape: {request.X_test.shape}\")\n", |
158 | | - "print(f\" Task type: {request.task_type}\")" |
159 | | - ], |
160 | 150 | "outputs": [ |
161 | 151 | { |
162 | 152 | "name": "stdout", |
|
169 | 159 | ] |
170 | 160 | } |
171 | 161 | ], |
172 | | - "execution_count": 33 |
| 162 | + "source": [ |
| 163 | + "# Create a LimiX classification request\n", |
| 164 | + "request = LimiXPredictRequest(\n", |
| 165 | + " X_train=X_train,\n", |
| 166 | + " y_train=y_train,\n", |
| 167 | + " X_test=X_test,\n", |
| 168 | + " task_type=\"Classification\",\n", |
| 169 | + ")\n", |
| 170 | + "\n", |
| 171 | + "print(\"Request prepared:\")\n", |
| 172 | + "print(f\" X_train shape: {request.X_train.shape}\")\n", |
| 173 | + "print(f\" X_test shape: {request.X_test.shape}\")\n", |
| 174 | + "print(f\" Task type: {request.task_type}\")" |
| 175 | + ] |
173 | 176 | }, |
174 | 177 | { |
175 | 178 | "cell_type": "markdown", |
|
182 | 185 | }, |
183 | 186 | { |
184 | 187 | "cell_type": "code", |
| 188 | + "execution_count": 34, |
185 | 189 | "metadata": { |
186 | 190 | "ExecuteTime": { |
187 | 191 | "end_time": "2025-12-17T19:13:36.431619Z", |
188 | 192 | "start_time": "2025-12-17T19:13:35.466839Z" |
189 | 193 | } |
190 | 194 | }, |
191 | | - "source": [ |
192 | | - "try:\n", |
193 | | - " # Make predictions\n", |
194 | | - " response = client.predict(request)\n", |
195 | | - "\n", |
196 | | - " print(f\"Predictions shape: {response.predictions.shape}\")\n", |
197 | | - " print(f\"First 10 predictions: {response.predictions[:10]}\")\n", |
198 | | - "\n", |
199 | | - " if response.probabilities is not None:\n", |
200 | | - " print(f\"\\nClass probabilities shape: {response.probabilities.shape}\")\n", |
201 | | - " print(f\"First 3 samples probabilities:\\n{response.probabilities[:3]}\")\n", |
202 | | - "\n", |
203 | | - " print(\"\\nMetadata:\")\n", |
204 | | - " for key, value in response.metadata.items():\n", |
205 | | - " if key == 'cost_amount':\n", |
206 | | - " value = float(value)/1e6\n", |
207 | | - " print(f\" {key}: {value}\")\n", |
208 | | - "\n", |
209 | | - "except Exception as e:\n", |
210 | | - " print(f\"Error: {e}\")" |
211 | | - ], |
212 | 195 | "outputs": [ |
213 | 196 | { |
214 | 197 | "name": "stdout", |
|
233 | 216 | ] |
234 | 217 | } |
235 | 218 | ], |
236 | | - "execution_count": 34 |
| 219 | + "source": [ |
| 220 | + "try:\n", |
| 221 | + " # Make predictions\n", |
| 222 | + " response = client.predict(request)\n", |
| 223 | + "\n", |
| 224 | + " print(f\"Predictions shape: {response.predictions.shape}\")\n", |
| 225 | + " print(f\"First 10 predictions: {response.predictions[:10]}\")\n", |
| 226 | + "\n", |
| 227 | + " if response.probabilities is not None:\n", |
| 228 | + " print(f\"\\nClass probabilities shape: {response.probabilities.shape}\")\n", |
| 229 | + " print(f\"First 3 samples probabilities:\\n{response.probabilities[:3]}\")\n", |
| 230 | + "\n", |
| 231 | + " print(\"\\nMetadata:\")\n", |
| 232 | + " for key, value in response.metadata.items():\n", |
| 233 | + " if key == \"cost_amount\":\n", |
| 234 | + " value = float(value) / 1e6\n", |
| 235 | + " print(f\" {key}: {value}\")\n", |
| 236 | + "\n", |
| 237 | + "except Exception as e:\n", |
| 238 | + " print(f\"Error: {e}\")" |
| 239 | + ] |
237 | 240 | }, |
238 | 241 | { |
239 | 242 | "cell_type": "markdown", |
|
246 | 249 | }, |
247 | 250 | { |
248 | 251 | "cell_type": "code", |
| 252 | + "execution_count": 35, |
249 | 253 | "metadata": { |
250 | 254 | "ExecuteTime": { |
251 | 255 | "end_time": "2025-12-17T19:13:36.461088Z", |
252 | 256 | "start_time": "2025-12-17T19:13:36.450764Z" |
253 | 257 | } |
254 | 258 | }, |
| 259 | + "outputs": [ |
| 260 | + { |
| 261 | + "name": "stdout", |
| 262 | + "output_type": "stream", |
| 263 | + "text": [ |
| 264 | + "Classification Metrics:\n", |
| 265 | + " Accuracy: 0.9860\n", |
| 266 | + " Precision: 0.9888\n", |
| 267 | + " Recall: 0.9888\n", |
| 268 | + " F1-Score: 0.9888\n" |
| 269 | + ] |
| 270 | + } |
| 271 | + ], |
255 | 272 | "source": [ |
256 | 273 | "from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score\n", |
257 | 274 | "\n", |
|
270 | 287 | " print(f\" F1-Score: {f1:.4f}\")\n", |
271 | 288 | "except NameError:\n", |
272 | 289 | " print(\"Run prediction cell first to evaluate metrics.\")" |
273 | | - ], |
274 | | - "outputs": [ |
275 | | - { |
276 | | - "name": "stdout", |
277 | | - "output_type": "stream", |
278 | | - "text": [ |
279 | | - "Classification Metrics:\n", |
280 | | - " Accuracy: 0.9860\n", |
281 | | - " Precision: 0.9888\n", |
282 | | - " Recall: 0.9888\n", |
283 | | - " F1-Score: 0.9888\n" |
284 | | - ] |
285 | | - } |
286 | | - ], |
287 | | - "execution_count": 35 |
| 290 | + ] |
288 | 291 | } |
289 | 292 | ], |
290 | 293 | "metadata": { |
|
0 commit comments