[scikit-learn] 第二章 Model Section

系列文章目录

[scikit-learn] 第一章 初识scikit-learn及内置数据集介绍


[scikit-learn] 第二章 Model Section

菜鸡镇贴!!!

请添加图片描述

Model Section

sklearn.model_selection 模块是 Scikit-learn 库中用于模型选择和评估的核心工具集。该模块提供了用于分割数据集、交叉验证、参数调优和性能评估的功能。本贴主要从交叉验证:评估估计器性能、调整估计器的超参数和学习曲线部分进行介绍。

交叉验证:评估估计器性能

​ 在同一数据上学习预测函数的参数并在该数据上进行测试是一种方法上的错误:一个仅会重复其刚刚见过的样本标签的模型可能会获得完美的分数,但在尚未见过的数据上却无法预测任何有用的信息。这种情况称为过拟合。为了避免这种情况,在执行(监督)机器学习实验时,通常会将部分可用数据保留为测试集 X_test、y_test。请注意,“实验”一词并不仅用于学术用途,因为即使在商业环境中,机器学习通常也是从实验开始的。以下是模型训练中典型交叉验证工作流程的流程图。最佳参数可以通过网格搜索技术确定。
请添加图片描述

​ 在scikit中,可以使用train_test_split辅助函数快速计算随机划分为训练集和测试集。让我们加载鸢尾数据集,以在其上拟合线性支持向量机:

import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import datasets
from sklearn import svm

// return_X_y=True参数表示返回的数据是分开的。X包含特征数据,y包含对应的标签。
X, y = datasets.load_iris(return_X_y=True)

// test_size=0.4参数指定了测试集占总数据的比例为40%,random_state=0参数确保每次运行代码时得到的随机拆分结果相同。
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=0)

// 创建支持向量机分类器对象(SVC),使用线性核(kernel='linear'),正则化参数(C=1)。然后使用训练集(X_train和y_train)对分类器进行训练。
clf = svm.SVC(kernel='linear', C=1).fit(X_train, y_train)

// 使用测试集评估分类器的性能。score()方法返回分类器在测试集上的准确率。
print(clf.score(X_test, y_test))

​ 在评估不同的估算器设置(即“超参数”)时,比如对于 SVM 必须手动设置的 C 参数,仍然存在着在测试集上过度拟合的风险,因为参数可以调整直至估算器表现最佳。这样一来,关于测试集的信息可能会“泄露”到模型中,评估指标也就无法再报告出泛化性能。为了解决这个问题,数据集的另一部分可以被保留作为所谓的“验证集”:先在训练集上进行训练,然后在验证集上进行评估;当实验看起来成功时,最终评估可以在测试集上进行。

​ 然而,将可用数据分成三组会大幅减少可用于模型学习的样本数量,并且结果可能依赖于对(训练、验证)集的特定随机选择。

​ 解决这一问题的方法是一种称为交叉验证(CV)的程序。尽管最终评估仍需保留一个测试集,但在进行CV时不再需要验证集。在基本的k折交叉验证方法中,训练集被分成k个较小的子集(还有其他方法,但通常遵循相同的原则)。对于每一个k“折”,按照以下步骤进行:

  1. 使用 k - 1 个折叠的数据来训练模型;
  2. 将剩余的数据用作验证集(即,用作测试集来计算性能指标,如准确率)。

​ k折交叉验证报告的性能度量是在循环中计算的值的平均值。这种方法可能会消耗大量计算资源,但不会浪费太多数据(就像固定一个任意的验证集一样),这在样本数量非常小的逆推问题等情况下是一个重大优势。
请添加图片描述

调整估计器的超参数

​ 超参数是在估计器内部不直接学习的参数。在 scikit-learn 中,它们作为参数传递给估计器类的构造函数。典型的例子包括支持向量分类器的 C、kernel 和 gamma,以及 Lasso 的 alpha 等。

​ 推荐的做法是搜索超参数空间,以获得最佳的交叉验证分数。

​ 可以通过这种方式优化构造估计器时提供的任何参数。具体来说,要找到给定估计器的所有参数的名称和当前值,请使用:

