日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

误差模型:过拟合,交叉验证,偏差-方差权衡

發(fā)布時(shí)間:2025/7/25 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 误差模型:过拟合,交叉验证,偏差-方差权衡 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

from:?http://www.voidcn.com/blog/Mark_LQ/article/p-5983585.html

Introduction

In this post you will get to grips with what is perhaps the most essential concept in machine learning: thebias-variance trade-off(偏差-方差權(quán)衡). The main idea here is that you want to create models that areas good at prediction as possible but that are still applicable to new data?(i.e. they are generalizable). The danger is that you can easily create models thatoverfit?to the?local noise in your specific dataset, which isn’t too helpful and leads to poor generalizability since the noise is random and therefore different in each dataset. Essentially, you want to create models that capture only the useful components of a dataset. On the other hand, models that generalize very well but are too inflexible to generate good predictions are the other extreme you want to avoid (this is calledunderfitting).

We discuss and demonstrate these concepts using the?k-nearest neighbors algorithm, which has a simple parameter k which can be varied to cleanly demonstrate these ideas of underfitting, overfitting and generalization(泛化:指模型對(duì)未知樣本的適應(yīng)能力). Together, this bundle of concepts related to the balance between underfitting and overfitting is referred to as the?bias-variance trade-off. Here is a table summarizing some different but related characteristics of models which either underfit or overfit, which you can refer to throughout this post:

We will explain what all of these terms mean and how they are interrelated. We will also discusscross-validation, which is a good way of estimating the accuracy and generalizability of your models.

You will encounter all of these concepts in future blog posts, which will cover model optimization, random forests, Naive Bayes, logistic regression and how to combine different models into an ensembled meta-model.

Generating the dataset

Let’s start off by building an artificial dataset to play with. You can do this easily with themake_classification()?function fromsklearn.datasets. Specifically, you will generate a relatively simple binary classification problem. To make it a bit more interesting, let’s make the data?crescent-shaped and add some random noise(數(shù)據(jù)呈現(xiàn)月牙型并加入一些隨機(jī)噪聲). This should make it more realistic and increase the difficulty of classifying observations.

<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># Creating the dataset</span> <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># e.g. make_moons generates crescent-shaped data</span> <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># Check out make_classification, which generates linearly-separable data</span> <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">from</span> sklearn.datasets <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">import</span> make_moonsX, y =make_moons(n_samples=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">500</span>, <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># the number of observations</span>random_state=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>,noise=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0.3</span> )<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># Take a peek</span> print(X[:<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">10</span>,]) print(y[:<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">10</span>])

The dataset you just generated looks a bit like this: [[ 0.50316464 0.11135559][ 1.06597837 -0.63035547][ 0.95663377 0.58199637][ 0.33961202 0.40713937][ 2.17952333 -0.08488181][ 2.00520942 0.7817976 ][ 0.12531776 -0.14925731][ 1.06990641 0.36447753][-0.76391099 -0.6136396 ][ 0.55678871 0.8810501 ]] [1 1 0 0 1 1 1 0 0 0] <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">import</span> matplotlib.pyplot <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">as</span> plt <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">from</span> matplotlib.colors <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">import</span> ListedColormap%matplotlib inline <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># for the plots to appear inline in jupyter notebooks</span><span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># Plot the first feature against the other, color by class</span> plt.scatter(X[y == <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>], X[y==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>], color=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"#EE3D34"</span>, marker=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"x"</span>) plt.scatter(X[y == <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>], X[y==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>], color=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"#4458A7"</span>, marker=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"o"</span>)

Next up, let’s?split the dataset into a?training set?andtest set.?The training set will be used to develop and tune our models. The test set will be completely left alone until the very end, at which point you’ll run your finished models on it. Having a test set will allow you to get a good estimate of how well your models would perform out in the wild on previously unseen data.

<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">from</span> sklearn.cross_validation <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">import</span> train_test_split<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># Split into training and test sets</span> XTrain, XTest, yTrain, yTest= train_test_split(X, y, random_state=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>, test_size=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0.5</span>)

You are going to try to predict the classes in our dataset with a k Nearest Neighbor (kNN) classifier. Chapter 2 of theIntroduction to Statistical Learning?book provides a great intro to the theory behind kNN. We are huge fans of the ISLR book, so definitely check it out if you have the time. You could also have a look at this previous post that teaches youhow to implement the algorithm from scratch in Python.

Introducing the k hyperparameter in kNN

The kNN algorithm works by using information about the k-nearest neighbors of a new data point in order to assign it a class label. It simply looks at the class of other data points most similar to it (its ‘nearest neighbors’) and assigns the new data point to the most common class of these neighbors. When using kNN, you have to set the value ofk?that you want the algorithm to use ahead of time, and it is not trivial to know which value to use.

If the value for?k?is high (e.g.?k=99), then the model considers a large number of neighbors when making a a decision about the class of an unknown datapoint. This means that the model is quite constrained, since it has to take a large amount of information into account when classifying instances. In other words, a high number fork?give rise to relatively “rigid” model behaviour.

By contrast, if the value for?k?is low (e.g.?k=1?or?k=2), then only a few neighbors are taken into account when making a classification decision. It is a very flexible model with a lot of complexity – it really fits very closely to the precise shape of the dataset. Hence, the predictions of the model are much more dependent on the local tendencies of the data (crucially, this includes the noise!).

Take a look at how the kNN algorithm separates the training cases when?k=99?compared to whenk=1. The green line is the decision boundary on the training data (i.e. the threshold at which the algorithm decides whether a data point belong in the blue or red class).

At the bottom of the post you learn how to generate these plots yourself, but let’s delve into some theory first.

When?k=99?(on the left), it looks like the model fit might be a bit too smooth and could stand to fit the data a bit closer. The model haslow flexibility?and?low complexity. It paints the decision boundary with a broad brush. It has relativelyhigh bias?because one can tell it is not modelling the data as well as it could – it models the underlying generative process of the data as something too simple, and this is highly biased away from the ground truth. But, the decision boundary would probably look very similar if you redrew it on a slightly different dataset. It is a stable model that won’t vary a lot – it haslow variance.

When?k=1?(on the right), you can see that the model is?massively overfitting to the noise.?It is technically generating perfectly correct predictions on the training set (the error in the bottom right hand corner is equal to 0.00!), but hopefully you can see how this fit is way too sensitive to individual data points. Keep in mind that you added noise to the dataset – it looks like this model fit is taking the noise too seriously and is fitting very closely to it. You can say that thek=1?model has?high flexibility?andhigh complexity?because it tunes very tightly to the data. It also haslow bias?– if nothing else, the decision boundary certainly fits the trends you observe in the data. But, the fitted boundary would drastically change on even slightly different data – it would vary significantly, i.e. the?k=1?model has?high variance.

