Skip to content
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

Add logistic regression multi classification ovr #368

Merged
merged 4 commits into from
Oct 30, 2023

Conversation

magic-hya
Copy link
Contributor

Pull Request

What problem does this PR solve?

增加多分类ovr功能

Issue Number: Fixed #252

Possible side effects?

  • Performance:

  • Backward compatibility:

@magic-hya
Copy link
Contributor Author

目前遇到问题:
使用
roc_auc_score(y.values, result2[0], multi_class='ovr')
函数时,该函数需要校验prob的求和和1的误差,
误差校验函数:

# validation of the input y_score
if not np.allclose(1, y_score.sum(axis=1)):
    raise ValueError(
        "Target scores need to be probabilities for multiclass "
        "roc_auc, i.e. they should sum up to 1.0 over classes"
    )

其中校验函数的默认参数为 rtol=1.e-5
spu中计算prob代码为:
prob = preds / preds.sum(axis=1).reshape((preds.shape[0], -1))
求和后,结果如下,误差精度超过1.e-5

[0.99998796 0.99999934 0.99998623 0.999986   0.99999976 0.9999895
 0.9999957  0.9999958  0.99999976 0.9999894  0.99998903 1.
 0.99999917 0.9999858  0.9999884  0.999993   0.9999982  0.9999987
 0.9999858  0.99999857 0.9999856  1.         0.9999879  1.
 1.         1.         1.         0.99999666 0.999994   0.99999887
 0.9999904  0.9999883  1.         0.99999344 0.9999994  0.99999917
 0.9999925  0.9999993  0.9999993  0.99999154 0.99998975 0.99999785
 0.9999871  0.9999868  0.9999989  0.99999994 0.9999863  0.99998987
 0.9999995  0.9999865  0.99998564 0.9999861  0.9999868  0.99999475
 0.9999995  0.9999935  0.99999225 0.9999963  0.9999888  1.
 0.9999999  1.         1.         1.         0.99999446 0.99999964
 1.         0.9999996  1.         0.9999998  1.         0.99999964
 1.         0.99998564 1.         0.9999913  0.999997   0.9999975
 1.         0.9999993  0.99999994 0.99999964 0.99999994 1.
 0.9999845  0.9999995  0.99999344 0.9999964  0.99999905 1.
 0.99999785 0.9999969  0.99999994 1.         1.         0.99998987
 1.         0.99999994 1.         0.9999984  1.         0.99999994
 0.9999529  0.99999917 0.99999964 0.9999957  1.         1.
 1.         0.99999994 0.99999875 0.9999993  0.99999523 0.9999989
 1.         0.9999908  1.         0.9999999  1.         0.99999934
 1.         0.99999213 0.99999803 1.         0.99999994 1.
 0.99996746 0.9999928  1.         0.9999999  0.99998355 0.99999964
 0.9999997  0.99999976 0.99999976 0.99999994 1.         1.
 0.9999999  1.         0.99999964 0.9999957  0.9999997  0.99999994
 1.         0.9999999  0.99999964 0.9999999  0.9999997  1.
 0.9999998  0.99999976 0.9999969  0.99999994 0.9999999  1.
 0.9999999  1.         0.9999996  0.99999726 0.99999994 0.99999976
 1.         0.9999998  0.9999996  0.99999994 1.         0.9999999
 0.9999997  1.         1.         0.99999976 0.99999815 1.
 1.         1.         1.         1.        ]

@anakinxc anakinxc requested a review from deadlywing October 17, 2023 07:52
sml/linear_model/logistic.py Show resolved Hide resolved
sml/linear_model/logistic.py Show resolved Hide resolved
sml/linear_model/logistic.py Outdated Show resolved Hide resolved
sml/linear_model/logistic.py Outdated Show resolved Hide resolved
sml/linear_model/tests/logistic_test.py Outdated Show resolved Hide resolved
sml/linear_model/tests/logistic_test.py Outdated Show resolved Hide resolved
sml/linear_model/emulations/logistic_emul.py Outdated Show resolved Hide resolved
@deadlywing
Copy link
Contributor

@magic-hya Hi,抱歉前段时间比较忙,review不及时,一些意见供参考,欢迎讨论~

Signed-off-by: magic-hya <[email protected]>
Signed-off-by: magic-hya <[email protected]>
sml/linear_model/logistic.py Show resolved Hide resolved
sml/linear_model/logistic.py Show resolved Hide resolved
sml/linear_model/logistic.py Outdated Show resolved Hide resolved
Signed-off-by: magic-hya <[email protected]>
@magic-hya magic-hya requested a review from deadlywing October 30, 2023 08:12
Copy link
Contributor

@deadlywing deadlywing left a comment

Choose a reason for hiding this comment

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

LGTM

@deadlywing deadlywing merged commit 4ab16e2 into secretflow:main Oct 30, 2023
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用 SPU 逻辑回归算法功能性增强
2 participants