Разделы презентаций


Train with python. Predict with C++

Содержание

Machine Learning everywhere!MobileEmbeddedAutomotiveDesktopsGamesFinanceEtc.Image from [1]

Слайды и текст этой презентации

Слайд 1Pavel Filonov, C++ Siberia 2019
Train with python. Predict with C++

Pavel Filonov, C++ Siberia 2019Train with python. Predict with C++

Слайд 2Machine Learning everywhere!
Mobile
Embedded
Automotive
Desktops
Games
Finance
Etc.

Image from [1]

Machine Learning everywhere!MobileEmbeddedAutomotiveDesktopsGamesFinanceEtc.Image from [1]

Слайд 3Dream team
Developer
Data Scientist

Dream teamDeveloperData Scientist

Слайд 4Dream team – synergy way
Developer
Data Scientist
Research Developer

Dream team – synergy wayDeveloperData ScientistResearch Developer

Слайд 5Dream team – process way
Developer
Data Scientist
Communications

Dream team – process wayDeveloperData ScientistCommunications

Слайд 6Machine learning sample cases
Energy efficiency prediction
Intrusion detection system
Image classification

Machine learning sample casesEnergy efficiency prediction Intrusion detection systemImage classification

Слайд 7Buildings Energy Efficiency
ref: [2]
Input attributes
Relative Compactness
Surface Area
Wall Area
etc.

Outcomes
Heating Load

Buildings Energy Efficiencyref: [2] Input attributesRelative CompactnessSurface AreaWall Areaetc.OutcomesHeating Load

Слайд 8Regression problem

Regression problem

Слайд 9Regression problem

Regression problem

Слайд 10Regression problem

Regression problem

Слайд 11Quality metric

Quality metric

Слайд 12Baseline model
class Predictor {
public:
    using features = std::vector;

   

virtual ~Predictor() {};
    
    virtual double predict(const features&) const

= 0;
};

class MeanPredictor: public Predictor {
public:
    MeanPredictor(double mean);

    double predict(const features&) const override { return mean_; }

protected:
    double mean_;
};

