Powered by:NEFU AB-IN
文章目录
4509. 归一化处理
-
题意
第26次CCF计算机软件能力认证
在机器学习中,对数据进行归一化处理是一种常用的技术。
将数据从各种各样分布调整为平均值为 0、方差为 1 的标准分布,在很多情况下都可以有效地加速模型的训练。
这里假定需要处理的数据为 n 个整数 a1,a2,⋯,an。
在机器学习中,对数据进行归一化处理是一种常用的技术。
将数据从各种各样分布调整为平均值为 0、方差为 1 的标准分布,在很多情况下都可以有效地加速模型的训练。
这里假定需要处理的数据为 n 个整数 a1,a2,⋯,an。 -
思路
模拟公式即可,注意double
-
代码
/* * @Author: NEFU AB-IN * @Date: 2023-01-12 11:52:00 * @FilePath: \Acwing\4509\4509.cpp * @LastEditTime: 2023-01-12 12:02:49 */ #include <bits/stdc++.h> using namespace std; #define int long long #undef int #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define IOS \ ios::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) #define DEBUG(X) cout << #X << ": " << X << '\n' typedef pair<int, int> PII; const int N = 1e5 + 10, INF = 0x3f3f3f3f; signed main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; double avg = (double)accumulate(a.begin(), a.end(), 0) / n; double s = 0; for (int i = 0; i < n; ++i) { s += (a[i] - avg) * (a[i] - avg); } s /= (double)n; s = sqrt(s); for (int i = 0; i < n; ++i) { printf("%.17lf\n", (a[i] - avg) / s); } return 0; }