But how well do these models?generalize, i.e. how well would they perform on new data?

You have so far only looked at the training data, but quantifying training error isn’t that useful. You are not interested in how well models can recapitulate what they just learned on the training set.Let’s take a look at how they perform on test data, since that gives a better impression of whether your models are actually good or not. Try it yourself using a few different values ofk:

<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">from</span> sklearn.neighbors <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">import</span> KNeighborsClassifier <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">from</span> sklearn <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">import</span> metricsknn99 =KNeighborsClassifier(n_neighbors =<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">99</span>) knn99.fit(XTrain, yTrain) yPredK99 = knn99.predict(XTest) <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">print</span><span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Overall Error of k=99 Model:"</span>,<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span> - round(metrics.accuracy_score(yTest, yPredK99), <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">2</span>)knn1 =KNeighborsClassifier(n_neighbors =<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>) knn1.fit(XTrain, yTrain) yPredK1 = knn1.predict(XTest) <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">print</span><span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Overall Error of k=1 Model:"</span>,<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span> - round(metrics.accuracy_score(yTest, yPredK1), <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">2</span>)

Overall Error of k=99 Model: 0.15 Overall Error of k=1 Model: 0.15

Actually, it looks like these models perform approximately equally well on the test data. Here are the decision boundaries you learned on the training set, applied to the test set. See if you can figure out where the two models are making their mistakes.

The two models are making mistakes for very different reasons. It seems that thek=99?model isn’t doing a good job at capturing the crescent shape of the data (it isunderfitting), while the?k=1?model is making mistakes by being horriblyoverfitted?to the noise. Remember, the hallmark of overfitting is good training performance and bad testing performance, which is what you observe here.

Maybe intermediate values of k are where you want to be? Try a value of k between 99 and 1, e.g.:

knn50 =KNeighborsClassifier(n_neighbors =<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">50</span>) knn50.fit(XTrain, yTrain) yPredK50 = knn50.predict(XTest) <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">print</span><span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Overall Error of k=50 Model:"</span>,<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span> - round(metrics.accuracy_score(yTest, yPredK50), <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">2</span>)
Overall Error of k=50 Model: 0.11

Looking better! Let’s check out the decision boundary for the k=50 model.

Much better – the model fit is similar to the actual trend in the dataset and this improvement is reflected in a lower test set error.

The bias-variance trade-off: concluding comments

Hopefully you now have a good intuition for what it means for models to underfit and overfit. See if all of the terms in the table at the beginning of this post now make sense.?Basically, finding the right balance between overfitting and underfitting corresponds to the bias-variance trade-off.

To recap, when you train machine learning algorithms on a data set, what you are really interested in ishow your model will perform on an independent data set.?It is not enough to do a good job classifying instances on the training set. Essentially, you are only interested in building models that aregeneralizable(提高泛化能力)?– getting 100% accuracy on the training set is not impressive, and is simply an indicator ofoverfitting. Overfitting is the situation in which you have fitted your model too closely to the data, and have tuned to the noise instead of just to the signal.

To be clear: strictly speaking, you are not trying to model the trends in the dataset. You try to model the real world process that has led to us observing the data. The specific dataset you happen to be working with is just a small set of instances (i.e. a sample) of the ground truth, which brings with it its own noise and peculiarities.

Here is a summary figure showing how?under-fitting (high bias, low variance), properly fitting, andover-fitting (low bias, high variance)models fare on the training compared to the test sets:

This idea of building generalizable models is the motivationg your dataset into atraining set?(on which models can be trained) and a?test set?(which is held out until the very end of your analysis, and provides an accurate measure of model performance).

But –?BIG?warning! It’s also possibly to overfit to the test set. If you were to try out lots of different models and keep changing them in order to chase accuracy points on the test set, then the information from the test set can inadvertentlyleak?into our model creation phase. You need a way around this.

Estimating model performance using k-fold cross validation

Enter?k-fold cross-validation, which is a handy technique for measuring a model’s performance usingonly?the training set. Say that you want to do e.g. 10-fold cross-validation. The process is as follows:you randomly partition the training set into 10 equal sections.Then, we train an algorithm on 9/10ths (i.e. 9 out of the 10 sections) of that training set. You then evaluate its performance on the remaining 1 section. This gives you some measure of the model’s performance (e.g. overall accuracy). You then train the algorithm on a?different9/10ths of the training set, and evaluate on the other (different from before) remaining 1 section.You continue the process 10 times, get 10 different measures of model performance, and average these values to get an overall measure of performance.?Of course, you could have chosen some number other than 10. To keep on with the example, the process behind 10-fold CV looks like this:

You can use k-fold cross validation to get an estimate of model accuracy, and you can use these estimates to tweak(調(diào)整) your model until you are happy. This lets you leave the test data alone until the very end, thus side-stepping the danger of overfitting to it. In other words, cross-validation provides a way to simulate having more data than you actually have so that you do not have to “spend” your test data until the very end of model building.?k-fold cross validation, and its variants, are extremely popular and very useful, especially if you’re trying out lots and lots of different models?(e.g. if you want to test how well a load of differently parameterized models perform).

Comparing training error, cross-validation error, and test error

So what would be the best value for?k(k指的是K-NN算法中的參數(shù)k)? Try out different values fork?when building models with the training data and see how well the resulting models fare when predicting the classes of either the training set itself or the test set. Finally, see how well k-fold cross validation will be at indicating the bestk.

Note: in practice, when scanning a parameter like this, it would be a bad idea to use the training set for testing the model. In equal measure, you would never scan a parameter using the test set multiple times (once for each parameter value tried). In the following plot you use these calculations just as an illustration to see what they would look like. In practice, only k-fold cross validation is a safe approach!

<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">import</span> numpy <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">as</span> np <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">from</span> sklearn.cross_validation <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">import</span> train_test_split, cross_val_scoreknn =KNeighborsClassifier()<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># the range of number of neighbors you want to test</span> n_neighbors = np.arange(<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>,<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">141</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">2</span>)<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># here you store the models for each dataset used</span> train_scores = list() test_scores = list() cv_scores = list()<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># loop through possible n_neighbors and try them out</span> <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">for</span> n <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">in</span> n_neighbors:knn.n_neighbors= nknn.fit(XTrain, yTrain)train_scores.append(<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>- metrics.accuracy_score(yTrain, knn.predict(XTrain))) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># this will over-estimate the accuracy</span>test_scores.append(<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>- metrics.accuracy_score(yTest, knn.predict(XTest)))cv_scores.append(<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>- cross_val_score(knn, XTrain, yTrain, cv= <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">10</span>).mean()) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># you take the mean of the CV scores</span>So what would be the best value to pick for?k? When multiple values are giving the same prediction error, you just pick the smallest value for?k. <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># what do these different datasets think is the best value of k?</span> print(<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'The best values of k are:\n'</span>\<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'{} according to the Training Set\n'</span>\<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'{} according to the Test Set and\n'</span>\<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'{} according to Cross-Validation'</span>.format(min(n_neighbors[train_scores==min(train_scores)]),min(n_neighbors[test_scores==min(test_scores)]),min(n_neighbors[cv_scores==min(cv_scores)]) ) )
The best values of k are: 1 according to the Training Set 23 according to the Test Set and 11 according to Cross-Validation

Rather than just collecting the best?ks, have a peek at what the prediction error is over the range ofks tested.

<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># let's plot the error you get with different values of k</span> plt.figure(figsize=(<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">10</span>,<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">7.5</span>)) plt.plot(n_neighbors, train_scores, c=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"black"</span>, label=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Training Set"</span>) plt.plot(n_neighbors, test_scores, c=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"black"</span>, linestyle=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"--"</span>, label=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Test Set"</span>) plt.plot(n_neighbors, cv_scores, c=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"green"</span>, label=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Cross-Validation"</span>) plt.xlabel(<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'Number of K Nearest Neighbors'</span>) plt.ylabel(<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'Classification Error'</span>) plt.gca().invert_xaxis() plt.legend(loc = <span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"lower left"</span>) plt.show()

Let’s talk about the classification error on the training set. The fewer neighbors you consider, the lower the prediction error when evaluating the models on the training set (black solid line). This makes sense, since you approach the scenario where each point only considers its own self when making new classifications, which leads to perfect “predictions”. The test data error follows a similar trajectory, but experiences an increase after a certain point because of?local overfitting. This behaviour indicates that now the specific test set sample is not modelled very well by the model fit which was built on the training data.

In this plot, you see that especially for low values of?k, using k-fold cross-validation highlights a region in the parameter space (i.e. very low values ofk) that is very prone to overfitting. Even though cross-validation and the test set evaluation lead to somewhat different optima, they are both pretty decent and you are clearly in the right ballpark. You can also see that cross-validation is a reasonable estimator of test error. This type of plot is nice to study in order to get a good feeling for how a certain parameter influences model performance and help build an intuition about your dataset.

Just show me the code!

Here is the code for generating the above plots, and doing the training and testing of different kNN algorithms. This code is an adapted version ofthis scikit-learn example, and most it deals with the finicky details of calculating decision boundaries and making the plots look nice. The meaty machine learning parts of splitting the dataset, fitting the algorithm, and testing it were covered above.

<span class="hljs-function" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background: transparent;"><span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">def</span> <span class="hljs-title" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(25, 70, 157); background: transparent;">detect_plot_dimension</span><span class="hljs-params" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(0, 0, 255); background: transparent;">(X, h=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0.02</span>, b=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0.05</span>)</span>:</span>x_min, x_max= X[:, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>].min()- b, X[:, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>].max()+ by_min, y_max= X[:, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>].min()- b, X[:, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>].max()+ bxx, yy= np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))dimension= xx, yyreturndimension<span class="hljs-function" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background: transparent;"><span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">def</span> <span class="hljs-title" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(25, 70, 157); background: transparent;">detect_decision_boundary</span><span class="hljs-params" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(0, 0, 255); background: transparent;">(dimension, model)</span>:</span>xx, yy= dimension <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># unpack the dimensions</span>boundary= model.predict(np.c_[xx.ravel(), yy.ravel()])boundary= boundary.reshape(xx.shape) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># Put the result into a color plot</span>returnboundary<span class="hljs-function" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background: transparent;"><span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">def</span> <span class="hljs-title" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(25, 70, 157); background: transparent;">plot_decision_boundary</span><span class="hljs-params" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(0, 0, 255); background: transparent;">(panel, dimension, boundary, colors=[<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'#DADDED'</span>,<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'#FBD8D8'</span>])</span>:</span>xx, yy= dimension <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># unpack the dimensions</span>panel.contourf(xx, yy, boundary, cmap=ListedColormap(colors), alpha=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>)panel.contour(xx, yy, boundary, colors=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"g"</span>, alpha=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>, linewidths=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0.5</span>) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># the decision boundary in green</span><span class="hljs-function" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background: transparent;"><span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">def</span> <span class="hljs-title" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(25, 70, 157); background: transparent;">plot_dataset</span><span class="hljs-params" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(0, 0, 255); background: transparent;">(panel, X, y, colors=[<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"#EE3D34"</span>,<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"#4458A7"</span>], markers=[<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"x"</span>,<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"o"</span>])</span>:</span>panel.scatter(X[y==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>], X[y==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>], color=colors[<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>], marker=markers[<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>])panel.scatter(X[y==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>], X[y==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>], color=colors[<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>], marker=markers[<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>])<span class="hljs-function" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background: transparent;"><span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">def</span> <span class="hljs-title" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(25, 70, 157); background: transparent;">calculate_prediction_error</span><span class="hljs-params" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(0, 0, 255); background: transparent;">(model, X, y)</span>:</span>yPred= model.predict(X)score= <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span> - round(metrics.accuracy_score(y, yPred),<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">2</span>)returnscore<span class="hljs-function" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background: transparent;"><span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">def</span> <span class="hljs-title" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(25, 70, 157); background: transparent;">plot_prediction_error</span><span class="hljs-params" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(0, 0, 255); background: transparent;">(panel, dimension, score, b=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">.3</span>)</span>:</span>xx, yy= dimension <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># unpack the dimensions</span>panel.text(xx.max()- b, yy.min()+ b, (<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'%.2f'</span>% score).lstrip(<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'0'</span>), size=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">15</span>, horizontalalignment=<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'right'</span>)<span class="hljs-function" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background: transparent;"><span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">def</span> <span class="hljs-title" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(25, 70, 157); background: transparent;">explore_fitting_boundaries</span><span class="hljs-params" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(0, 0, 255); background: transparent;">(model, n_neighbors, datasets, width)</span>:</span> <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># determine the height of the plot given the aspect ration of each panel should be equal</span>height= float(width)/len(n_neighbors)* len(datasets.keys())nrows= len(datasets.keys())ncols= len(n_neighbors)<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># set up the plot</span>figure, axes= plt.subplots(nrows,ncols,figsize=(width, height),sharex=<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">True</span>,sharey=<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">True</span>)dimension= detect_plot_dimension(X, h=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0.02</span>) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># the dimension each subplot based on the data</span><span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># Plotting the dataset and decision boundaries</span>i= <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>forn <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">in</span> n_neighbors:model.n_neighbors= nmodel.fit(datasets[<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Training Set"</span>][<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>], datasets[<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Training Set"</span>][<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>])boundary= detect_decision_boundary(dimension, model)j= <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>ford <span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">in</span> datasets.keys():<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">try</span>:panel= axes[j, i]<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">except</span>(TypeError, IndexError):<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">if</span>(nrows * ncols) ==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>:panel= axeselifnrows ==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>: <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># if you only have one dataset</span>panel= axes[i]elifncols ==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>: <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># if you only try one number of neighbors</span>panel= axes[j]plot_decision_boundary(panel, dimension, boundary) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># plot the decision boundary</span>plot_dataset(panel, X=datasets[d][<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>], y=datasets[d][<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>]) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># plot the observations</span>score= calculate_prediction_error(model, X=datasets[d][<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>], y=datasets[d][<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>])plot_prediction_error(panel, dimension, score, b=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0.2</span>) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># plot the score</span><span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># make compacted layout</span>panel.set_frame_on(<span class="hljs-keyword" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(149, 65, 33); background: transparent;">False</span>)panel.set_xticks([])panel.set_yticks([])<span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># format the axis labels</span>ifi ==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>:panel.set_ylabel(d)ifj ==<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>:panel.set_title(<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">'k={}'</span>.format(n))j+=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>i+=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span> plt.subplots_adjust(hspace=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>, wspace=<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">0</span>) <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># make compacted layout</span>You can then run the code like this: <span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># specify the model and settings</span> model =KNeighborsClassifier() n_neighbors = [<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">200</span>,<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">99</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">50</span>,<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">23</span>, <span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">11</span>,<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">1</span>] datasets = {<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Training Set"</span>: [XTrain, yTrain],<span class="hljs-string" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(33, 145, 97); background: transparent;">"Test Set"</span>: [XTest, yTest] } width =<span class="hljs-number" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(64, 160, 112); background: transparent;">20</span><span class="hljs-comment" style="border: 0px; margin: 0px; padding: 0px; font-weight: inherit; font-style: italic; font-family: inherit; vertical-align: baseline; color: rgb(64, 128, 128); background: transparent;"># explore_fitting_boundaries(model, n_neighbors, datasets, width)</span> explore_fitting_boundaries(model=model, n_neighbors=n_neighbors, datasets=datasets, width=width)

