Skip to content
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

Change format of MulticlassConfusionMatrix result to be more self-explanatory #48174

Merged

Conversation

przemekwitek
Copy link
Contributor

Current MulticlassConfusionMatrix result can be confusing to the API user.
They have no means to tell if the outer map is actual or predicted. Similarly for inner map.

This PR fixes that by making the format strict (naming each field).

Relates #46735

@przemekwitek przemekwitek force-pushed the revamp_multiclass_confusion_matrix branch from 66e1005 to 071cbd7 Compare October 17, 2019 08:45
@przemekwitek przemekwitek removed the WIP label Oct 17, 2019
@przemekwitek przemekwitek force-pushed the revamp_multiclass_confusion_matrix branch from 071cbd7 to fa6ab5b Compare October 17, 2019 08:52
@przemekwitek przemekwitek marked this pull request as ready for review October 17, 2019 08:53
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core (:ml)

@przemekwitek
Copy link
Contributor Author

run elasticsearch-ci/packaging-sample-matrix

@przemekwitek przemekwitek force-pushed the revamp_multiclass_confusion_matrix branch 4 times, most recently from 4ce3aa3 to 97628e2 Compare October 18, 2019 07:11
@przemekwitek
Copy link
Contributor Author

przemekwitek commented Oct 18, 2019

@elasticmachine update branch

1 similar comment
@przemekwitek
Copy link
Contributor Author

@elasticmachine update branch

@przemekwitek przemekwitek force-pushed the revamp_multiclass_confusion_matrix branch 2 times, most recently from 2fd6087 to dfecdf6 Compare October 18, 2019 08:56
@benwtrent benwtrent self-requested a review October 18, 2019 13:17
Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the new format. It also gives us flexibility to add new fields in the future if we deem them necessary.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(PREDICTED_CLASS.getPreferredName(), predictedClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the ctor, both of these are nullable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

String actualClass, long actualClassDocCount, List<PredictedClass> predictedClasses, long otherPredictedClassDocCount) {
this.actualClass = actualClass;
this.actualClassDocCount = actualClassDocCount;
this.predictedClasses = Collections.unmodifiableList(predictedClasses);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be nullable? I think it would throw if predictedClasses == null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

this.otherClassesCount = otherClassesCount;
public Result(List<ActualClass> actualClasses, long otherActualClassCount) {
this.actualClasses = Collections.unmodifiableList(Objects.requireNonNull(actualClasses));
this.otherActualClassCount = otherActualClassCount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to do a otherActualClassCount >= 0 check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

in.readMap(StreamInput::readString, in2 -> in2.readMap(StreamInput::readString, StreamInput::readLong)));
this.otherClassesCount = in.readLong();
this.actualClasses = Collections.unmodifiableList(in.readList(ActualClass::new));
this.otherActualClassCount = in.readLong();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.otherActualClassCount = in.readLong();
this.otherActualClassCount = in.readVLong();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(actualClass);
out.writeLong(actualClassDocCount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out.writeLong(actualClassDocCount);
out.writeVLong(actualClassDocCount);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


public PredictedClass(StreamInput in) throws IOException {
this.predictedClass = in.readString();
this.count = in.readLong();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.count = in.readLong();
this.count = in.readVLong();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(predictedClass);
out.writeLong(count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out.writeLong(count);
out.writeVLong(count);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

private final long count;

public PredictedClass(String predictedClass, long count) {
this.predictedClass = predictedClass;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


public PredictedClass(String predictedClass, long count) {
this.predictedClass = predictedClass;
this.count = count;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>= 0 check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@przemekwitek przemekwitek force-pushed the revamp_multiclass_confusion_matrix branch 2 times, most recently from cc20654 to 9b1c359 Compare October 21, 2019 08:28
@przemekwitek
Copy link
Contributor Author

run elasticsearch-ci/packaging-sample-matrix

@przemekwitek przemekwitek force-pushed the revamp_multiclass_confusion_matrix branch from 9b1c359 to 92a6dd4 Compare October 21, 2019 09:36
@przemekwitek
Copy link
Contributor Author

run elasticsearch-ci/packaging-sample-matrix

@przemekwitek przemekwitek merged commit c9fea1e into elastic:master Oct 21, 2019
@przemekwitek przemekwitek deleted the revamp_multiclass_confusion_matrix branch October 21, 2019 12:36
przemekwitek added a commit to przemekwitek/elasticsearch that referenced this pull request Oct 21, 2019
przemekwitek added a commit to przemekwitek/elasticsearch that referenced this pull request Oct 21, 2019
przemekwitek added a commit that referenced this pull request Oct 21, 2019
przemekwitek added a commit that referenced this pull request Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants