|
53 | 53 | "\n", |
54 | 54 | "- [`Microsoft.ML`](https://www.nuget.org/packages/Microsoft.ML/)\n", |
55 | 55 | "- [`Microsoft.ML.TorchSharp`](https://www.nuget.org/packages/Microsoft.ML.TorchSharp/)\n", |
56 | | - "- [`TorchSharp-cpu`](https://www.nuget.org/packages/TorchSharp-cpu/) if you're using a CPU or [`TorchSharp-cuda-windows`](https://www.nuget.org/packages/TorchSharp-cuda-windows/) / [`TorchSharp-cuda-linux`](https://www.nuget.org/packages/TorchSharp-cuda-linux/) if you're using a GPU." |
| 56 | + "- [`TorchSharp-cpu`](https://www.nuget.org/packages/TorchSharp-cpu/) if you're using a CPU or [`TorchSharp-cuda-windows`](https://www.nuget.org/packages/TorchSharp-cuda-windows/) / [`TorchSharp-cuda-linux`](https://www.nuget.org/packages/TorchSharp-cuda-linux/) if you're using a GPU.\n", |
| 57 | + "\n", |
| 58 | + "To enable GPU support, you'll also have to install the CUDA dependencies. For more information, see the [GPU support guide](https://docs.microsoft.com/dotnet/machine-learning/how-to-guides/install-gpu-model-builder#install-dependencies)." |
57 | 59 | ] |
58 | 60 | }, |
59 | 61 | { |
|
65 | 67 | } |
66 | 68 | }, |
67 | 69 | "source": [ |
68 | | - "#r \"nuget:Microsoft.ML,2.0.0-preview.22313.1\"\n", |
69 | | - "#r \"nuget:Microsoft.ML.TorchSharp,0.20.0-preview.22313.1\"\n", |
| 70 | + "#i \"nuget:https://pkgs.dev.azure.com/dnceng/public/_packaging/MachineLearning/nuget/v3/index.json\"\n", |
| 71 | + "\n", |
| 72 | + "#r \"nuget:Microsoft.ML,2.0.0-preview.22324.1\"\n", |
| 73 | + "#r \"nuget:Microsoft.ML.TorchSharp,0.20.0-preview.22324.1\"\n", |
70 | 74 | "#r \"nuget:TorchSharp-cpu,0.96.7\"\n", |
71 | | - "#r \"nuget:Microsoft.Data.Analysis,0.20.0-preview.22313.1\"" |
| 75 | + "#r \"nuget:Microsoft.Data.Analysis,0.20.0-preview.22324.1\"" |
72 | 76 | ], |
73 | 77 | "outputs": [ |
74 | 78 | { |
75 | 79 | "output_type": "execute_result", |
76 | 80 | "data": { |
77 | | - "text/html": "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.Data.Analysis, 0.20.0-preview.22313.1</span></li><li><span>Microsoft.ML, 2.0.0-preview.22313.1</span></li><li><span>Microsoft.ML.TorchSharp, 0.20.0-preview.22313.1</span></li><li><span>TorchSharp-cpu, 0.96.7</span></li></ul></div></div>" |
| 81 | + "text/html": "<div><div><strong>Restore sources</strong><ul><li><span>https://pkgs.dev.azure.com/dnceng/public/_packaging/MachineLearning/nuget/v3/index.json</span></li></ul></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.Data.Analysis, 0.20.0-preview.22324.1</span></li><li><span>Microsoft.ML, 2.0.0-preview.22324.1</span></li><li><span>Microsoft.ML.TorchSharp, 0.20.0-preview.22324.1</span></li><li><span>TorchSharp-cpu, 0.96.7</span></li></ul></div></div>" |
78 | 82 | }, |
79 | 83 | "execution_count": 1, |
80 | 84 | "metadata": {} |
|
205 | 209 | { |
206 | 210 | "output_type": "execute_result", |
207 | 211 | "data": { |
208 | | - "text/html": "<table id=\"table_637907545650178735\"><thead><tr><th><i>index</i></th><th>Text</th><th>Sentiment</th></tr></thead><tbody><tr><td><i><div class=\"dni-plaintext\">0</div></i></td><td>Wow... Loved this place.</td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">1</div></i></td><td>Crust is not good.</td><td><div class=\"dni-plaintext\">0</div></td></tr><tr><td><i><div class=\"dni-plaintext\">2</div></i></td><td>Not tasty and the texture was just nasty.</td><td><div class=\"dni-plaintext\">0</div></td></tr></tbody></table>" |
| 212 | + "text/html": "<table id=\"table_637919371773035870\"><thead><tr><th><i>index</i></th><th>Text</th><th>Sentiment</th></tr></thead><tbody><tr><td><i><div class=\"dni-plaintext\">0</div></i></td><td>Wow... Loved this place.</td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">1</div></i></td><td>Crust is not good.</td><td><div class=\"dni-plaintext\">0</div></td></tr><tr><td><i><div class=\"dni-plaintext\">2</div></i></td><td>Not tasty and the texture was just nasty.</td><td><div class=\"dni-plaintext\">0</div></td></tr></tbody></table>" |
209 | 213 | }, |
210 | 214 | "execution_count": 1, |
211 | 215 | "metadata": {} |
|
268 | 272 | "source": [ |
269 | 273 | "var pipeline =\n", |
270 | 274 | "\t\tmlContext.Transforms.Conversion.MapValueToKey(\"Label\",\"Sentiment\")\n", |
271 | | - "\t\t\t.Append(mlContext.MulticlassClassification.Trainers.TextClassification(numberOfClasses: 2, sentence1ColumnName: \"Text\"))\n", |
| 275 | + "\t\t\t.Append(mlContext.MulticlassClassification.Trainers.TextClassification(sentence1ColumnName: \"Text\"))\n", |
272 | 276 | "\t\t\t.Append(mlContext.Transforms.Conversion.MapKeyToValue(\"PredictedLabel\"));" |
273 | 277 | ], |
274 | 278 | "outputs": [] |
|
361 | 365 | { |
362 | 366 | "output_type": "execute_result", |
363 | 367 | "data": { |
364 | | - "text/html": "<table id=\"table_637907582471037219\"><thead><tr><th><i>index</i></th><th>Text</th><th>Sentiment</th><th>PredictedLabel</th></tr></thead><tbody><tr><td><i><div class=\"dni-plaintext\">0</div></i></td><td>Oh this is such a thing of beauty, this restaurant.</td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">1</div></i></td><td>A greasy, unhealthy meal.</td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">2</div></i></td><td>The best place in Vegas for breakfast (just check out a Sat, or Sun.</td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">1</div></td></tr></tbody></table>" |
| 368 | + "text/html": "<table id=\"table_637919373979111360\"><thead><tr><th><i>index</i></th><th>Text</th><th>Sentiment</th><th>PredictedLabel</th></tr></thead><tbody><tr><td><i><div class=\"dni-plaintext\">0</div></i></td><td>Oh this is such a thing of beauty, this restaurant.</td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">0</div></td></tr><tr><td><i><div class=\"dni-plaintext\">1</div></i></td><td>A greasy, unhealthy meal.</td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">2</div></i></td><td>The best place in Vegas for breakfast (just check out a Sat, or Sun.</td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">1</div></td></tr></tbody></table>" |
365 | 369 | }, |
366 | 370 | "execution_count": 1, |
367 | 371 | "metadata": {} |
|
379 | 383 | "cell_type": "markdown", |
380 | 384 | "metadata": {}, |
381 | 385 | "source": [ |
382 | | - "There's a variety of metrics you can use to evaluate how well your model performs. In this case, you'll calculate the model's accuracy. \n", |
383 | | - "\n", |
384 | | - "Start by taking the instances where the actual value matches the predicted value, also known as the true positives (TP) and true negatives (TN)." |
| 386 | + "There's a variety of metrics you can use to evaluate how well your model performs. Use the [Evaluate](https://docs.microsoft.com/dotnet/api/microsoft.ml.multiclassclassificationcatalog.evaluate?view=ml-dotnet) method to calculate the evaluation metrics for your model using the predictions `IDataView`." |
385 | 387 | ] |
386 | 388 | }, |
387 | 389 | { |
|
393 | 395 | } |
394 | 396 | }, |
395 | 397 | "source": [ |
396 | | - "var tptn = \n", |
397 | | - "\tpredictions.Filter(\n", |
398 | | - "\t\tpredictions[\"Sentiment\"].ElementwiseEquals(predictions[\"PredictedLabel\"]));" |
| 398 | + "var evaluationMetrics = \n", |
| 399 | + "\tmlContext\n", |
| 400 | + "\t\t.MulticlassClassification\n", |
| 401 | + "\t\t.Evaluate(predictionIDV);" |
399 | 402 | ], |
400 | 403 | "outputs": [] |
401 | 404 | }, |
402 | 405 | { |
403 | 406 | "cell_type": "markdown", |
404 | 407 | "metadata": {}, |
405 | 408 | "source": [ |
406 | | - "Then, divide the number of instances where the actual value matches the predicted value by the total number of predictions. " |
| 409 | + "Then, display the evaluation metrics. For more information on multiclass classification evaluation metrics, see the [ML.NET evaluation metrics guide](https://docs.microsoft.com/dotnet/machine-learning/resources/metrics#evaluation-metrics-for-multi-class-classification)." |
407 | 410 | ] |
408 | 411 | }, |
409 | 412 | { |
|
415 | 418 | } |
416 | 419 | }, |
417 | 420 | "source": [ |
418 | | - "var accuracy = ((float) tptn.Rows.Count / (float) predictions.Rows.Count);\n", |
419 | | - "\n", |
420 | | - "$\"Accuracy: {accuracy:0.####}\"" |
| 421 | + "evaluationMetrics" |
421 | 422 | ], |
422 | 423 | "outputs": [ |
423 | 424 | { |
424 | 425 | "output_type": "execute_result", |
425 | 426 | "data": { |
426 | | - "text/plain": "Accuracy: 0.56" |
| 427 | + "text/html": "<table><thead><tr><th>LogLoss</th><th>LogLossReduction</th><th>MacroAccuracy</th><th>MicroAccuracy</th><th>TopKAccuracy</th><th>TopKPredictionCount</th><th>TopKAccuracyForAllK</th><th>PerClassLogLoss</th><th>ConfusionMatrix</th></tr></thead><tbody><tr><td><div class=\"dni-plaintext\">10.53512863047496</div></td><td><div class=\"dni-plaintext\">-14.199291365827746</div></td><td><div class=\"dni-plaintext\">0.6737016700983757</div></td><td><div class=\"dni-plaintext\">0.6737967914438503</div></td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\"><null></div></td><td><div class=\"dni-plaintext\">[ 10.940300196581468, 10.134267400178105 ]</div></td><td><div class=\"dni-plaintext\">{ Microsoft.ML.Data.ConfusionMatrix: PerClassPrecision: [ 0.6777777777777778, 0.6701030927835051 ], PerClassRecall: [ 0.6559139784946236, 0.6914893617021277 ], Counts: [ [ 61, 32 ], [ 29, 65 ] ], NumberOfClasses: 2 }</div></td></tr></tbody></table>" |
427 | 428 | }, |
428 | 429 | "execution_count": 1, |
429 | 430 | "metadata": {} |
|
0 commit comments