Conclusion

The bias-variance trade-off appears in a lot of different areas of machine learning. All algorithms can be considered to have a certain degree of flexibility and this is certainly not specific to kNN. The goal of finding the sweet spot of flexibility that describes the patterns in the data well but is still generalizable to new data applies to basically all algorithms.

總結(jié)

以上是生活随笔為你收集整理的误差模型:过拟合,交叉验证,偏差-方差权衡的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

国产视频一区二区三区在线 | 天天综合操| 一级性视频 | 91中文字幕 | 一色av | 中文字幕.av.在线 | 久久成人国产 | 日韩精品中文字幕在线不卡尤物 | 亚洲黄色一级大片 | 天堂入口网站 | 亚洲精品动漫在线 | 欧美小视频在线 | 亚洲va天堂va欧美ⅴa在线 | 综合五月 | 韩国av免费看| 成人午夜精品久久久久久久3d | 欧美日韩另类视频 | 免费av黄色| avav99| 久久国语露脸国产精品电影 | 精品国产一区二 | 成人免费视频播放 | 亚洲精品国产视频 | 久久一本综合 | 精品国产乱码久久久久久1区二区 | 亚洲日本一区二区在线 | 中文字幕二区在线观看 | 精品国产乱码久久 | av不卡免费在线观看 | 亚洲成av人片| 久久综合精品一区 | 国产成人综合在线观看 | 日日夜夜综合网 | 久久免费国产电影 | 成人网中文字幕 | 91伊人影院| 亚洲精品中文字幕在线 | 久亚洲| 国产在线观看一 | 国产精品美女999 | av网址最新| 国产一级精品视频 | 国产精品不卡av | 欧美激情视频在线观看免费 | 免费看一级特黄a大片 | 成人黄色av网站 | 亚洲涩涩涩涩涩涩 | 97精品超碰一区二区三区 | 精品国产免费观看 | 亚洲免费精品一区二区 | 久久久激情网 | 99视频在线免费 | 夜夜夜夜猛噜噜噜噜噜初音未来 | 婷婷亚洲综合 | 久久欧美精品 | 成人久久免费 | 91在线文字幕 | 丁香五婷| 在线观看视频你懂得 | 亚洲天堂首页 | 亚洲九九九在线观看 | 成人午夜黄色影院 | 在线播放亚洲激情 | 成人午夜电影久久影院 | 成年人黄色在线观看 | 91丨九色丨勾搭 | 日韩精品五月天 | 在线亚洲欧美视频 | 视频精品一区二区三区 | 黄色软件视频大全免费下载 | 精品国产网址 | 91福利试看| 国产 日韩 在线 亚洲 字幕 中文 | 四虎视频 | a在线免费 | 天天插天天干天天操 | 亚洲爽爽网 | 国产精品理论片在线观看 | wwwav视频| 视频91在线 | 欧美成人中文字幕 | 国产伦精品一区二区三区照片91 | 亚洲美女精品区人人人人 | 久久久久99精品成人片三人毛片 | 波多野结衣在线播放一区 | 成人国产综合 | 激情婷婷综合 | 狠狠躁日日躁夜夜躁av | 国产999精品久久久影片官网 | 久99久中文字幕在线 | 亚洲理论电影网 | 9免费视频| 亚洲色图av | 国产精品一码二码三码在线 | 天天射天天做 | 亚洲精品国产综合99久久夜夜嗨 | 中文字幕免费观看全部电影 | 欧美精品久久天天躁 | 中文字幕在线视频网站 | 久久免费电影网 | 五月婷婷一级片 | 91九色在线播放 | 毛片888 | 91经典在线 | 激情校园亚洲 | 久久色亚洲 | www.色五月 | 日韩精品一区二区三区免费视频观看 | 亚洲.www | 亚洲福利精品 | 性色av一区二区三区在线观看 | 久久久精品高清 | 亚洲精品视频在线免费播放 | 天天操狠狠操网站 | 久草视频在线免费看 | 久久精品久久久久久久 | 亚洲欧美精品一区二区 | 天天操天天干天天爽 | 日韩欧美视频一区二区三区 | 欧美va天堂va视频va在线 | 免费观看一区二区三区视频 | 少妇搡bbbb搡bbb搡aa | 久久成人午夜视频 | av不卡免费在线观看 | 国产成人在线播放 | 99色网站 | 国产精品1区2区在线观看 | 99在线热播精品免费99热 | 国内三级在线 | 91精品视频一区二区三区 | 国产精品毛片久久久久久久久久99999999 | 91理论片午午伦夜理片久久 | 91大神免费在线观看 | 日日干网址 | 日韩欧美视频在线免费观看 | 一区二区三区免费播放 | 亚洲色图美腿丝袜 | 婷婷干五月 | 探花视频在线观看免费 | 欧美怡红院视频 | 国产免费小视频 | 欧美一区成人 | 99热在线精品观看 | 1区2区3区在线观看 三级动图 | 久久av在线 | 亚洲综合国产精品 | 久久天天躁夜夜躁狠狠躁2022 | 欧美嫩草影院 | 久久精品久久精品久久精品 | 91一区二区在线 | 欧美日韩免费一区二区三区 | 17婷婷久久www | 99免费在线播放99久久免费 | 992tv在线 | 国产亚洲精品久久久网站好莱 | 欧美男同网站 | 99久久精品视频免费 | 综合在线观看色 | 午夜美女福利 | 国产一线二线三线在线观看 | 久久婷婷综合激情 | 九九免费在线观看视频 | 激情久久久久久久久久久久久久久久 | 91麻豆操| 国产91影视 | 色婷婷狠 | 国产精品99久久久久 | 奇米影音四色 | 天堂在线视频中文网 | 福利在线看片 | 蜜臀久久99精品久久久酒店新书 | 四虎影视成人精品国库在线观看 | www.天堂av| 九九热在线视频免费观看 | 精品久久久久久综合 | 久久精品国产精品 | 国产精品一区久久久久 | 久久优| 国产亚洲视频在线免费观看 | 91在线播放综合 | 国产精品自产拍在线观看蜜 | av片在线观看免费 | 国产精品你懂的在线观看 | 久久婷婷久久 | 天堂网一区二区 | 久久久91精品国产一区二区精品 | 91麻豆产精品久久久久久 | 日本激情视频中文字幕 | 久久国产色 | 免费在线国产视频 | 97视频在线观看视频免费视频 | 国产成人香蕉 | 成人av资源站| 午夜久久久久久久 | 亚洲国产精品传媒在线观看 | 国产黄色片在线 | 日韩字幕在线观看 | 天天天操天天天干 | 在线观看成人国产 | 久久精品91久久久久久再现 | 久久免费黄色大片 | 日韩精品免费在线播放 | 狠狠久久综合 | 日韩久久影院 | 国产精品夜夜夜一区二区三区尤 | 蜜臀av性久久久久av蜜臀妖精 | 国产精品va在线播放 | 韩日色视频 | 国产一区二区三区高清播放 | 四虎影视成人永久免费观看亚洲欧美 | 蜜臀av麻豆 | 免费进去里的视频 | 国产三级视频在线 | 91超国产| 激情伊人五月天久久综合 | 欧美精品在线观看免费 | 国产一级特黄毛片在线毛片 | 五月婷婷视频 | 高清久久久久久 | 亚州成人av在线 | 久久久久免费精品国产 | 欧美日韩精品在线视频 | 9幺看片 | 日韩久久一区二区 | 中文字幕免费看 | 久久伊人色综合 | 首页国产精品 | 综合色亚洲 | 一区三区视频在线观看 | 免费视频久久久久久久 | 成人国产精品久久久久久亚洲 | 免费观看国产视频 | 中文国产字幕 | 色网站在线观看 | 中文字幕第一页在线 | 中文字幕 第二区 | 中文字幕在线资源 | 狠狠狠狠狠狠狠干 | 国产在线a视频 | 久久久男人的天堂 | 日本一区二区三区视频在线播放 | 999久久| 久久99久久99精品免观看粉嫩 | 久久久国产精品人人片99精片欧美一 | 伊人电影在线观看 | 福利视频在线看 | 午夜视频在线观看一区 | 国产精品露脸在线 | 在线激情小视频 | 欧美在线观看小视频 | 99热只有精品在线观看 | 黄色小说免费在线观看 | 99视频播放 | 国产精品久久久久久久久毛片 | a在线一区 | 免费看黄20分钟 | 国产va在线 | 精品国产中文字幕 | 黄色三级av | 天天干,狠狠干 | 国产精品久久一区二区三区, | 在线观看黄网 | 99精品免费在线观看 | 国产一区网址 | 美女一区网站 | 国产精品免费观看在线 | 天天操狠狠操网站 | 亚洲一区尤物 | 91你懂的 | 人人爱人人添 | 激情久久五月 | 西西人体4444www高清视频 | 欧美精品一区二区免费 | 日韩精品视频一二三 | 奇米影视8888在线观看大全免费 | 成人国产精品久久久久久亚洲 | 免费看特级毛片 | 激情av网址 | 欧美日韩在线免费观看 | 中文字幕在线观看一区二区三区 | 综合激情av | 久久精品久久久久久久 | 黄色福利 | 国际精品久久久 | 99精品观看| 久久国产精品一区二区三区四区 | 久久综合九色欧美综合狠狠 | 午夜三级毛片 | 中文伊人| 久久久久久久国产精品影院 | 久久久影视 | 伊人网av | www.国产精品 | 久久福利 | 99精品在线观看视频 | 最新国产福利 | 97超碰.com | 中文字幕精品久久 | 中文字幕观看av | 欧美激情xxxx性bbbb | 91九色视频在线观看 | 五月综合色婷婷 | 99精品视频中文字幕 | 91久久黄色 | 在线观看色视频 | 国产精品自产拍在线观看网站 | 国产成人一区二区三区在线观看 | 日韩一区在线免费观看 | 婷婷在线视频观看 | 久久久天堂 | 中文字幕在线免费看线人 | 日本精品中文字幕 | wwxxx日本| 大片网站久久 | 色婷婷免费视频 | 国产视频亚洲视频 | 91av视频在线观看免费 | 丁香电影小说免费视频观看 | 国产在线观看高清视频 | 99久精品 | 久久99精品国产麻豆婷婷 | 毛片美女网站 | 中文国产在线观看 | 国产亚洲久久 | 我要色综合天天 | www.av免费| 97超碰在线人人 | 国产在线看一区 | 奇米777777| 国产一级大片在线观看 | 亚洲午夜精品一区 | 国产精品女人久久久久久 | 91丨九色丨国产丨porny精品 | 中文字幕观看在线 | 国产小视频免费在线观看 | 欧美日韩视频免费 | 日日日网 | 美女视频永久黄网站免费观看国产 | 美女黄频免费 | 最新国产在线 | 欧美特一级 | 国精产品永久999 | 午夜美女网站 | 久久无码av一区二区三区电影网 | 99热这里只有精品1 av中文字幕日韩 | 婷婷四房综合激情五月 | 91网免费看| 日本黄色片一区二区 | 国产精品刺激对白麻豆99 | 美女国产网站 | 国产精品久久久久久妇 | 狠狠狠狠狠狠狠干 | 人人草在线视频 | 亚洲成a人片在线www | 成人av播放 | 成人欧美亚洲 | 91av综合| 久久高清视频免费 | 激情丁香久久 | 欧美黄网站 | 亚洲视频久久久 | 91精品久久久久久综合乱菊 | 狠狠色丁香婷婷综合久小说久 | av经典在线 | 97超级碰碰 | 91在线视频观看 | 久久人人射| 久久国语露脸国产精品电影 | 亚一亚二国产专区 | 天天干天天玩天天操 | 波多野结衣精品在线 | 国产又粗又硬又长又爽的视频 | 92中文资源在线 | 免费高清男女打扑克视频 | 日韩v在线 | 国产伦精品一区二区三区免费 | 97视频在线免费 | 久艹视频在线观看 | 久久精品电影院 | 久久高清视频免费 | 日韩欧美精品在线观看 | 国产精品一区二区在线免费观看 | 日韩免费一级a毛片在线播放一级 | 一级片免费视频 | 国产精品视频线看 | 日韩在线观看的 | 精品国模一区二区 | 亚洲理论在线 | 国产视频一区二区在线播放 | 久操中文字幕在线观看 | 国产精品va最新国产精品视频 | 久久伦理视频 | 少妇搡bbb| 天天射天天爽 | 福利网在线| 欧美孕交vivoestv另类 | 在线中文字幕播放 | 中文在线字幕观看电影 | 天天激情站 | 人人爽人人av | 婷婷视频 | 亚洲精品人人 | 超碰在线天天 | 国产亚洲va综合人人澡精品 | 丁香六月在线观看 | 国产综合在线视频 | 亚洲成a人片77777潘金莲 | www.夜色.com| 日韩高清成人在线 | 91视频专区| 久久网页 | 久久五月网 | www.色午夜,com| 午夜精品在线看 | 欧美专区国产专区 | 一本—道久久a久久精品蜜桃 | 免费福利片2019潦草影视午夜 | 欧美日在线观看 | 欧美一级艳片视频免费观看 | 国产专区一 | 久久久久久免费网 | 国产精品久久久久久久久久新婚 | 最新国产精品拍自在线播放 | 黄a网站| 国产91成人| 日韩av黄 | 亚洲 综合 专区 | 91麻豆精品国产91久久久无限制版 | 婷婷丁香激情网 | 久久国内精品视频 | 欧美一级久久 | 国产91精品一区二区 | 不卡的av中文字幕 | 天天色欧美 | 97超碰香蕉 | 日本aaaa级毛片在线看 | 欧美日韩精品在线播放 | 久久久91精品国产一区二区三区 | 国产精品一区二区免费 | 免费观看版 | 精品福利国产 | 一区二区三区免费 | 久久成年人| 激情久久综合网 | 国产美女精品 | 国产中文字幕在线播放 | 国产亚洲精品久久久久5区 成人h电影在线观看 | 久久狠狠一本精品综合网 | 日日夜夜精品视频天天综合网 | 色综合天天干 | 麻豆视频国产精品 | h网站免费在线观看 | 天天综合网在线观看 | 在线天堂亚洲 | 亚洲最大免费成人网 | 麻豆国产网站 | 亚洲精品ww| 中日韩免费视频 | 色5月婷婷 | 久久这里只精品 | 欧美色综合天天久久综合精品 | 日韩电影黄色 | 欧美日韩国产在线观看 | 国产精品综合久久久久久 | 日韩在线观看你懂得 | 国产精品av一区二区 | 夜夜躁狠狠躁 | 激情综合网五月激情 | 免费不卡中文字幕视频 | 国产视频 亚洲精品 | 久久99在线 | 日韩一区二区三区在线观看 | 国产一级片免费播放 | 久久久网站 | 久久免费看 | 99精品视频99 | 伊人www22综合色 | av网站地址 | 午夜视频免费在线观看 | 麻豆国产精品一区二区三区 | 美女在线黄 | 日韩电影在线一区二区 | 亚洲日本一区二区在线 | 久久国产精品一区二区三区四区 | av黄色影院 | 亚洲伦理中文字幕 | 久草电影免费在线观看 | 激情五月婷婷综合 | 日韩在线视频观看免费 | 中文字幕在线视频一区 | 深爱五月激情网 | 一区二区三区韩国免费中文网站 | 国产亚洲视频在线观看 | 激情五月婷婷激情 | av在线一二三区 | 激情婷婷亚洲 | 在线观看视频国产 | 国产亚洲资源 | av电影 一区二区 | 激情av五月婷婷 | 四虎www com| 免费看片成年人 | 国产精品久久久久久久99 | 99在线高清视频在线播放 | 毛片区 | 狠狠的干狠狠的操 | 日韩 在线观看 | 国产美女久久久 | 99免费观看视频 | 国产精品毛片一区二区三区 | 一区二区三区在线免费观看 | 天天玩天天操天天射 | 成人毛片一区 | 久久免费试看 | 亚洲va欧美 | 色播亚洲婷婷 | 国产成人777777 | 色视频网站在线 | 免费一级片观看 | 精品毛片在线 | 91精品国产99久久久久久久 | 亚洲天天看 | 亚洲爱av | 黄色avwww| 中文字幕高清在线播放 | 婷婷资源站 | 丁香视频在线观看 | 国产在线免费观看 | 亚洲丝袜中文 | 超碰电影在线观看 | 国产精品ⅴa有声小说 | 999色视频 | 在线播放 日韩专区 | www国产精品com | 9ⅰ精品久久久久久久久中文字幕 | 久久久午夜视频 | 中文在线中文a | 国产精品一区二区 91 | 成年人免费看片网站 | 久久精品欧美一区 | 日韩xxxxxxxxx | 国产精品原创视频 | 涩涩色亚洲一区 | av在线免费在线观看 | 精品视频免费看 | 91精品国自产在线观看 | 超碰999| av中文电影| 在线观看视频你懂 | 黄色一级大片在线观看 | 狠狠干激情 | 一区二区精品久久 | 最近中文字幕高清字幕在线视频 | 久久久69| 国产精品欧美一区二区三区不卡 | 夜夜躁狠狠躁日日躁 | 久久精品黄 | 手机在线小视频 | 久久精品久久综合 | 国产一区二区三区免费在线 | 国产在线一线 | 国产精品久久久久久69 | 午夜精品久久久久久久99 | 中文字幕丰满人伦在线 | 在线国产视频一区 | 久久99精品久久久久蜜臀 | 99精品国产一区二区三区麻豆 | 国产精品久久久久久久婷婷 | av中文天堂 | av一区二区在线观看中文字幕 | 亚洲成年人免费网站 | 公开超碰在线 | 日韩午夜三级 | 福利一区二区在线 | 五月婷婷色丁香 | 国产成人一区二区三区久久精品 | 国产日韩精品一区二区 | 精品国产a| 美女久久视频 | 亚洲成人av一区 | 人人搞人人干 | 蜜臀久久99精品久久久酒店新书 | 日日干夜夜操视频 | 国产在线免费观看 | 三级大片网站 | 一区二区三区在线免费播放 | av免费观看网站 | 日韩二区三区在线 | 久久久国产成人 | 最近免费在线观看 | 天堂av在线网址 | 亚洲撸撸 | 美女视频久久黄 | 一区精品久久 | 97免费在线观看视频 | 在线va视频| 中文字幕成人一区 | 黄色成人影视 | 久草com | 69精品视频 | 精品国产一区二区三区av性色 | 日韩一区二区三区免费电影 | 国产亚洲视频中文字幕视频 | 黄色三级视频片 | 9992tv成人免费看片 | 日躁夜躁狠狠躁2001 | 久久理论电影 | 天天玩天天干天天操 | 成人午夜在线观看 | 尤物九九久久国产精品的分类 | 日韩一区二区免费视频 | 日韩午夜高清 | 国产精品国产三级国产aⅴ入口 | 91九色国产 | 欧美成人h版在线观看 | 天天躁天天狠天天透 | 国产精品18久久久久久vr | 999视频网 | av不卡中文字幕 | 久草在线官网 | 日韩大片在线 | 外国av网 | 麻豆果冻剧传媒在线播放 | 免费av观看网站 | 久久精彩视频 | 婷婷久久婷婷 | 日韩欧美在线综合网 | 人人看人人做人人澡 | 成人在线一区二区三区 | 中文字幕在线观看日本 | 日日躁夜夜躁aaaaxxxx | 五月婷综合 | 麻花豆传媒mv在线观看 | 不卡视频在线 | av亚洲产国偷v产偷v自拍小说 | 精品视频成人 | 深夜免费福利视频 | 久久综合九色欧美综合狠狠 | 国产精品久久一区二区三区, | 国产免费又爽又刺激在线观看 | 黄色成人在线观看 | 国产成人一二三 | 成人久久精品视频 | 人人玩人人添人人澡超碰 | 精品在线不卡 | 久草久草在线 | 色小说av| 美女啪啪图片 | 亚洲综合欧美激情 | 日韩特黄一级欧美毛片特黄 | 天天夜夜狠狠操 | 欧美在线aaa | 国内精品视频在线 | 免费黄色网址大全 | 精品久久久久久亚洲综合网站 | 久久久久久美女 | 午夜精品一区二区三区在线观看 | 天天综合色 | 免费观看av | 一二三久久久 | 国产一线二线三线性视频 | 中文字幕一区二区三区四区视频 | 91成品人影院| 草免费视频| 天天草天天干天天射 | 久久国产热 | 色丁香色婷婷 | 五月黄色 | 人人澡人人澡人人 | 91亚色免费视频 | 欧美亚洲国产一卡 | 国产精品入口久久 | 色爱成人网 | 日韩婷婷| 日日干夜夜骑 | 99r在线观看 | 成人性生爱a∨ | 久草视频在线资源站 | 亚洲一级片在线观看 | 91人人爽久久涩噜噜噜 | 亚洲成人精品久久久 | 久久经典国产 | 狠狠操精品 | 免费在线观看国产精品 | 伊人狠狠色丁香婷婷综合 | 国产98色在线 | 日韩 | 激情久久小说 | 青青草视频精品 | 久久涩涩网站 | 夜夜操天天摸 | 超碰在线97观看 | 九热精品 | 亚洲成人xxx | 激情五月看片 | 免费日韩av片 | 黄色av电影一级片 | 日本中文字幕在线 | 91精品视频一区二区三区 | 国产精品成人自拍 | 久久成人欧美 | 999ZYZ玖玖资源站永久 | www.五月天婷婷 | 日韩va亚洲va欧美va久久 | 久久99精品久久久久久三级 | 国产免费二区 | 三级黄色大片在线观看 | 色婷婷综合久久久中文字幕 | 一区二区三区四区在线 | 久久精品之 | 天天干,天天草 | av观看在线观看 | 蜜臀av性久久久久蜜臀aⅴ涩爱 | 色视频在线免费 | 精品国产精品久久 | 99国产精品一区二区 | 香蕉久久久久久av成人 | 日韩在线观看视频中文字幕 | 日韩欧美在线第一页 | 国产日产精品久久久久快鸭 | 国产亚洲精品美女 | 成人午夜电影免费在线观看 | 免费一级特黄录像 | 成人免费毛片aaaaaa片 | 天堂在线一区二区 | av中文天堂在线 | 亚洲干视频在线观看 | 黄色一级在线视频 | 天天干天天玩天天操 | 日日操日日操 | 久久免费播放视频 | 国产中文伊人 | 日韩 在线 | 久久中文字幕在线视频 | 福利网址在线观看 | 九九视频在线播放 | 在线观看蜜桃视频 | 欧美一二三区在线播放 | 亚洲成人精品国产 | 五月天激情综合 | 国产精品女同一区二区三区久久夜 | 久久久久久久久久久久亚洲 | 97av超碰| 国产69久久精品成人看 | 国产中文字幕久久 | 久久久免费国产 | 美女在线黄 | 91黄色影视| 午夜精品久久久久久久久久久久久久 | 亚洲午夜精品一区二区三区电影院 | 欧美激情视频一区二区三区免费 | 天天爱天天射天天干天天 | 国内外成人免费在线视频 | 狠狠操精品 | 91九色蝌蚪视频在线 | 久久精品国亚洲 | 国产成人精品一区在线 | 91九色自拍 | 日产乱码一二三区别在线 | 久久久免费观看 | 美女网站黄在线观看 | 亚洲精品美女视频 | 午夜男人影院 | 日b视频在线观看网址 | 久久激情视频 久久 | 国色天香第二季 | 亚洲国产免费看 | 国产日产在线观看 | 成人中心免费视频 | 制服丝袜在线91 | 四虎成人免费观看 | 97精品在线 | 国产成人精品一区二区三区在线 | 欧洲黄色片 | 中文字幕在线不卡国产视频 | 欧美午夜精品久久久久久浪潮 | 欧美黄在线 | 麻豆精品在线视频 | 91av在线精品 | 国产视频欧美视频 | 久草99| 国产伦精品一区二区三区在线 | 黄色一级在线视频 | 特级黄色一级 | 少妇精69xxtheporn | 97超碰人人澡人人爱 | 久久一区国产 | 又黄又刺激又爽的视频 | 久草网在线观看 | 欧美久久久一区二区三区 | 国产小视频在线免费观看视频 | 欧美午夜a| 亚洲成人一二三 | 99国产精品久久久久久久久久 | 国产精品18久久久久久久 | 国产精品中文字幕av | 成年人国产视频 | 欧美成人精品三级在线观看播放 | 久久99亚洲精品久久 | 国产精品99爱 | 欧美福利视频 | av丁香花 | 香蕉视频18 | 国产成人精品一区二区 | 久久久999免费视频 日韩网站在线 | 久久av福利 | 国内成人综合 | 欧美性大战 | 久久久高清免费视频 | 免费观看丰满少妇做爰 | 亚一亚二国产专区 | 国产色黄网站 | 婷婷丁香综合 | 狠狠干狠狠插 | 成人一区二区三区在线 | 亚洲精品综合一二三区在线观看 | 色综合天天色综合 | 日本字幕网 | 日本中文字幕一二区观 | 黄www在线观看 | 国产高清视频在线 | 91c网站色版视频 | 久久av免费| av在线com | 精品福利在线视频 | 97av视频| 成年人黄色av | 操操操干干干 | 在线观看免费av网 | 国产精品婷婷午夜在线观看 | 91观看视频| 97人人射 | 免费网站污| 中文字幕一区二区三区四区视频 | 国产一区二区三区午夜 | 久色伊人| 香蕉网站在线观看 | www九九热 | 91精品在线视频 | 日本大尺码专区mv | 日日夜夜人人天天 | 成人影片在线播放 | 青青河边草免费观看 | 在线亚洲日本 | 色五月成人 | 一区二区三区高清 | 色橹橹欧美在线观看视频高清 | 婷婷亚洲综合五月天小说 | 国产一级片不卡 | 色婷婷88av视频一二三区 | 五月天激情视频在线观看 | 日韩一区在线免费观看 | av丁香花| 91麻豆精品国产91久久久久久久久 | 国产99久久久精品 | 久久伊人91 | 免费看国产一级片 | 国产黄色一级片在线 | 国产69精品久久久久99尤 | 久久国产福利 | 日韩欧美高清视频在线观看 | 国产免费精彩视频 | 国产视频一区二区三区在线 | 日韩在线国产 | 日韩高清国产精品 | 国产黄色成人av | 手机成人av在线 | 久久婷婷综合激情 | 超碰在线个人 | 亚洲伦理电影在线 | 亚洲成a人片77777kkkk1在线观看 | 亚洲综合成人婷婷小说 | 亚洲精品乱码久久久久久蜜桃不爽 | 日韩专区一区二区 | 91网址在线 | 国产麻豆精品一区 | 天天爱天天干天天爽 | 91九色精品女同系列 | 久久国产精品久久精品国产演员表 | 日日干综合 | 国产精品一区二区三区久久 | 国产精品毛片一区二区三区 | 性色大片在线观看 | 国产91免费在线观看 | 欧美日韩国产一二 | 天天干,天天插 | 成人在线电影观看 | 中文字幕在线观看av | 精品国产网址 | 免费看短 | 久草在线欧美 | 久久久久女教师免费一区 | 亚洲最大激情中文字幕 | 国产免码va在线观看免费 | 在线视频专区 | 超碰97人人爱 | 欧美在线你懂的 | 九九免费在线视频 | 亚洲少妇自拍 | 欧美色888| 99999精品视频 | 三级小视频在线观看 | 综合久久久久久久久 | 色婷丁香| 亚洲免费精品一区二区 | 日韩三级一区 | 丁香国产视频 | 久二影院| 97精品国自产拍在线观看 | 日韩午夜一级片 | 九九九在线观看 | 看国产黄色片 | 欧美性受极品xxxx喷水 | 国产女做a爱免费视频 | 激情小说 五月 | 天天人人综合 | 91av精品 | 久久欧洲视频 | 91在线中字| 最新精品视频在线 | 天天干天天上 | 久久婷婷视频 | 毛片网站在线观看 | 久久综合九色综合欧美狠狠 | 国产美女在线免费观看 | 免费大片黄在线 | 人人爽人人爽人人爽学生一级 | 美女免费网站 | 精品国产观看 | 久草网站 | 日本中文字幕在线一区 | 久久国产精品视频观看 | 国产成人福利片 | 亚洲精品久久久蜜桃直播 | 国产一级大片免费看 | 美女黄频在线观看 | 亚洲视频免费在线看 | 国产视频不卡 | 欧美激情第十页 | 日韩av不卡在线播放 | 91九色视频 | 婷婷亚洲五月 | 九九九九九精品 | 偷拍精偷拍精品欧洲亚洲网站 | 亚洲网站在线看 | 黄色aaa毛片 | 久久久黄色av | 久久久久这里只有精品 | 亚洲精品国偷拍自产在线观看蜜桃 | 天天爱天天操 | 国产欧美精品一区二区三区四区 | 精品专区 | 婷婷综合成人 | www欧美xxxx | 91免费版成人 | 99精品国产一区二区三区麻豆 | 亚洲五月婷 | 色九九影院 | 成人黄色大片在线观看 | 97超碰成人在线 | 国产原创在线 | 国产福利久久 | 日韩一区二区在线免费观看 | 999男人的天堂 | 婷婷综合视频 | 国产精品免费观看视频 | 日韩在线播放av | 中文字幕免费观看视频 | 又黄又刺激的视频 | 97在线免费视频 | 久久免费视频在线 | 欧美日韩中文视频 | 在线观看小视频 | 免费人做人爱www的视 | 亚洲性少妇性猛交wwww乱大交 | 丁香久久久 | 91视频黄色| 国产在线观看免费av | 91精品久久久久久久久 | 黄色国产大片 | 91黄色在线视频 | 成人黄色片免费看 | 精品黄色视| 国产精品久久视频 | 亚洲一区二区三区毛片 | 亚洲 中文 欧美 日韩vr 在线 | 色婷婷99 | 久久一区二区免费视频 | 日日干夜夜干 | 亚洲国产精品va在线 | 国产精品久久久久一区二区国产 | 中文字幕亚洲综合久久五月天色无吗'' | 最近日本韩国中文字幕 | 99爱在线观看 | 91精品看片| 精品国产理论片 | 天天射综合网站 | 在线观看黄色 | 天天爱天天干天天爽 |