Commit 548cec82 authored by Jeff Daily's avatar Jeff Daily
Browse files

Merge branch 'master' into rocm3

parents 2f7bd8ef 5dbfcdc4
......@@ -2,8 +2,8 @@
* Copyright (c) 2016 Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/
#ifndef LIGHTGBM_TREELEARNER_SERIAL_TREE_LEARNER_H_
#define LIGHTGBM_TREELEARNER_SERIAL_TREE_LEARNER_H_
#ifndef LIGHTGBM_SRC_TREELEARNER_SERIAL_TREE_LEARNER_H_
#define LIGHTGBM_SRC_TREELEARNER_SERIAL_TREE_LEARNER_H_
#include <LightGBM/dataset.h>
#include <LightGBM/tree.h>
......@@ -247,4 +247,4 @@ inline data_size_t SerialTreeLearner::GetGlobalDataCountInLeaf(int leaf_idx) con
}
} // namespace LightGBM
#endif // LightGBM_TREELEARNER_SERIAL_TREE_LEARNER_H_
#endif // LIGHTGBM_SRC_TREELEARNER_SERIAL_TREE_LEARNER_H_
......@@ -2,8 +2,8 @@
* Copyright (c) 2016 Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/
#ifndef LIGHTGBM_TREELEARNER_SPLIT_INFO_HPP_
#define LIGHTGBM_TREELEARNER_SPLIT_INFO_HPP_
#ifndef LIGHTGBM_SRC_TREELEARNER_SPLIT_INFO_HPP_
#define LIGHTGBM_SRC_TREELEARNER_SPLIT_INFO_HPP_
#include <LightGBM/meta.h>
......@@ -291,4 +291,4 @@ struct LightSplitInfo {
};
} // namespace LightGBM
#endif // LightGBM_TREELEARNER_SPLIT_INFO_HPP_
#endif // LIGHTGBM_SRC_TREELEARNER_SPLIT_INFO_HPP_
......@@ -4,6 +4,8 @@
*/
#include <LightGBM/tree_learner.h>
#include <string>
#include "gpu_tree_learner.h"
#include "linear_tree_learner.h"
#include "parallel_tree_learner.h"
......
......@@ -4,7 +4,9 @@
*/
#include <LightGBM/utils/common.h>
#include <algorithm>
#include <cstring>
#include <functional>
#include <tuple>
#include <vector>
......@@ -13,8 +15,7 @@
namespace LightGBM {
template <typename TREELEARNER_T>
VotingParallelTreeLearner<TREELEARNER_T>::VotingParallelTreeLearner(const Config* config)
:TREELEARNER_T(config) {
VotingParallelTreeLearner<TREELEARNER_T>::VotingParallelTreeLearner(const Config* config):TREELEARNER_T(config) {
top_k_ = this->config_->top_k;
}
......
......@@ -4,8 +4,8 @@
*
* Author: Alberto Ferreira
*/
#ifndef LIGHTGBM_SWIG_STRING_ARRAY_H_
#define LIGHTGBM_SWIG_STRING_ARRAY_H_
#ifndef LIGHTGBM_SWIG_STRINGARRAY_HPP_
#define LIGHTGBM_SWIG_STRINGARRAY_HPP_
#include <algorithm>
#include <new>
......@@ -137,4 +137,4 @@ class StringArray {
std::vector<char*> _array;
};
#endif // LIGHTGBM_SWIG_STRING_ARRAY_H_
#endif // LIGHTGBM_SWIG_STRINGARRAY_HPP_
......@@ -8,6 +8,7 @@
#include <LightGBM/utils/array_args.h>
#include <random>
#include <vector>
using LightGBM::data_size_t;
using LightGBM::score_t;
......
......@@ -10,6 +10,7 @@
#include <cmath>
#include <cstdlib>
#include <vector>
using LightGBM::ArrowChunkedArray;
using LightGBM::ArrowTable;
......
......@@ -6,6 +6,7 @@
#include <gtest/gtest.h>
#include <LightGBM/utils/byte_buffer.h>
#include <memory>
#include <random>
using LightGBM::ByteBuffer;
......
......@@ -5,6 +5,9 @@
* Author: Alberto Ferreira
*/
#include <gtest/gtest.h>
#include <vector>
#include "../include/LightGBM/utils/chunked_array.hpp"
using LightGBM::ChunkedArray;
......
......@@ -11,6 +11,7 @@
#include <LightGBM/dataset.h>
#include <iostream>
#include <string>
using LightGBM::ByteBuffer;
using LightGBM::Dataset;
......
......@@ -7,8 +7,10 @@
#include <testutils.h>
#include <LightGBM/c_api.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
using LightGBM::TestUtils;
......
......@@ -10,6 +10,8 @@
#include <LightGBM/dataset.h>
#include <iostream>
#include <string>
#include <vector>
using LightGBM::Dataset;
using LightGBM::Log;
......
......@@ -3,24 +3,25 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/
#include <gtest/gtest.h>
#include <testutils.h>
#include <LightGBM/c_api.h>
#include <LightGBM/utils/random.h>
#include <gtest/gtest.h>
#include <string>
#include <thread>
#include <utility>
#include <vector>
using LightGBM::Log;
using LightGBM::Random;
namespace LightGBM {
/*!
* Creates a Dataset from the internal repository examples.
*/
int TestUtils::LoadDatasetFromExamples(const char* filename, const char* config, DatasetHandle* out) {
/*!
* Creates a Dataset from the internal repository examples.
*/
int TestUtils::LoadDatasetFromExamples(const char* filename, const char* config, DatasetHandle* out) {
std::string fullPath("examples/");
fullPath += filename;
Log::Info("Debug sample data path: %s", fullPath.c_str());
......@@ -29,12 +30,12 @@ namespace LightGBM {
config,
nullptr,
out);
}
}
/*!
* Creates fake data in the passed vectors.
*/
void TestUtils::CreateRandomDenseData(
/*!
* Creates fake data in the passed vectors.
*/
void TestUtils::CreateRandomDenseData(
int32_t nrows,
int32_t ncols,
int32_t nclasses,
......@@ -53,12 +54,12 @@ namespace LightGBM {
}
CreateRandomMetadata(nrows, nclasses, labels, weights, init_scores, groups);
}
}
/*!
* Creates fake data in the passed vectors.
*/
void TestUtils::CreateRandomSparseData(
/*!
* Creates fake data in the passed vectors.
*/
void TestUtils::CreateRandomSparseData(
int32_t nrows,
int32_t ncols,
int32_t nclasses,
......@@ -88,12 +89,12 @@ namespace LightGBM {
}
CreateRandomMetadata(nrows, nclasses, labels, weights, init_scores, groups);
}
}
/*!
* Creates fake data in the passed vectors.
*/
void TestUtils::CreateRandomMetadata(int32_t nrows,
/*!
* Creates fake data in the passed vectors.
*/
void TestUtils::CreateRandomMetadata(int32_t nrows,
int32_t nclasses,
std::vector<float>* labels,
std::vector<float>* weights,
......@@ -130,9 +131,9 @@ namespace LightGBM {
groups->push_back(group);
}
}
}
}
void TestUtils::StreamDenseDataset(DatasetHandle dataset_handle,
void TestUtils::StreamDenseDataset(DatasetHandle dataset_handle,
int32_t nrows,
int32_t ncols,
int32_t nclasses,
......@@ -205,9 +206,9 @@ namespace LightGBM {
auto cur_time = std::chrono::steady_clock::now();
Log::Info(" Time: %d", cur_time - start_time);
}
}
void TestUtils::StreamSparseDataset(DatasetHandle dataset_handle,
void TestUtils::StreamSparseDataset(DatasetHandle dataset_handle,
int32_t nrows,
int32_t nclasses,
int32_t batch_count,
......@@ -272,14 +273,14 @@ namespace LightGBM {
auto cur_time = std::chrono::steady_clock::now();
Log::Info(" Time: %d", cur_time - start_time);
}
}
/*!
/*!
* Pushes data from 1 thread into a Dataset based on thread_id and nrows.
* e.g. with 100 rows, thread 0 will push rows 0-49, and thread 2 will push rows 50-99.
* Note that rows are still pushed in microbatches within their range.
*/
void TestUtils::PushSparseBatch(DatasetHandle dataset_handle,
void TestUtils::PushSparseBatch(DatasetHandle dataset_handle,
int32_t nrows,
int32_t nclasses,
int32_t batch_count,
......@@ -345,10 +346,10 @@ namespace LightGBM {
groups_ptr += batch_count;
}
}
}
}
void TestUtils::AssertMetadata(const Metadata* metadata,
void TestUtils::AssertMetadata(const Metadata* metadata,
const std::vector<float>* ref_labels,
const std::vector<float>* ref_weights,
const std::vector<double>* ref_init_scores,
......@@ -418,9 +419,9 @@ namespace LightGBM {
} else if (ref_groups) {
FAIL() << "Expected non-null query_boundaries";
}
}
}
const double* TestUtils::CreateInitScoreBatch(std::vector<double>* init_score_batch,
const double* TestUtils::CreateInitScoreBatch(std::vector<double>* init_score_batch,
int32_t index,
int32_t nrows,
int32_t nclasses,
......@@ -434,6 +435,6 @@ namespace LightGBM {
}
}
return init_score_batch->data();
}
}
} // namespace LightGBM
......@@ -2,8 +2,8 @@
* Copyright (c) 2022 Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/
#ifndef LIGHTGBM_TESTUTILS_H_
#define LIGHTGBM_TESTUTILS_H_
#ifndef LIGHTGBM_TESTS_CPP_TESTS_TESTUTILS_H_
#define LIGHTGBM_TESTS_CPP_TESTS_TESTUTILS_H_
#include <LightGBM/c_api.h>
#include <LightGBM/dataset.h>
......@@ -121,4 +121,4 @@ class TestUtils {
int32_t thread_id);
};
} // namespace LightGBM
#endif // LIGHTGBM_TESTUTILS_H_
#endif // LIGHTGBM_TESTS_CPP_TESTS_TESTUTILS_H_
......@@ -16,7 +16,14 @@ import psutil
import pytest
from scipy.sparse import csr_matrix, isspmatrix_csc, isspmatrix_csr
from sklearn.datasets import load_svmlight_file, make_blobs, make_classification, make_multilabel_classification
from sklearn.metrics import average_precision_score, log_loss, mean_absolute_error, mean_squared_error, roc_auc_score
from sklearn.metrics import (
average_precision_score,
log_loss,
mean_absolute_error,
mean_squared_error,
r2_score,
roc_auc_score,
)
from sklearn.model_selection import GroupKFold, TimeSeriesSplit, train_test_split
import lightgbm as lgb
......@@ -4049,6 +4056,29 @@ def test_average_precision_metric():
assert res["training"]["average_precision"][-1] == pytest.approx(1)
def test_r2_metric():
# test against sklearn R2 metric
X, y = make_synthetic_regression()
params = {"objective": "regression", "metric": "r2", "verbose": -1}
res = {}
train_data = lgb.Dataset(X, label=y)
est = lgb.train(
params, train_data, num_boost_round=1, valid_sets=[train_data], callbacks=[lgb.record_evaluation(res)]
)
r2 = res["training"]["r2"][-1]
pred = est.predict(X)
sklearn_r2 = r2_score(y, pred)
assert r2 == pytest.approx(sklearn_r2)
assert r2 != 0
assert r2 != 1
# test that R2 is 1 when y has no variance and the model predicts perfectly
y = y.copy()
y[:] = 1
lgb_X = lgb.Dataset(X, label=y)
lgb.train(params, lgb_X, num_boost_round=1, valid_sets=[lgb_X], callbacks=[lgb.record_evaluation(res)])
assert res["training"]["r2"][-1] == pytest.approx(1)
def test_reset_params_works_with_metric_num_class_and_boosting():
X, y = load_breast_cancer(return_X_y=True)
dataset_params = {"max_bin": 150}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment