"Advanced Machine Learning" Udacity machine learning based on the error reason + learning curve and model the complexity of the project predict house prices + Boston

 

 

Error reason

We have discussed some of the basic indicators for measuring the performance of the model, the model now look at what at first appears an error.

In the model prediction, error model that may arise from two main sources, namely: the deviation due to the complexity of the model can not represent the basic data caused (bias), or overly sensitive due to limited data model train caused it uses variance (variance). We will discuss in more detail the two carried out.

Error caused by deviation - accuracy and underfitting

As mentioned earlier, if the model has enough data, but not enough complex to capture the fundamental relationship will deviation. As a result, the model has been systematically error indicates that the data, resulting in reduced accuracy. This phenomenon is called underfitting (underfitting).

In simple terms, if the model is inappropriate, will deviation. For example: If the object is classified by color and shape, but the model can only be distinguished by the color of objects and classify objects (over-simplified model), which has been incorrectly classified objects.

Or, we may have a continuous data polynomials in nature, but can only express a linear relationship model. In this case, we provide data to the model number is not important, because the model simply can not represent the basic relationship between them, we need a more complex model.

Error variance caused by - the accuracy and overfitting

When training model, usually a limited number of samples from a larger training set. If you use a randomly selected subset of data repeated training model, it can be expected that forecasting results will be available to it due to the specific sample to another. Here, the variance (variance) used to measure the change in the prediction result will be much for any given test sample.

Appears variance is normal, but too high variance indicates that the model can not be generalized to predict the result of more data. Highly sensitive to the training set, also known as over-fitting (overfitting), and usually appears in the model is too complicated or we do not have enough data to support it when.

In general, more data can be used for training, in order to reduce the variance of the prediction model and improve the accuracy of the results. If there is no more data it can be used for training, but also to reduce the variance by limiting the complexity of the model.

Improve the effectiveness of the model

我们可以看到,在给定一组固定数据时,模型不能过于简单或复杂。如果过于简单,模型无法了解数据并会错误地表示数据。但是,如果建立非常复杂的模型,则需要更多数据才能了解基本关系,否则十分常见的是,模型会推断出在数据中实际上并不存在的关系。

关键在于,通过找出正确的模型复杂度来找到最大限度降低偏差和方差的最有效点。当然,数据越多,模型随着时间推移会变得越好。

要详细了解偏差和方差,建议阅读 Scott Fortmann-Roe 撰写的这篇文章

除了选定用来训练模型的数据子集外,您使用的哪些来自给定数据集的特征也会显著影响模型的偏差和方差?

 


 

 

学习曲线

让我们根据模型通过可视化图形从数据中学习的能力来探讨偏差与方差之间的关系。

机器学习中的学习曲线是一种可视化图形,能根据一系列训练实例中的训练和测试数据比较模型的指标性能。

在查看数据与误差之间的关系时,我们通常会看到,随着训练点数量的增加,误差会趋于下降。由于我们尝试构建从经验中学习的模型,因此这很有意义。

我们将训练集和测试集分隔开,以便更好地了解能否将模型泛化到未见过的数据而不是拟合到刚见过的数据。

在学习曲线中,当训练曲线和测试曲线均达到稳定阶段,并且两者之间的差距不再变化时,则可以确认模型已尽其所能地了解数据。

 

 

 

理想的学习曲线

模型的最终目标是,误差小并能很好地泛化到未见过的数据(测试数据)。如果测试曲线和训练曲线均收敛,并且误差极低,就能看到这种模型。这种模型能根据未见过的数据非常准确地进行预测。

 

模型复杂度

与学习曲线图形不同,模型复杂度图形呈现的是模型复杂度如何改变训练曲线和测试曲线,而不是呈现用来训练模型的数据点数量。一般趋势是,随着模型增大,模型对固定的一组数据表现出更高的变化性。

 

学习曲线与模型复杂度

那么,学习曲线与模型复杂度之间有何关系?

如果我们获取具有同一组固定数据的相同机器学习算法的学习曲线,但为越来越高的模型复杂度创建几个图形,则所有学习曲线图形均代表模型复杂度图形。这就是说,如果我们获取了每个模型复杂度的最终测试误差和训练误差,并依据模型复杂度将它们可视化,则我们能够看到随着模型的增大模型的表现有多好。

模型复杂度的实际使用

既然知道了能通过分析模型复杂度图形来识别偏差和方差的问题,现在可利用一个可视化工具来帮助找出优化模型的方法。在下一部分中,我们会探讨 gridsearch 和如何微调模型以获得更好的性能。

 


 

问题 2 - 拟合程度

假设一个数据集有五个数据且一个模型做出下列目标变量的预测:

真实数值 预测数值
3.0 2.5
-0.5 0.0
2.0 2.1
7.0 7.8
4.2 5.3

你觉得这个模型已成功地描述了目标变量的变化吗?如果成功,请解释为什么,如果没有,也请给出原因。

提示1:运行下方的代码,使用 performance_metric 函数来计算 y_true 和 y_predict 的决定系数。

提示2$R^2$ 分数是指可以从自变量中预测的因变量的方差比例。 换一种说法:

  • $R^2$ 为0意味着因变量不能从自变量预测。
  • $R^2$ 为1意味着可以从自变量预测因变量。
  • $R^2$ 在0到1之间表示因变量可预测的程度。
  • $R^2$ 为0.40意味着 Y 中40%的方差可以从 X 预测。

第四步. 分析模型的表现

在项目的第四步,我们来看一下不同参数下,模型在训练集和验证集上的表现。这里,我们专注于一个特定的算法(带剪枝的决策树,但这并不是这个项目的重点),和这个算法的一个参数 'max_depth'。用全部训练集训练,选择不同'max_depth' 参数,观察这一参数的变化如何影响模型的表现。画出模型的表现来对于分析过程十分有益,这可以让我们看到一些单看结果看不到的行为。

 

学习曲线

下方区域内的代码会输出四幅图像,它们是一个决策树模型在不同最大深度下的表现。每一条曲线都直观得显示了随着训练数据量的增加,模型学习曲线的在训练集评分和验证集评分的变化,评分使用决定系数R2。曲线的阴影区域代表的是该曲线的不确定性(用标准差衡量)。

运行下方区域中的代码,并利用输出的图形回答下面的问题。

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/JasonPeng1/p/12110070.html