estimator.get_params()

一次搜索包括:

  1. 一个估计器(回归器或分类器,例如sklearn.svm.SVC());
  2. 一个参数空间;
  3. 一种搜索或抽样候选项的方法;
  4. 一个交叉验证方案;以及
  5. 一个评分函数。

​ scikit-learn提供了两种通用的参数搜索方法:对于给定的值,GridSearchCV会详尽考虑所有参数组合,而RandomizedSearchCV则可以从指定分布的参数空间中抽取指定数量的候选项。这两种工具都有对应的连续减半版本,即HalvingGridSearchCV和HalvingRandomSearchCV,后者在寻找优秀参数组合时可能更快。

demo:

import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import cross_val_score, GridSearchCV, KFold
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC

# 加载数据集
iris = load_iris()
X = iris.data
y = iris.target

# 创建一个SVM分类器的Pipeline
pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC())])

# 定义参数网格
param_grid = {'svc__C': [0.1, 1, 10, 100],  # SVM正则化参数
              'svc__gamma': [0.1, 0.01, 0.001, 0.0001],  # RBF核函数的宽度
              'svc__kernel': ['linear', 'rbf', 'poly']}  # SVM的核函数类型

# 定义k折交叉验证
kfold = KFold(n_splits=5, shuffle=True, random_state=42)

# 使用GridSearchCV进行参数调优
grid_search = GridSearchCV(pipe, param_grid, cv=kfold, scoring='accuracy', n_jobs=-1)
grid_search.fit(X, y)

# 输出最佳参数组合
print("Best parameters:", grid_search.best_params_)

# 输出最佳模型的交叉验证得分
print("Best cross-validation score:", grid_search.best_score_)

# 输出每个超参数组合的交叉验证得分
results = grid_search.cv_results_
for mean_score, params in zip(results['mean_test_score'], results['params']):
    print(f"Mean validation score: {mean_score:.3f} with params: {params}")

result:
请添加图片描述

学习曲线

​ 学习曲线展示了估计器在不同数量的训练样本下的验证分数和训练分数。它是一个工具,用于确定我们增加更多训练数据能获得多少收益,以及估计器是否更多地受到方差误差或偏差误差的影响。考虑以下示例,我们绘制了朴素贝叶斯分类器和支持向量机的学习曲线。

​ 对于朴素贝叶斯,随着训练集大小的增加,验证分数和训练分数都收敛到一个相当低的值。因此,我们可能不会从更多的训练数据中获益很多。

​ 相反,对于小量数据,支持向量机的训练分数远远大于验证分数。增加更多的训练样本很可能会增加泛化能力。
请添加图片描述

demo:

import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import learning_curve
from sklearn.datasets import load_digits
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC

# 加载示例数据集
digits = load_digits()
X, y = digits.data, digits.target

# 定义朴素贝叶斯分类器和支持向量机分类器
nb_classifier = GaussianNB()
svm_classifier = SVC(kernel='linear')

# 定义绘制学习曲线函数
def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None, n_jobs=None, train_sizes=np.linspace(.1, 1.0, 5)):
    plt.figure()
    plt.title(title)
    if ylim is not None:
        plt.ylim(*ylim)
    plt.xlabel("Training examples")
    plt.ylabel("Score")
    train_sizes, train_scores, test_scores = learning_curve(
        estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes)
    train_scores_mean = np.mean(train_scores, axis=1)
    train_scores_std = np.std(train_scores, axis=1)
    test_scores_mean = np.mean(test_scores, axis=1)
    test_scores_std = np.std(test_scores, axis=1)
    plt.grid()

    plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
    plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
                     test_scores_mean + test_scores_std, alpha=0.1, color="g")
    plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
             label="Training score")
    plt.plot(train_sizes, test_scores_mean, 'o-', color="g",
             label="Cross-validation score")

    plt.legend(loc="best")
    return plt

# 绘制朴素贝叶斯分类器的学习曲线
plot_learning_curve(nb_classifier, "Naive Bayes Learning Curve", X, y, cv=5)
plt.show()