Baseline modelclass Predictor {public:    using features = std::vector;    virtual ~Predictor() {};        virtual double

Слайд 13Linear regression
class LinregPredictor: public Predictor {
public:
    LinregPredictor(const std::vector&);

   

double predict(const features& feat) const override {
       

assert(feat.size() + 1 == coef_.size());
        return  std::inner_product(feat.begin(), feat.end(), ++coef_.begin(), coef_.front());
    }
    
protected:
    std::vector coef_;
};
Linear regressionclass LinregPredictor: public Predictor {public:    LinregPredictor(const std::vector&);     double predict(const features& feat) const override

Слайд 14Polynomial regression

Polynomial regression

Слайд 15Polynomial regression
class PolyPredictor: public LinregPredictor {
public:
    using LinregPredictor::LinregPredictor;
    
 

  double predict(const features& feat) const override {
     

  features poly_feat{feat};
const auto m = feat.size();
poly_feat.reserve(m*(m+1)/2);
        for (size_t i = 0; i < m; ++i) {
            for (size_t j = i; j < m; ++j) {
                poly_feat.push_back(feat[i]*feat[j]);            
            }
        }   
    return LinregPredictor::predict(poly_feat);    
    }
};
Polynomial regressionclass PolyPredictor: public LinregPredictor {public:    using LinregPredictor::LinregPredictor;        double predict(const features& feat) const override

Слайд 16Integration testing
you always have a lot of data for testing
use

python model output as expected values
beware of floating point arithmetic

problems

TEST(LinregPredictor, compare_to_python) {
    auto predictor = LinregPredictor{coef};
    double y_pred_expected = 0.0;
    std::ifstream test_data{"../train/test_data_linreg.csv"};
    while (read_features(test_data, features)) {
        test_data >> y_pred_expected;
        auto y_pred = predictor.predict(features);
        EXPECT_NEAR(y_pred_expected, y_pred, 1e-4);
    }
}


Слайд 17Intrusion detection system
input - network traffic features
protocol_type
connection duration
src_bytes
dst_bytes
etc.
Output
normal
network attack
ref: [3]

Intrusion detection systeminput - network traffic featuresprotocol_typeconnection durationsrc_bytesdst_bytesetc.Outputnormalnetwork attackref: [3]

Слайд 18Classification problem

Classification problem

Слайд 19Quality metrics
Receive operation characteristics (ROC) curve

Quality metricsReceive operation characteristics (ROC) curve

Слайд 20Baseline model
always predict most frequent class
ROC area under the curve

= 0.5

Baseline modelalways predict most frequent classROC area under the curve = 0.5

Слайд 21Logistic regression

Logistic regression

Слайд 22Logistic regression
easy to implement
template
auto sigma(T z) {
    return

1/(1 + std::exp(-z));
}

class LogregClassifier: public BinaryClassifier {
public:
    float predict_proba(const

features_t& feat) const override {
        auto z = std::inner_product(feat.begin(), feat.end(), ++coef_.begin(), coef_.front());
        return sigma(z);
    }

protected:
    std::vector coef_;
};
Logistic regressioneasy to implementtemplateauto sigma(T z) {    return 1/(1 + std::exp(-z));} class LogregClassifier: public BinaryClassifier {public: 

Слайд 23Gradient boosting
de facto standard universal method
multiple well known C++

implementations with python bindings
XGBoost
LigthGBM
CatBoost
each implementation has its own custom model

format
Gradient boosting de facto standard universal methodmultiple well known C++ implementations with python bindingsXGBoostLigthGBMCatBoosteach implementation has its

Слайд 24CatBoost
C API and C++ wrapper
own build system (ymake)
class CatboostClassifier: public

BinaryClassifier {
public:
    CatboostClassifier(const std::string& modepath);
    ~CatboostClassifier() override;
    
 

  double predict_proba(const features_t& feat) const override {
        double result = 0.0;
        if (!CalcModelPredictionSingle(model_, feat.data(), feat.size(), nullptr, 0, &result, 1)) {
            throw std::runtime_error{"CalcModelPredictionFlat error message:" + GetErrorString()};
        }
        return result;
    }
private:
    ModelCalcerHandle* model_;
}
CatBoostC API and C++ wrapperown build system (ymake)class CatboostClassifier: public BinaryClassifier {public:    CatboostClassifier(const std::string& modepath);   

Слайд 25CatBoost
ROC-AUC = 0.9999

CatBoostROC-AUC = 0.9999

Слайд 26Image classification
Handwritten digits recognizer – MNIST
input – gray-scale pixels 28x28
output

– digit on picture (0, 1, … 9)

Image classificationHandwritten digits recognizer – MNISTinput – gray-scale pixels 28x28output – digit on picture (0, 1, …

Слайд 27Multilayer perceptron
Image from: [4]

Multilayer perceptronImage from: [4]

Слайд 28Quality metrics

Quality metrics

Слайд 29Multilayer perceptron
auto MlpClassifier::predict_proba(const features_t& feat) const {
    VectorXf x{feat.size()};

 

  auto o1 = sigmav(w1_ * x);
    auto o2

= softmax(w2_ * o1);

    return o2;
}
Multilayer perceptronauto MlpClassifier::predict_proba(const features_t& feat) const {    VectorXf x{feat.size()};    auto o1 = sigmav(w1_ * x); 

Слайд 30Convolutional networks
State of the Art algorithms in image processing
a lot

of C++ implementation with python bindings
TensorFlow
Caffe
MXNet
CNTK

Convolutional networksState of the Art algorithms in image processinga lot of C++ implementation with python bindingsTensorFlowCaffeMXNetCNTK

Слайд 31Tensorflow
C++ API
Bazel build system
Hint – prebuild C API

TensorflowC++ APIBazel build systemHint – prebuild C API

Слайд 32Conclusion
Don’t be fear of the ML
Try simpler things first
Get benefits

from different languages

ConclusionDon’t be fear of the MLTry simpler things firstGet benefits from different languages

Слайд 33References
Andrew Ng, Machine Learning – coursera
Energy efficiency Data Set
KDD Cup

1999
MNIST training with Multi Layer Perceptron
Code samples

ReferencesAndrew Ng, Machine Learning – courseraEnergy efficiency Data SetKDD Cup 1999MNIST training with Multi Layer PerceptronCode samples

Слайд 34Let’s Talk?

Let’s Talk?

Обратная связь

Если не удалось найти и скачать доклад-презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:

Email: Нажмите что бы посмотреть 

Что такое TheSlide.ru?

Это сайт презентации, докладов, проектов в PowerPoint. Здесь удобно  хранить и делиться своими презентациями с другими пользователями.


Для правообладателей

Яндекс.Метрика