ML之SVM:利用SVM算法(超参数组合进行单线程网格搜索+3fCrVa)对20类新闻文本数据集进行分类预测、评估


Feling
Feling 2022-09-19 15:27:23 49604
分类专栏: 资讯

ML之SVM:利用SVM算法(超参数组合进行单线程网格搜索+3fCrVa)对20类新闻文本数据集进行分类预测、评估

目录

输出结果

设计思路

核心代码


输出结果

  1. Fitting 3 folds for each of 12 candidates, totalling 36 fits
  2. [CV] svc__C=0.1, svc__gamma=0.01 .....................................
  3. [CV] ............................ svc__C=0.1, svc__gamma=0.01 - 6.2s
  4. [Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 6.2s remaining: 0.0s
  5. [CV] svc__C=0.1, svc__gamma=0.01 .....................................
  6. [CV] ............................ svc__C=0.1, svc__gamma=0.01 - 7.1s
  7. [CV] svc__C=0.1, svc__gamma=0.01 .....................................
  8. [CV] ............................ svc__C=0.1, svc__gamma=0.01 - 7.0s
  9. [CV] svc__C=0.1, svc__gamma=0.1 ......................................
  10. [CV] ............................. svc__C=0.1, svc__gamma=0.1 - 6.9s
  11. [CV] svc__C=0.1, svc__gamma=0.1 ......................................
  12. [CV] ............................. svc__C=0.1, svc__gamma=0.1 - 6.8s
  13. [CV] svc__C=0.1, svc__gamma=0.1 ......................................
  14. [CV] ............................. svc__C=0.1, svc__gamma=0.1 - 6.3s
  15. [CV] svc__C=0.1, svc__gamma=1.0 ......................................
  16. [CV] ............................. svc__C=0.1, svc__gamma=1.0 - 6.3s
  17. [CV] svc__C=0.1, svc__gamma=1.0 ......................................
  18. [CV] ............................. svc__C=0.1, svc__gamma=1.0 - 7.0s
  19. [CV] svc__C=0.1, svc__gamma=1.0 ......................................
  20. [CV] ............................. svc__C=0.1, svc__gamma=1.0 - 8.1s
  21. [CV] svc__C=0.1, svc__gamma=10.0 .....................................
  22. [CV] ............................ svc__C=0.1, svc__gamma=10.0 - 8.8s
  23. [CV] svc__C=0.1, svc__gamma=10.0 .....................................
  24. [CV] ............................ svc__C=0.1, svc__gamma=10.0 - 10.7s
  25. [CV] svc__C=0.1, svc__gamma=10.0 .....................................
  26. [CV] ............................ svc__C=0.1, svc__gamma=10.0 - 9.4s
  27. [CV] svc__C=1.0, svc__gamma=0.01 .....................................
  28. [CV] ............................ svc__C=1.0, svc__gamma=0.01 - 8.4s
  29. [CV] svc__C=1.0, svc__gamma=0.01 .....................................
  30. [CV] ............................ svc__C=1.0, svc__gamma=0.01 - 6.7s
  31. [CV] svc__C=1.0, svc__gamma=0.01 .....................................
  32. [CV] ............................ svc__C=1.0, svc__gamma=0.01 - 6.9s
  33. [CV] svc__C=1.0, svc__gamma=0.1 ......................................
  34. [CV] ............................. svc__C=1.0, svc__gamma=0.1 - 6.6s
  35. [CV] svc__C=1.0, svc__gamma=0.1 ......................................
  36. [CV] ............................. svc__C=1.0, svc__gamma=0.1 - 6.2s
  37. [CV] svc__C=1.0, svc__gamma=0.1 ......................................
  38. [CV] ............................. svc__C=1.0, svc__gamma=0.1 - 6.8s
  39. [CV] svc__C=1.0, svc__gamma=1.0 ......................................
  40. [CV] ............................. svc__C=1.0, svc__gamma=1.0 - 7.6s
  41. [CV] svc__C=1.0, svc__gamma=1.0 ......................................
  42. [CV] ............................. svc__C=1.0, svc__gamma=1.0 - 7.7s
  43. [CV] svc__C=1.0, svc__gamma=1.0 ......................................
  44. [CV] ............................. svc__C=1.0, svc__gamma=1.0 - 8.2s
  45. [CV] svc__C=1.0, svc__gamma=10.0 .....................................
  46. [CV] ............................ svc__C=1.0, svc__gamma=10.0 - 6.7s
  47. [CV] svc__C=1.0, svc__gamma=10.0 .....................................
  48. [CV] ............................ svc__C=1.0, svc__gamma=10.0 - 8.4s
  49. [CV] svc__C=1.0, svc__gamma=10.0 .....................................
  50. [CV] ............................ svc__C=1.0, svc__gamma=10.0 - 9.5s
  51. [CV] svc__C=10.0, svc__gamma=0.01 ....................................
  52. [CV] ........................... svc__C=10.0, svc__gamma=0.01 - 10.1s
  53. [CV] svc__C=10.0, svc__gamma=0.01 ....................................
  54. [CV] ........................... svc__C=10.0, svc__gamma=0.01 - 9.9s
  55. [CV] svc__C=10.0, svc__gamma=0.01 ....................................
  56. [CV] ........................... svc__C=10.0, svc__gamma=0.01 - 8.8s
  57. [CV] svc__C=10.0, svc__gamma=0.1 .....................................
  58. [CV] ............................ svc__C=10.0, svc__gamma=0.1 - 9.2s
  59. [CV] svc__C=10.0, svc__gamma=0.1 .....................................
  60. [CV] ............................ svc__C=10.0, svc__gamma=0.1 - 7.7s
  61. [CV] svc__C=10.0, svc__gamma=0.1 .....................................
  62. [CV] ............................ svc__C=10.0, svc__gamma=0.1 - 6.9s
  63. [CV] svc__C=10.0, svc__gamma=1.0 .....................................
  64. [CV] ............................ svc__C=10.0, svc__gamma=1.0 - 8.0s
  65. [CV] svc__C=10.0, svc__gamma=1.0 .....................................
  66. [CV] ............................ svc__C=10.0, svc__gamma=1.0 - 9.5s
  67. [CV] svc__C=10.0, svc__gamma=1.0 .....................................
  68. [CV] ............................ svc__C=10.0, svc__gamma=1.0 - 9.0s
  69. [CV] svc__C=10.0, svc__gamma=10.0 ....................................
  70. [CV] ........................... svc__C=10.0, svc__gamma=10.0 - 8.6s
  71. [CV] svc__C=10.0, svc__gamma=10.0 ....................................
  72. [CV] ........................... svc__C=10.0, svc__gamma=10.0 - 8.1s
  73. [CV] svc__C=10.0, svc__gamma=10.0 ....................................
  74. [CV] ........................... svc__C=10.0, svc__gamma=10.0 - 9.0s
  75. [Parallel(n_jobs=1)]: Done 36 out of 36 | elapsed: 4.8min finished
  76. 单线程:输出最佳模型在测试集上的准确性: 0.8226666666666667

设计思路

核心代码

  1. class GridSearchCV(-title class_ inherited__">BaseSearchCV):
  2. """Exhaustive search over specified parameter values for an estimator.
  3. .. deprecated:: 0.18
  4. This module will be removed in 0.20.
  5. Use :class:`sklearn.model_selection.GridSearchCV` instead.
  6. Important members are fit, predict.
  7. GridSearchCV implements a "fit" and a "score" method.
  8. It also implements "predict", "predict_proba", "decision_function",
  9. "transform" and "inverse_transform" if they are implemented in the
  10. estimator used.
  11. The parameters of the estimator used to apply these methods are
  12. optimized
  13. by cross-validated grid-search over a parameter grid.
  14. Read more in the :ref:`User Guide <grid_search>`.
  15. Parameters
  16. ----------
  17. estimator : estimator object.
  18. A object of that type is instantiated for each grid point.
  19. This is assumed to implement the scikit-learn estimator interface.
  20. Either estimator needs to provide a ``score`` function,
  21. or ``scoring`` must be passed.
  22. param_grid : dict or list of dictionaries
  23. Dictionary with parameters names (string) as keys and lists of
  24. parameter settings to try as values, or a list of such
  25. dictionaries, in which case the grids spanned by each dictionary
  26. in the list are explored. This enables searching over any sequence
  27. of parameter settings.
  28. scoring : string, callable or None, default=None
  29. A string (see model evaluation documentation) or
  30. a scorer callable object / function with signature
  31. ``scorer(estimator, X, y)``.
  32. If ``None``, the ``score`` method of the estimator is used.
  33. fit_params : dict, optional
  34. Parameters to pass to the fit method.
  35. n_jobs: int, default: 1 :
  36. The maximum number of estimators fit in parallel.
  37. - If -1 all CPUs are used.
  38. - If 1 is given, no parallel computing code is used at all,
  39. which is useful for debugging.
  40. - For ``n_jobs`` below -1, ``(n_cpus + n_jobs + 1)`` are used.
  41. For example, with ``n_jobs = -2`` all CPUs but one are used.
  42. .. versionchanged:: 0.17
  43. Upgraded to joblib 0.9.3.
  44. pre_dispatch : int, or string, optional
  45. Controls the number of jobs that get dispatched during parallel
  46. execution. Reducing this number can be useful to avoid an
  47. explosion of memory consumption when more jobs get dispatched
  48. than CPUs can process. This parameter can be:
  49. - None, in which case all the jobs are immediately
  50. created and spawned. Use this for lightweight and
  51. fast-running jobs, to avoid delays due to on-demand
  52. spawning of the jobs
  53. - An int, giving the exact number of total jobs that are
  54. spawned
  55. - A string, giving an expression as a function of n_jobs,
  56. as in '2*n_jobs'
  57. iid : boolean, default=True
  58. If True, the data is assumed to be identically distributed across
  59. the folds, and the loss minimized is the total loss per sample,
  60. and not the mean loss across the folds.
  61. cv : int, cross-validation generator or an iterable, optional
  62. Determines the cross-validation splitting strategy.
  63. Possible inputs for cv are:
  64. - None, to use the default 3-fold cross-validation,
  65. - integer, to specify the number of folds.
  66. - An object to be used as a cross-validation generator.
  67. - An iterable yielding train/test splits.
  68. For integer/None inputs, if the estimator is a classifier and ``y`` is
  69. either binary or multiclass,
  70. :class:`sklearn.model_selection.StratifiedKFold` is used. In all
  71. other cases, :class:`sklearn.model_selection.KFold` is used.
  72. Refer :ref:`User Guide <cross_validation>` for the various
  73. cross-validation strategies that can be used here.
  74. refit : boolean, default=True
  75. Refit the best estimator with the entire dataset.
  76. If "False", it is impossible to make predictions using
  77. this GridSearchCV instance after fitting.
  78. verbose : integer
  79. Controls the verbosity: the higher, the more messages.
  80. error_score : 'raise' (default) or numeric
  81. Value to assign to the score if an error occurs in estimator fitting.
  82. If set to 'raise', the error is raised. If a numeric value is given,
  83. FitFailedWarning is raised. This parameter does not affect the refit
  84. step, which will always raise the error.
  85. Examples
  86. --------
  87. >>> from sklearn import svm, grid_search, datasets
  88. >>> iris = datasets.load_iris()
  89. >>> parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
  90. >>> svr = svm.SVC()
  91. >>> clf = grid_search.GridSearchCV(svr, parameters)
  92. >>> clf.fit(iris.data, iris.target)
  93. ... doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
  94. GridSearchCV(cv=None, error_score=...,
  95. estimator=SVC(C=1.0, cache_size=..., class_weight=..., coef0=...,
  96. decision_function_shape='ovr', degree=..., gamma=...,
  97. kernel='rbf', max_iter=-1, probability=False,
  98. random_state=None, shrinking=True, tol=...,
  99. verbose=False),
  100. fit_params={}, iid=..., n_jobs=1,
  101. param_grid=..., pre_dispatch=..., refit=...,
  102. scoring=..., verbose=...)
  103. Attributes
  104. ----------
  105. grid_scores_ : list of named tuples
  106. Contains scores for all parameter combinations in param_grid.
  107. Each entry corresponds to one parameter setting.
  108. Each named tuple has the attributes:
  109. * ``parameters``, a dict of parameter settings
  110. * ``mean_validation_score``, the mean score over the
  111. cross-validation folds
  112. * ``cv_validation_scores``, the list of scores for each fold
  113. best_estimator_ : estimator
  114. Estimator that was chosen by the search, i.e. estimator
  115. which gave highest score (or smallest loss if specified)
  116. on the left out data. Not available if refit=False.
  117. best_score_ : float
  118. Score of best_estimator on the left out data.
  119. best_params_ : dict
  120. Parameter setting that gave the best results on the hold out data.
  121. scorer_ : function
  122. Scorer function used on the held out data to choose the best
  123. parameters for the model.

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=3276
赞同 0
评论 0 条
FelingL2
粉丝 0 发表 10 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2941
【软件正版化】软件正版化工作要点  2860
统信UOS试玩黑神话:悟空  2819
信刻光盘安全隔离与信息交换系统  2712
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1246
grub引导程序无法找到指定设备和分区  1213
华为全联接大会2024丨软通动力分论坛精彩议程抢先看!  163
点击报名 | 京东2025校招进校行程预告  162
2024海洋能源产业融合发展论坛暨博览会同期活动-海洋能源与数字化智能化论坛成功举办  160
华为纯血鸿蒙正式版9月底见!但Mate 70的内情还得接着挖...  157
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
信创开放社区邀请他人注册的具体步骤如下 15
如何玩转信创开放社区—从小白进阶到专家 15
方德桌面操作系统 14
我有15积分有什么用? 13
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!