Skip to content

Commit c03eef7

Browse files
authored
Merge pull request #5223 from dotnet/master
update live from master
2 parents 42b1a1e + 523c3d3 commit c03eef7

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

docs/machine-learning/tutorials/sentiment-analysis.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ You need to create two global variables to hold the path to the recently downloa
101101
Add the following code to the line right above the `Main` method:
102102

103103
```csharp
104-
const string _dataPath = @"..\..\data\sentiment labelled sentences\imdb_labelled.txt";
105-
const string _testDataPath = @"..\..\data\sentiment labelled sentences\yelp_labelled.txt";
104+
const string _dataPath = @"..\..\..\data\imdb_labelled.txt";
105+
const string _testDataPath = @"..\..\..\data\yelp_labelled.txt";
106106
```
107107

108108
You need to create some classes for your input data and predictions. Add a new class to your project:
@@ -122,8 +122,9 @@ Add the following code, which has two classes `SentimentData` and `SentimentPred
122122
```csharp
123123
public class SentimentData
124124
{
125+
[Column(ordinal: "0")]
125126
public string SentimentText;
126-
[ColumnName("Label")]
127+
[Column(ordinal: "1", name: "Label")]
127128
public float Sentiment;
128129
}
129130

@@ -134,7 +135,7 @@ public class SentimentPrediction
134135
}
135136
```
136137

137-
`SentimentData` is the input dataset class and has a string for the comment (`SentimentText`), a boolean (`Sentiment`) that has a value for sentiment of either positive or negative, and a `Label` `ColumnName` attribute. `SentimentPrediction` is the class used for prediction after the model has been trained. It has a single boolean (`Sentiment`) and a `PredictedLabel` `ColumnName` attribute. The `Label` is used to create and train the model, and it's also used with a second dataset to evaluate the model. The `PredictedLabel` is used during prediction and evaluation. For evaluation, an input with training data, the predicted values, and the model are used.
138+
`SentimentData` is the input dataset class and has a string for the comment (`SentimentText`), a `float` (`Sentiment`) that has a value for sentiment of either positive or negative. Both fields have `Column` attributes attached to them. This attribute describes the order of each field in the data file, and which is the `Label` field. `SentimentPrediction` is the class used for prediction after the model has been trained. It has a single boolean (`Sentiment`) and a `PredictedLabel` `ColumnName` attribute. The `Label` is used to create and train the model, and it's also used with a second dataset to evaluate the model. The `PredictedLabel` is used during prediction and evaluation. For evaluation, an input with training data, the predicted values, and the model are used.
138139

139140
In the *Program.cs* file, replace the `Console.WriteLine("Hello World!")` line with the following code in the `Main` method:
140141

@@ -169,7 +170,7 @@ var pipeline = new LearningPipeline();
169170
The <xref:Microsoft.ML.TextLoader%601> object is the first part of the pipeline, and loads the training file data.
170171

171172
```csharp
172-
pipeline.Add(new TextLoader<SentimentData>(_dataPath, header: false, sep: "tab"));
173+
pipeline.Add(new TextLoader<SentimentData>(_dataPath, useHeader: false, separator: "tab"));
173174
```
174175

175176
## Data preprocess and feature engineering
@@ -299,7 +300,7 @@ Evaluate(model);
299300
The <xref:Microsoft.ML.TextLoader%601> class loads the new test dataset with the same schema. You can evaluate the model using this dataset as a quality check. Add that next to the `Evaluate` method call, using the following code:
300301

301302
```csharp
302-
var testData = new TextLoader<SentimentData>(_testDataPath, header: false, sep: "tab");
303+
var testData = new TextLoader<SentimentData>(_testDataPath, useHeader: false, separator: "tab");
303304
```
304305

305306
The <xref:Microsoft.ML.Models.BinaryClassificationEvaluator> object computes the quality metrics for the `PredictionModel` using the specified dataset. To see those metrics, add the evaluator as the next line in the `Evaluate` method, with the following code:

docs/machine-learning/tutorials/taxi-fare.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,25 @@ Next, create classes for the input data and the predictions:
105105
using Microsoft.ML.Runtime.Api;
106106
```
107107

108-
Add two classes into this file. `TaxiTrip`, the input data set class, has definitions for each of the columns discovered above and a `Label` `ColumnName` attribute. Add the following code to the file:
108+
Add two classes into this file. `TaxiTrip`, the input data set class, has definitions for each of the columns discovered above and a `Label` attribute for the fare_amount column that you are predicting. Add the following code to the file:
109109

110110
```csharp
111111
public class TaxiTrip
112112
{
113+
[Column(ordinal: "0")]
113114
public string vendor_id;
115+
[Column(ordinal: "1")]
114116
public string rate_code;
117+
[Column(ordinal: "2")]
115118
public float passenger_count;
119+
[Column(ordinal: "3")]
116120
public float trip_time_in_secs;
121+
[Column(ordinal: "4")]
117122
public float trip_distance;
123+
[Column(ordinal: "5")]
118124
public string payment_type;
125+
[Column(ordinal: "6", "Label")]
119126
public float fare_amount;
120-
121-
[ColumnName("Label")]
122-
public float Label;
123127
}
124128
```
125129

0 commit comments

Comments
 (0)