1113: 众数问题

1113: 众数问题

1.描述

所谓众数,就是对于给定的含有N个元素的多重集合,每个元素在S中出现次数最多的成为该元素的重数,
多重集合S重的重数最大的元素成为众数。例如:S={1,2,2,2,3,5},则多重集S的众数是2,其重数为3。
现在你的任务是:对于给定的由m个自然数组成的多重集S,计算出S的众数及其重数。
输入
第一行为n,表示测试数据组数。(n<30)
每组测试的第一行是一个整数m,表示多重集S中元素的个数为m
接下来的一行中给出m(m<100)个不大于10万的自然数
(不会出现不同元素出现的次数相同的情况,如:S={11,11,22,22,33,33})。
输出
每组测试数据输出一行,包含两个数,第一个是众数,第二个是其重数,中间以空格隔开。
样例输入
1
6
1 2 2 2 3 5
样例输出
2 3

2.代码

#include <stdio.h>
#include <stdlib.h>
int main
上述ValueError Traceback (most recent call last) Cell In[17], line 34 29 X_train, X_test, y_train, y_test = train_test_split( 30 X_processed, y, test_size=0.3, random_state=420 31 ) 33 # 训练Ridge模型 ---> 34 reg = Ridge(alpha=5).fit(X_train, y_train) 36 # 评估模型 37 r2 = reg.score(X_test, y_test) File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\base.py:1365, in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs) 1358 estimator._validate_params() 1360 with config_context( 1361 skip_parameter_validation=( 1362 prefer_skip_nested_validation or global_skip_validation 1363 ) 1364 ): -> 1365 return fit_method(estimator, *args, **kwargs) File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\linear_model\_ridge.py:1238, in Ridge.fit(self, X, y, sample_weight) 1236 _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), self.solver) 1237 xp, _ = get_namespace(X, y, sample_weight) -> 1238 X, y = validate_data( 1239 self, 1240 X, 1241 y, 1242 accept_sparse=_accept_sparse, 1243 dtype=[xp.float64, xp.float32], 1244 force_writeable=True, 1245 multi_output=True, 1246 y_numeric=True, 1247 ) 1248 return super().fit(X, y, sample_weight=sample_weight) File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\validation.py:2971, in validate_data(_estimator, X, y, reset, validate_separately, skip_check_array, **check_params) 2969 y = check_array(y, input_name="y", **check_y_params) 2970 else: -> 2971 X, y = check_X_y(X, y, **check_params) 2972 out = X, y 2974 if not no_val_X and check_params.get("ensure_2d", True): File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\validation.py:1368, in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_writeable, force_all_finite, ensure_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, estimator) 1362 raise ValueError( 1363 f"{estimator_name} requires y to be passed, but the target y is None" 1364 ) 1366 ensure_all_finite = _deprecate_force_all_finite(force_all_finite, ensure_all_finite) -> 1368 X = check_array( 1369 X, 1370 accept_sparse=accept_sparse, 1371 accept_large_sparse=accept_large_sparse, 1372 dtype=dtype, 1373 order=order, 1374 copy=copy, 1375 force_writeable=force_writeable, 1376 ensure_all_finite=ensure_all_finite, 1377 ensure_2d=ensure_2d, 1378 allow_nd=allow_nd, 1379 ensure_min_samples=ensure_min_samples, 1380 ensure_min_features=ensure_min_features, 1381 estimator=estimator, 1382 input_name="X", 1383 ) 1385 y = _check_y(y, multi_output=multi_output, y_numeric=y_numeric, estimator=estimator) 1387 check_consistent_length(X, y) File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\validation.py:1105, in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_writeable, force_all_finite, ensure_all_finite, ensure_non_negative, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name) 1099 raise ValueError( 1100 f"Found array with dim {array.ndim}," 1101 f" while dim <= 2 is required{context}." 1102 ) 1104 if ensure_all_finite: -> 1105 _assert_all_finite( 1106 array, 1107 input_name=input_name, 1108 estimator_name=estimator_name, 1109 allow_nan=ensure_all_finite == "allow-nan", 1110 ) 1112 if copy: 1113 if _is_numpy_namespace(xp): 1114 # only make a copy if `array` and `array_orig` may share memory` File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\validation.py:120, in _assert_all_finite(X, allow_nan, msg_dtype, estimator_name, input_name) 117 if first_pass_isfinite: 118 return --> 120 _assert_all_finite_element_wise( 121 X, 122 xp=xp, 123 allow_nan=allow_nan, 124 msg_dtype=msg_dtype, 125 estimator_name=estimator_name, 126 input_name=input_name, 127 ) File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\validation.py:169, in _assert_all_finite_element_wise(X, xp, allow_nan, msg_dtype, estimator_name, input_name) 152 if estimator_name and input_name == "X" and has_nan_error: 153 # Improve the error message on how to handle missing values in 154 # scikit-learn. 155 msg_err += ( 156 f"\n{estimator_name} does not accept missing values" 157 " encoded as NaN natively. For supervised learning, you might want" (...) 167 "#estimators-that-handle-nan-values" 168 ) --> 169 raise ValueError(msg_err) ValueError: Input X contains NaN. Ridge does not accept missing values encoded as NaN natively. For supervised learning, you might want to consider sklearn.ensemble.HistGradientBoostingClassifier and Regressor which accept missing values encoded as NaNs natively. Alternatively, it is possible to preprocess the data, for instance by using an imputer transformer in a pipeline or drop samples with missing values. See https://scikit-learn.org/stable/modules/impute.html You can find a list of all estimators that handle NaN values at the following page: https://scikit-learn.org/stable/modules/impute.html#estimators-that-handle-nan-values 1
最新发布
10-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤米先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值