Cosan
1.0
Data Analytics Library
modelfittting.cpp
Go to the documentation of this file.
1
//
2
// Created by Xinyu Zhang on 3/26/21.
3
//
4
#include <iostream>
5
#include <
cosan/data/CosanData.h
>
6
#include <
cosan/base/CosanBO.h
>
7
#include <
cosan/preprocessing/overunderflow.h
>
8
#include <
cosan/preprocessing/missingvalues.h
>
9
#include <
cosan/preprocessing/normalizer.h
>
10
#include <
cosan/preprocessing/standardScaler.h
>
11
#include <
cosan/preprocessing/encoder.h
>
12
#include <
cosan/preprocessing/minmaxscaler.h
>
13
#include <
cosan/preprocessing/polynomialfeatures.h
>
14
#include <
cosan/preprocessing/principalcomponentanalysis.h
>
15
#include <
cosan/preprocessing/customtransform.h
>
16
17
#include <
cosan/model/CosanLinearRegression.h
>
18
#include <
cosan/model/CosanRidgeRegression.h
>
19
#include <
cosan/model/CosanPrincipalComponentRegression.h
>
20
#include <
cosan/model/CosanPCRRidge.h
>
21
22
typedef
double
NumericType
;
23
int
main
() {
24
Cosan::CosanRawData<NumericType>
CRD(
"./example_data/toy2/X_.csv"
,
"./example_data/toy2/Y_.csv"
);
25
Cosan::OverUnderFlow
ouf(CRD);
26
Cosan::MissingValues
MissV(CRD);
27
Cosan::Normalizer
NM(CRD,2);
28
Cosan::StandardScaler
SS(CRD);
29
bool
bias =
true
;
30
Cosan::CosanLinearRegression
CLR(CRD,bias);
//The second argument indicates whether to consider intercept term. The default is true.
31
//or
32
// Cosan::CosanLinearRegression CLR(bias);
33
// CLR.fit(CRD.GetInput(),CRD.GetTarget());
34
35
36
return
0;
37
}
38
//
39
40
// Cosan::CosanLinearRegression CLR(true);
41
// CLR.fit(CD.GetInput(),CD.GetTarget());
42
43
// std::cout<<CD.GetrowsX()<<" "<<CD.GetcolsX()<<" "<<std::endl;
44
// for (auto each : CD.GetIdxpinfX()) {std::cout<<each[0]<<" "<<each[1]<<std::endl;}
45
// for (auto each : CD.GetIdxminfX()) {std::cout<<each[0]<<" "<<each[1]<<std::endl;}
46
// for (auto each : CD.GetIdxmissingX()) {std::cout<<each[0]<<" "<<each[1]<<std::endl;}
47
// for (auto each : CD.GetcolCatX()) {std::cout<<each<<std::endl;}
48
// for (auto each : CD.GetsvaluesX()) {std::cout<<each<<std::endl;}
49
// for (const auto & [ key, value ] : CD.GetRawToNumIdx()){
50
// std::cout<<key<<":"<<value<<std::endl;}
51
// for (const auto & [ key, value ] : CD.GetRawToCatIdx()){
52
// std::cout<<key<<":"<<value<<std::endl;}
53
54
// Cosan::CosanRawData CD1("./example_data/toy2/X_2.csv");
55
56
// // Cosan::CosanLinearRegression CLR(true);
57
// // CLR.fit(CD.GetInput(),CD.GetTarget());
58
// std::cout<<CD1.GetSummaryMessageX()<<std::endl;
59
// // std::cout<<CD.GetrowsX()<<" "<<CD.GetcolsX()<<" "<<std::endl;
60
// // for (auto each : CD.GetIdxpinfX()) {std::cout<<each[0]<<" "<<each[1]<<std::endl;}
61
// // for (auto each : CD.GetIdxminfX()) {std::cout<<each[0]<<" "<<each[1]<<std::endl;}
62
// // for (auto each : CD.GetIdxmissingX()) {std::cout<<each[0]<<" "<<each[1]<<std::endl;}
63
// // for (auto each : CD.GetcolCatX()) {std::cout<<each<<std::endl;}
64
// // for (auto each : CD.GetsvaluesX()) {std::cout<<each<<std::endl;}
65
// for (const auto & [ key, value ] : CD1.GetRawToNumIdx()){
66
// std::cout<<key<<":"<<value<<std::endl;}
67
// for (const auto & [ key, value ] : CD1.GetRawToCatIdx()){
68
// std::cout<<key<<":"<<value<<std::endl;}
69
70
// std::cout<<CD.GetInput()<<std::endl;
71
72
// double RegularizationTerm = 1;
73
// Cosan::CosanRidgeRegression CRR(RegularizationTerm,true);
74
// CRR.fit(CD.GetInput(),CD.GetTarget());
75
// std::cout<<CRR.GetBeta()<<std::endl;
76
// save_csv("./example_data/toy/beta_c1.csv",CRR.GetBeta());
77
78
// m(0, 0) = 3;
79
// m(1, 0) = 2.5;
80
// m(0, 1) = -1;
81
// m(1,1) = m(1,0)+m(0,1);
82
// std::cout<<y.rows()<<y.cols()<<std::endl;
83
// Eigen::MatrixXd beta = (X.transpose()*X).ldlt().solve(X.transpose()*y);
84
85
86
//
87
// m.transposeInPlace();
88
// cout<<m<<endl;
89
// m.resize(1,4);
90
// cout<<n<<endl;
91
encoder.h
CosanData.h
customtransform.h
CosanRidgeRegression.h
Cosan::OverUnderFlow
Definition:
overunderflow.h:14
normalizer.h
main
int main()
Definition:
modelfittting.cpp:23
Cosan::Normalizer
Definition:
normalizer.h:12
standardScaler.h
minmaxscaler.h
CosanPCRRidge.h
CosanLinearRegression.h
principalcomponentanalysis.h
polynomialfeatures.h
Cosan::CosanRawData
Raw Data container.
Definition:
CosanData.h:36
overunderflow.h
Cosan::MissingValues
Definition:
missingvalues.h:13
CosanBO.h
CosanBO.
CosanPrincipalComponentRegression.h
Cosan::StandardScaler
Definition:
standardScaler.h:11
missingvalues.h
Cosan::CosanLinearRegression
Definition:
CosanLinearRegression.h:20
NumericType
double NumericType
Definition:
modelfittting.cpp:22
test
tutorial_codeexamples
modelfittting.cpp
Generated by
1.8.20