Skip to content

[ML] calculate feature importance for multi-class results #1071

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

Merged
merged 10 commits into from
Mar 23, 2020
Merged

[ML] calculate feature importance for multi-class results #1071

merged 10 commits into from
Mar 23, 2020

Conversation

benwtrent
Copy link
Member

@benwtrent benwtrent commented Mar 19, 2020

Feature importance is already calculated for multi-class models. This commit adjusts the output sent to ES so that multi-class importance can be explored.

Feature importance objects are now mapped as follows
(logistic) Regression:

{
   "feature_name": "feature_0",
   "importance": -1.3
}

Multi-class [class names are foo, bar, baz]

{ 
   “feature_name”: “feature_0”, 
   “importance”: 2.0, // sum(abs()) of class importances
   “foo”: 1.0, 
   “bar”: 0.5, 
   “baz”: -0.5 
},

Java side change: elastic/elasticsearch#53803

@benwtrent benwtrent marked this pull request as ready for review March 20, 2020 12:40
@benwtrent
Copy link
Member Author

Ugh, windows build failed due to

CDataFrameAnalyzerFeatureImportanceTest.obj : error LNK2019: unresolved external symbol "public: static class ml::maths::CDenseVector<double> __cdecl ml::maths::CTools::softmax<double>(class ml::maths::CDenseVector<double>)" (??$softmax@N@CTools@maths@ml@@SA?AV?$CDenseVector@N@12@V312@@Z) referenced in function "public: class ml::maths::CDenseVector<double> __cdecl <lambda_c8f0b938f55e935ee669e05079912d7a>::operator()(class std::vector<double,class std::allocator<double> > const &)const " (??R<lambda_c8f0b938f55e935ee669e05079912d7a>@@QEBA?AV?$CDenseVector@N@maths@ml@@AEBV?$vector@NV?$allocator@N@std@@@std@@@Z)
ml_test.exe : fatal error LNK1120: 1 unresolved externals

I suppose I need to update the make file or something?

Tests ran and passed locally without issues though :(

Copy link
Contributor

@tveasey tveasey left a comment

Choose a reason for hiding this comment

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

Overall looks good Ben! Just some minor comments.

For the compilation failure you just need to add #include <maths/CToolsDetail.h> in CDataFrameAnalyzerFeatureImportanceTest.cc.

@benwtrent benwtrent requested a review from tveasey March 23, 2020 12:25
Copy link
Contributor

@tveasey tveasey left a comment

Choose a reason for hiding this comment

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

LGTM

@benwtrent benwtrent merged commit 20aab00 into elastic:master Mar 23, 2020
@benwtrent benwtrent deleted the feature/ml-change-featureimportance-format branch March 23, 2020 15:42
benwtrent added a commit that referenced this pull request Mar 23, 2020
)

Feature importance is already calculated for multi-class models. This commit adjusts the output sent to ES so that multi-class importance can be explored.

Feature importance objects are now mapped as follows
(logistic) Regression:
```
{
   "feature_name": "feature_0",
   "importance": -1.3
}
```
Multi-class [class names are `foo`, `bar`, `baz`]
```
{ 
   “feature_name”: “feature_0”, 
   “importance”: 2.0, // sum(abs()) of class importances
   “foo”: 1.0, 
   “bar”: 0.5, 
   “baz”: -0.5 
},
```
Java side change: elastic/elasticsearch#53803
benwtrent added a commit to elastic/elasticsearch that referenced this pull request Mar 23, 2020
…3821)

Feature importance storage format is changing to encompass multi-class. 

Feature importance objects are now mapped as follows
(logistic) Regression:
```
{
   "feature_name": "feature_0",
   "importance": -1.3
}
```
Multi-class [class names are `foo`, `bar`, `baz`]
```
{ 
   “feature_name”: “feature_0”, 
   “importance”: 2.0, // sum(abs()) of class importances
   “foo”: 1.0, 
   “bar”: 0.5, 
   “baz”: -0.5 
},
```

This change adjusts the mapping creation for analytics so that the field is mapped as a `nested` type. 

Native side change: elastic/ml-cpp#1071
benwtrent added a commit to benwtrent/elasticsearch that referenced this pull request Mar 23, 2020
…astic#53821)

Feature importance storage format is changing to encompass multi-class.

Feature importance objects are now mapped as follows
(logistic) Regression:
```
{
   "feature_name": "feature_0",
   "importance": -1.3
}
```
Multi-class [class names are `foo`, `bar`, `baz`]
```
{
   “feature_name”: “feature_0”,
   “importance”: 2.0, // sum(abs()) of class importances
   “foo”: 1.0,
   “bar”: 0.5,
   “baz”: -0.5
},
```

This change adjusts the mapping creation for analytics so that the field is mapped as a `nested` type.

Native side change: elastic/ml-cpp#1071
benwtrent added a commit to elastic/elasticsearch that referenced this pull request Mar 23, 2020
…3821) (#54013)

Feature importance storage format is changing to encompass multi-class.

Feature importance objects are now mapped as follows
(logistic) Regression:
```
{
   "feature_name": "feature_0",
   "importance": -1.3
}
```
Multi-class [class names are `foo`, `bar`, `baz`]
```
{
   “feature_name”: “feature_0”,
   “importance”: 2.0, // sum(abs()) of class importances
   “foo”: 1.0,
   “bar”: 0.5,
   “baz”: -0.5
},
```

This change adjusts the mapping creation for analytics so that the field is mapped as a `nested` type.

Native side change: elastic/ml-cpp#1071
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.

2 participants