-
Notifications
You must be signed in to change notification settings - Fork 62
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
Introduce classification analysis runner. #701
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6ef21aa
Make CDataFrameBoostedTreeRunner class abstract and derive two subcla…
przemekwitek 56248b1
Apply review comments
przemekwitek d3bec86
Add unit tests
przemekwitek 97ae2ae
Apply review comments
przemekwitek be76552
Fix compile error and apply clang-format
przemekwitek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
#ifndef INCLUDED_ml_api_CDataFrameClassificationRunner_h | ||
#define INCLUDED_ml_api_CDataFrameClassificationRunner_h | ||
|
||
#include <core/CDataSearcher.h> | ||
|
||
#include <api/CDataFrameAnalysisConfigReader.h> | ||
#include <api/CDataFrameAnalysisRunner.h> | ||
#include <api/CDataFrameAnalysisSpecification.h> | ||
#include <api/CDataFrameBoostedTreeRunner.h> | ||
#include <api/ImportExport.h> | ||
|
||
#include <rapidjson/fwd.h> | ||
|
||
#include <atomic> | ||
|
||
namespace ml { | ||
namespace api { | ||
|
||
//! \brief Runs boosted tree classification on a core::CDataFrame. | ||
class API_EXPORT CDataFrameClassificationRunner final : public CDataFrameBoostedTreeRunner { | ||
public: | ||
static const CDataFrameAnalysisConfigReader getParameterReader(); | ||
|
||
//! This is not intended to be called directly: use CDataFrameClassificationRunnerFactory. | ||
CDataFrameClassificationRunner(const CDataFrameAnalysisSpecification& spec, | ||
const CDataFrameAnalysisConfigReader::CParameters& parameters); | ||
|
||
//! This is not intended to be called directly: use CDataFrameClassificationRunnerFactory. | ||
CDataFrameClassificationRunner(const CDataFrameAnalysisSpecification& spec); | ||
|
||
//! \return Indicator of columns for which empty value should be treated as missing. | ||
TBoolVec columnsForWhichEmptyIsMissing(const TStrVec& fieldNames) const override; | ||
|
||
//! Write the prediction for \p row to \p writer. | ||
void writeOneRow(const TStrVec& featureNames, | ||
const TStrVecVec& categoricalFieldValues, | ||
TRowRef row, | ||
core::CRapidJsonConcurrentLineWriter& writer) const override; | ||
|
||
private: | ||
std::size_t m_NumTopClasses; | ||
}; | ||
|
||
//! \brief Makes a core::CDataFrame boosted tree classification runner. | ||
class API_EXPORT CDataFrameClassificationRunnerFactory final | ||
: public CDataFrameAnalysisRunnerFactory { | ||
public: | ||
const std::string& name() const override; | ||
|
||
private: | ||
static const std::string NAME; | ||
|
||
private: | ||
TRunnerUPtr makeImpl(const CDataFrameAnalysisSpecification& spec) const override; | ||
TRunnerUPtr makeImpl(const CDataFrameAnalysisSpecification& spec, | ||
const rapidjson::Value& jsonParameters) const override; | ||
}; | ||
} | ||
} | ||
|
||
#endif // INCLUDED_ml_api_CDataFrameClassificationRunner_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
#ifndef INCLUDED_ml_api_CDataFrameRegressionRunner_h | ||
#define INCLUDED_ml_api_CDataFrameRegressionRunner_h | ||
|
||
#include <core/CDataSearcher.h> | ||
|
||
#include <api/CDataFrameAnalysisConfigReader.h> | ||
#include <api/CDataFrameAnalysisSpecification.h> | ||
#include <api/CDataFrameBoostedTreeRunner.h> | ||
#include <api/ImportExport.h> | ||
|
||
#include <rapidjson/fwd.h> | ||
|
||
#include <atomic> | ||
|
||
namespace ml { | ||
namespace api { | ||
|
||
//! \brief Runs boosted tree regression on a core::CDataFrame. | ||
class API_EXPORT CDataFrameRegressionRunner final : public CDataFrameBoostedTreeRunner { | ||
public: | ||
static const CDataFrameAnalysisConfigReader getParameterReader(); | ||
|
||
//! This is not intended to be called directly: use CDataFrameRegressionRunnerFactory. | ||
CDataFrameRegressionRunner(const CDataFrameAnalysisSpecification& spec, | ||
const CDataFrameAnalysisConfigReader::CParameters& parameters); | ||
|
||
//! This is not intended to be called directly: use CDataFrameRegressionRunnerFactory. | ||
CDataFrameRegressionRunner(const CDataFrameAnalysisSpecification& spec); | ||
|
||
//! Write the prediction for \p row to \p writer. | ||
void writeOneRow(const TStrVec& featureNames, | ||
const TStrVecVec& categoricalFieldValues, | ||
TRowRef row, | ||
core::CRapidJsonConcurrentLineWriter& writer) const override; | ||
}; | ||
|
||
//! \brief Makes a core::CDataFrame boosted tree regression runner. | ||
class API_EXPORT CDataFrameRegressionRunnerFactory final : public CDataFrameAnalysisRunnerFactory { | ||
public: | ||
const std::string& name() const override; | ||
|
||
private: | ||
static const std::string NAME; | ||
|
||
private: | ||
TRunnerUPtr makeImpl(const CDataFrameAnalysisSpecification& spec) const override; | ||
TRunnerUPtr makeImpl(const CDataFrameAnalysisSpecification& spec, | ||
const rapidjson::Value& jsonParameters) const override; | ||
}; | ||
} | ||
} | ||
|
||
#endif // INCLUDED_ml_api_CDataFrameRegressionRunner_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: can we move before private typedefs as per coding standards
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.
Done.