# 绘制支持向量机分类器的学习曲线
plot_learning_curve(svm_classifier, "SVM Learning Curve", X, y, cv=5)
plt.show()

result:
请添加图片描述

库函数介绍:

Splitter Classes:

model_selection.GroupKFold([n_splits]) K-fold iterator variant with non-overlapping groups. n_splits参数含义是将数据集分成多少份。

model_selection.GroupShuffleSplit([...]) Shuffle-Group(s)-Out cross-validation iterator. [...]表示其他可选参数。

model_selection.KFold([n_splits, shuffle, ...]) K-Fold cross-validator. n_splits参数含义是将数据集分成多少份,shuffle参数表示是否在每次划分时打乱数据顺序。

model_selection.LeaveOneGroupOut() Leave One Group Out cross-validator.

model_selection.LeavePGroupsOut(n_groups) Leave P Group(s) Out cross-validator. n_groups参数含义是每次留出的组数。

model_selection.LeaveOneOut() Leave-One-Out cross-validator.

model_selection.LeavePOut(p) Leave-P-Out cross-validator. p参数含义是每次留出的数据点数量。

model_selection.PredefinedSplit(test_fold) Predefined split cross-validator. test_fold参数含义是预定义的测试集划分。

model_selection.RepeatedKFold(*[, n_splits, ...]) Repeated K-Fold cross validator. *表示其他可选参数,n_splits参数含义是将数据集重复分成多少份。

model_selection.RepeatedStratifiedKFold(*[, ...]) Repeated Stratified K-Fold cross validator. *表示其他可选参数。

model_selection.ShuffleSplit([n_splits, ...]) Random permutation cross-validator. n_splits参数含义是将数据集分成多少份。

model_selection.StratifiedKFold([n_splits, ...]) Stratified K-Fold cross-validator. n_splits参数含义是将数据集分成多少份。

model_selection.StratifiedShuffleSplit([...]) Stratified ShuffleSplit cross-validator. [...]表示其他可选参数。

model_selection.StratifiedGroupKFold([...]) Stratified K-Fold iterator variant with non-overlapping groups. [...]表示其他可选参数。

model_selection.TimeSeriesSplit([n_splits, ...]) Time Series cross-validator. n_splits参数含义是将时间序列数据分成多少份。

Splitter Functions

model_selection.check_cv([cv, y, classifier]) Input checker utility for building a cross-validator. cv参数含义是交叉验证器,y参数含义是目标变量,classifier参数含义是分类器。

model_selection.train_test_split(*arrays[, ...]) Split arrays or matrices into random train and test subsets. *arrays表示输入的数组或矩阵,...表示其他可选参数。

Hyper-parameter optimizers
model_selection.GridSearchCV(estimator, ...) Exhaustive search over specified parameter values for an estimator. estimator参数含义是估计器,...表示其他可选参数。

model_selection.HalvingGridSearchCV(...[, ...]) Search over specified parameter values with successive halving. ...[, ...]表示其他可选参数。

model_selection.ParameterGrid(param_grid) Grid of parameters with a discrete number of values for each. param_grid参数含义是参数网格。

model_selection.ParameterSampler(...[, ...]) Generator on parameters sampled from given distributions. ...[, ...]表示其他可选参数。

model_selection.RandomizedSearchCV(...[, ...]) Randomized search on hyper parameters. ...[, ...]表示其他可选参数。

model_selection.HalvingRandomSearchCV(...[, ...]) Randomized search on hyper parameters. ...[, ...]表示其他可选参数。

Model validation

model_selection.cross_validate(estimator, X) Evaluate metric(s) by cross-validation and also record fit/score times. estimator参数含义是估计器,X参数含义是输入数据。

model_selection.cross_val_predict(estimator, X) Generate cross-validated estimates for each input data point. estimator参数含义是估计器,X参数含义是输入数据。

model_selection.cross_val_score(estimator, X) Evaluate a score by cross-validation. estimator参数含义是估计器,X参数含义是输入数据。

