-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetSummaryDataView() implementation for Pca and Linear Predictors #185
Changes from 2 commits
ec890d6
9394cdd
b508e68
e072546
ec8200a
cf37f62
9943586
45cd5f2
083645f
58d0f31
c5c0173
695abc5
eea9c69
637b325
bdec903
b942537
678633c
3031a4c
b0c2e49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,6 +308,7 @@ public static CommonOutputs.AnomalyDetectionOutput TrainPcaAnomaly(IHostEnvironm | |
// REVIEW: move the predictor to a different file and fold EigenUtils.cs to this file. | ||
public sealed class PcaPredictor : PredictorBase<Float>, | ||
IValueMapper, | ||
ICanGetSummaryAsIDataView, | ||
ICanSaveInTextFormat, ICanSaveModel, ICanSaveSummary | ||
{ | ||
public const string LoaderSignature = "pcaAnomExec"; | ||
|
@@ -469,6 +470,20 @@ public void SaveAsText(TextWriter writer, RoleMappedSchema schema) | |
} | ||
} | ||
|
||
public IDataView GetSummaryDataView(RoleMappedSchema schema) | ||
{ | ||
var bldr = new ArrayDataViewBuilder(Host); | ||
|
||
bldr.AddColumn("Mean vector", NumberType.R4, _mean); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
While not explicitly prescribed, elsewhere we have held to the convention that these names ought to be valid C# identifiers... which is to say, |
||
bldr.AddColumn("Projected mean vector", NumberType.R4, _meanProjected); | ||
for (var i = 0; i < _rank; ++i) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For single line statements like this, prefer this: for (int i=0; I<foo; ++i)
yodawg += i; to this for (int i=0; I<foo; ++i)
{
yodawg += i;
} Those extra Edit: for one line statements, to be clear. I'm not a monster. #Closed |
||
bldr.AddColumn("V" + i, NumberType.R4, _eigenVectors[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This should be added as a single vector column, each eigenvector in one row. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Either this should be a single multidimensional vectror column (with In reply to: 189336699 [](ancestors = 189336699) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added as a single vector column |
||
} | ||
|
||
return bldr.GetDataView(); | ||
} | ||
|
||
public ColumnType InputType | ||
{ | ||
get { return _inputType; } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ public abstract class LinearPredictor : PredictorBase<Float>, | |
ICanSaveInTextFormat, | ||
ICanSaveInSourceCode, | ||
ICanSaveModel, | ||
ICanGetSummaryAsIDataView, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks Gani for making this change. Please take a look at these two classes inheriting from this class: LinearBinaryPredictor and LinearRegressionPredictor. They implement an interface called ICanGetSummaryAsIRow which this class should implement instead of ICanGetSummaryAsDataView. #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thx, this is done |
||
ICanSaveSummary, | ||
IPredictorWithFeatureWeights<Float>, | ||
IWhatTheFeatureValueMapper, | ||
|
@@ -343,6 +344,20 @@ public void SaveAsCode(TextWriter writer, RoleMappedSchema schema) | |
|
||
public abstract void SaveSummary(TextWriter writer, RoleMappedSchema schema); | ||
|
||
public IDataView GetSummaryDataView(RoleMappedSchema schema) | ||
{ | ||
var bldr = new ArrayDataViewBuilder(Host); | ||
|
||
ValueGetter<VBuffer<DvText>> getSlotNames = | ||
(ref VBuffer<DvText> dst) => | ||
MetadataUtils.GetSlotNames(schema, RoleMappedSchema.ColumnRole.Feature, Weight.Count, ref dst); | ||
|
||
// Add the bias and the weight columns. | ||
bldr.AddColumn("Bias", NumberType.R4, Bias); | ||
bldr.AddColumn("Weights", getSlotNames, NumberType.R4, Weight); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This will try to create a scalar column with multiple rows, and will not work because the bias column has only one row. #Closed |
||
return bldr.GetDataView(); | ||
} | ||
|
||
public abstract void SaveAsIni(TextWriter writer, RoleMappedSchema schema, ICalibrator calibrator = null); | ||
|
||
public virtual void GetFeatureWeights(ref VBuffer<Float> weights) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a unit test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added