model_selection.learning_curve(estimator, X, ...) Learning curve. estimator参数含义是估计器,X参数含义是输入数据,...表示其他可选参数。

model_selection.permutation_test_score(...) Evaluate the significance of a cross-validated score with permutations. ...表示其他可选参数。

model_selection.validation_curve(estimator, ...) Validation curve. estimator参数含义是估计器,...表示其他可选参数。

Visualization

model_selection.LearningCurveDisplay(*, ...) Learning Curve visualization. 表示其他可选参数。

model_selection.ValidationCurveDisplay(*, ...) Validation Curve visualization. 表示其他可选参数。
from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from matplotlib.colors import ListedColormap from sklearn.linear_model import LogisticRegression from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.svm import SVC from sklearn import tree import numpy as np import matplotlib.pyplot as plt # 代码参考 # Machine Learning with PyTorch and Scikit-Learn # # -- Code Examples # # 参考代码来自 https://github.com/rasbt/machine-learning-book # 时间:2024年3月19日 Date: March 19, 2024 # 文件名称 Filename: BasicML2.py # 编码实现 Coding by: Wei Zhou, 邮箱 Mailbox:2686818585@qq.com # 所属单位:中国 成都,西南民族大学(Southwest University of Nationality,or Southwest Minzu University), 计算机科学与工程学院. # Affiliation: School of Computer Science and Engineering,SWUN (before 2020) or SMU (2020 - now), Chengdu, PR. China # ### Overview # - [Decision tree learning](#Decision-tree-learning) # - [Maximizing information gain – getting the most bang for the buck](#Maximizing-information-gain--getting-the-most-bang-for-the-buck) # - [Building a decision tree](#Building-a-decision-tree) # - [Combining weak to strong learners via random forests](#Combining-weak-to-strong-learners-via-random-forests) # - [Maximum margin classification with support vector machines](#Maximum-margin-classification-with-support-vector-machines) # - [Dealing with the nonlinearly separable case using slack variables](#Dealing-with-the-nonlinearly-separable-case-using-slack-variables) # - [Solving nonlinear problems using a kernel SVM](#Solving-nonlinear-problems-using-a-kernel-SVM) # - [Using the kernel trick to find separating hyperplanes in higher dimensional space](#Using-the-kernel-trick-to-find-separating-hyperplanes-in-higher-dimensional-space) # 决策树代码包括: # - 使用Scikit-learn库写的决策树分类代码 # - 决策树可视化代码 # - 随机森林代码 # SVM代码包括: # - 使用Scikit-learn库写的SVM带松弛变量的代码,可以用于解决线性分类 # - XOR 数据可视化代码 # - 使用Scikit-learn库写的kernel SVM的代码,可以用于解决XOR数据集的非线性分类问题 # - 使用Scikit-learn库写的kernel SVM的代码,可以用于解决Iris数据集的非线性分类问题 # 对应于第4次课后练习,课后练习需要解释对应代码,问题见代码注释部分。 iris = datasets.load_iris() X = iris.data[:, [2, 3]] y = iris.target X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.3, random_state=1, stratify=y) sc = StandardScaler() sc.fit(X_train) X_train_std = sc.transform(X_train) X_test_std = sc.transform(X_test) def plot_decision_regions(X, y, classifier, test_idx=None, resolution=0.02): # setup marker generator and color map markers = ('o', 's', '^', 'v', '<') colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan') cmap = ListedColormap(colors[:len(np.unique(y))]) # plot the decision surface x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max() + 1 x2_min, x2_max = X[:, 1].min() - 1, X[:, 1].max() + 1 xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution), np.arange(x2_min, x2_max, resolution)) lab = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T) lab = lab.reshape(xx1.shape) plt.contourf(xx1, xx2, lab, alpha=0.3, cmap=cmap) plt.xlim(xx1.min(), xx1.max()) plt.ylim(xx2.min(), xx2.max()) # plot class examples for idx, cl in enumerate(np.unique(y)): plt.scatter(x=X[y == cl, 0], y=X[y == cl, 1], alpha=0.8, c=colors[idx], marker=markers[idx], label=f'Class {cl}', edgecolor='black') # highlight test examples if test_idx: # plot all examples X_test, y_test = X[test_idx, :], y[test_idx] plt.scatter(X_test[:, 0], X_test[:, 1], c='none', edgecolor='black', alpha=1.0, linewidth=1, marker='o', s=100, label='Test set') X_combined_std = np.vstack((X_train_std, X_test_std)) y_combined = np.hstack((y_train, y_test)) fig1= plt.figure(num=1) tree_model = DecisionTreeClassifier(criterion='gini', max_depth=4, random_state=1) tree_model.fit(X_train, y_train) X_combined = np.vstack((X_train, X_test)) y_combined = np.hstack((y_train, y_test)) plot_decision_regions(X_combined, y_combined, classifier=tree_model, test_idx=range(105, 150)) plt.xlabel('Petal length [cm]') plt.ylabel('Petal width [cm]') plt.legend(loc='upper left') #plt.savefig('figures/03_20.png', dpi=300) plt.title('DecisionTree Regions') plt.tight_layout() #plt.show() fig2= plt.figure(num=2) feature_names = ['Sepal length', 'Sepal width', 'Petal length', 'Petal width'] tree.plot_tree(tree_model, feature_names=feature_names, filled=True) #plt.savefig('figures/03_21_1.pdf') plt.title('Decision Tree') plt.tight_layout() #plt.show() # ## Combining weak to strong learners via random forests # 1. 请解释RandomForestClassifier函数中n_estimators,n_jobs这两个参数。 forest = RandomForestClassifier(n_estimators=25, random_state=1, n_jobs=2) forest.fit(X_train, y_train) fig3= plt.figure(num=3) plot_decision_regions(X_combined, y_combined, classifier=forest, test_idx=range(105, 150)) plt.xlabel('Petal length [cm]') plt.ylabel('Petal width [cm]') plt.legend(loc='upper left') #plt.savefig('figures/03_2.png', dpi=300) plt.title('Decision Regions by RandomForest') plt.tight_layout() plt.show() # # Maximum margin classification with support vector machines # ## Maximum margin intuition # ... # ## Dealing with the nonlinearly separable case using slack variables print('Now is SVM section') svm = SVC(kernel='linear', C=1.0, random_state=1) svm.fit(X_train_std, y_train) fig4= plt.figure(num=4) plot_decision_regions(X_combined_std, y_combined, classifier=svm, test_idx=range(105, 150)) plt.xlabel('Petal length [standardized]') plt.ylabel('Petal width [standardized]') plt.legend(loc='upper left') plt.title('Decision regions of Iris dataset found by SVM using slack variables') plt.tight_layout() #plt.savefig('figures/03_11.png', dpi=300) #plt.show() # # Solving non-linear problems using a kernel SVM np.random.seed(1) X_xor = np.random.randn(200, 2) # 2.请解释下面两条语句中使用 np.logical_xor 和 np.where ,对应的数据处理功能是什么? y_xor = np.logical_xor(X_xor[:, 0] > 0, X_xor[:, 1] > 0) y_xor = np.where(y_xor, 1, 0) fig5= plt.figure(num=5) plt.scatter(X_xor[y_xor == 1, 0], X_xor[y_xor == 1, 1], c='royalblue', marker='s', label='Class 1') plt.scatter(X_xor[y_xor == 0, 0], X_xor[y_xor == 0, 1], c='tomato', marker='o', label='Class 0') plt.xlim([-3, 3]) plt.ylim([-3, 3]) plt.xlabel('Feature 1') plt.ylabel('Feature 2') plt.legend(loc='best') plt.title('XOR Data') plt.tight_layout() #plt.savefig('figures/03_12.png', dpi=300) #plt.show() # ## Using the kernel trick to find separating hyperplanes in higher dimensional space # 3. 请解释svm函数中kernel, gamma, C三个参数的用处。 svm = SVC(kernel='rbf', random_state=1, gamma=0.10, C=10.0) svm.fit(X_xor, y_xor) fig6= plt.figure(num=6) plot_decision_regions(X_xor, y_xor, classifier=svm) plt.legend(loc='upper left') plt.title('Decision regions of XOR data found by kernel SVM') plt.tight_layout() #plt.savefig('figures/03_14.png', dpi=300) #plt.show() svm = SVC(kernel='rbf', random_state=1, gamma=0.2, C=1.0) svm.fit(X_train_std, y_train) fig7= plt.figure(num=7) plot_decision_regions(X_combined_std, y_combined, classifier=svm, test_idx=range(105, 150)) plt.xlabel('Petal length [standardized]') plt.ylabel('Petal width [standardized]') plt.legend(loc='upper left') plt.title('Decision regions of Iris dataset found by kernel SVM') plt.tight_layout() #plt.savefig('figures/03_15.png', dpi=300) plt.show()
10-14
### `RandomForestClassifier` 函数参数解释 在 Scikit - learn 中,`RandomForestClassifier` 是用于实现随机森林分类器的函数。 - **`n_estimators`**:该参数指定了随机森林中决策树的数量。随机森林是由多个决策树组成的集成学习模型,`n_estimators` 越大,模型通常越稳定,预测的准确性可能会提高,但同时也会增加计算时间和内存消耗。例如,如果设置 `n_estimators = 100`,则表示随机森林由 100 个决策树组成。 - **`n_jobs`**:此参数用于并行计算。它指定了在训练和预测时使用的 CPU 核心数量。如果设置为 `-1`,则使用所有可用的 CPU 核心;如果设置为 1,则不进行并行计算;设置为其他正整数,则使用指定数量的 CPU 核心。使用并行计算可以显著减少训练和预测的时间,尤其是在处理大规模数据集时。 ### `numpy` 函数功能解释 - **`np.logical_xor`**:`np.logical_xor` 是 NumPy 中的逻辑异或函数。它对两个布尔数组进行逐元素的逻辑异或运算。异或运算的规则是当两个元素不同时结果为 `True`,相同时结果为 `False`。例如: ```python import numpy as np a = np.array([True, False, True]) b = np.array([False, False, True]) result = np.logical_xor(a, b) print(result) # 输出: [ True False False] ``` - **`np.where`**:`np.where` 函数有两种常见的用法。一种是根据条件返回满足条件的元素的索引;另一种是根据条件进行元素替换。当传入一个条件数组时,它返回一个包含满足条件的元素索引的元组。当传入三个参数(条件、x、y)时,它会根据条件选择 `x` 或 `y` 中的元素。例如: ```python import numpy as np arr = np.array([1, 2, 3, 4, 5]) # 返回满足条件的索引 indices = np.where(arr > 3) print(indices) # 输出: (array([3, 4]),) # 根据条件进行元素替换 new_arr = np.where(arr > 3, 10, arr) print(new_arr) # 输出: [ 1 2 3 10 10] ``` ### `SVC` 函数参数解释 在 Scikit - learn 中,`SVC` 是用于实现支持向量机分类器的函数。 - **`kernel`**:该参数指定了支持向量机使用的核函数。核函数的作用是将输入数据映射到高维空间,使得数据在高维空间中更容易线性可分。常见的核函数有 `'linear'`(线性核)、`'poly'`(多项式核)、`'rbf'`(径向基核,默认值)和 `'sigmoid'`(Sigmoid 核)。不同的核函数适用于不同类型的数据和问题。例如,线性核适用于数据线性可分的情况,而径向基核在处理非线性数据时表现较好。 - **`gamma`**:`gamma` 是核系数,它控制了核函数的影响范围。对于径向基核(`'rbf'`),`gamma` 值越大,每个支持向量的影响范围越小,模型可能会过拟合;`gamma` 值越小,每个支持向量的影响范围越大,模型可能会欠拟合。 - **`C`**:`C` 是惩罚参数,它控制了分类错误的惩罚程度。`C` 值越大,模型对分类错误的惩罚越严重,可能会导致模型更倾向于准确分类训练数据,容易过拟合;`C` 值越小,模型对分类错误的惩罚较轻,可能会导致模型更平滑,容易欠拟合。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值