Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python plt.show()无法使用此代码_Python_Matplotlib_Scikit Learn - Fatal编程技术网

Python plt.show()无法使用此代码

Python plt.show()无法使用此代码,python,matplotlib,scikit-learn,Python,Matplotlib,Scikit Learn,数据 我也是ML和python的新手,所以请有人解释一下从def randomize(X,Y)到代码末尾的每个细节是如何工作的 TIA这是一个大问题,不幸的是,不,在一个答案中,让狗看完这段代码的每一行是不可行的。我建议你去看看涵盖你在这里展示的所有内容的优秀课程 简单的即时解决方案是在定义函数后调用它。在当前代码块的末尾,只需添加: 绘制学习曲线(X2,y2,估计器,5) 这将执行您使用X2、y2和estimator变量作为参数定义的函数。将最后一个参数更改为您希望可视化的培训次数。因此,这

数据 我也是ML和python的新手,所以请有人解释一下从def randomize(X,Y)到代码末尾的每个细节是如何工作的
TIA这是一个大问题,不幸的是,不,在一个答案中,让狗看完这段代码的每一行是不可行的。我建议你去看看涵盖你在这里展示的所有内容的优秀课程

简单的即时解决方案是在定义函数后调用它。在当前代码块的末尾,只需添加:

绘制学习曲线(X2,y2,估计器,5)

这将执行您使用
X2
y2
estimator
变量作为参数定义的函数。将最后一个参数更改为您希望可视化的培训次数。

因此,这里不是人们做作业的地方。您没有在显示的代码中使用参数调用draw\u learning\u curves。
import pandas as pd
import numpy as np
from sklearn import model_selection
from sklearn.model_selection import KFold
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
import matplotlib.pyplot as plt
from sklearn.model_selection import learning_curve
 
data = pd.read_csv("training5.csv")
X= np.array(data[['x1','x2']])
y=np.array(data['y'])
np.random.seed(55)
 
estimator = LogisticRegression()
 
 
 
def randomize(X, Y):
    permutation = np.random.permutation(Y.shape[0])
    X2 = X[permutation,:]
    Y2 = Y[permutation]
    return X2, Y2
 
X2, y2 = randomize(X, y)
 
def draw_learning_curves(X, y, estimator, num_trainings):
    train_sizes, train_scores, test_scores = learning_curve(
        estimator, X2, y2, cv=None, n_jobs=1, train_sizes=np.linspace(.1, 1.0, num_trainings))
 
    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.title("Learning Curves")
    plt.xlabel("Training examples")
    plt.ylabel("Score")
 
    plt.plot(train_scores_mean, 'o-', color="g",
             label="Training score")
    plt.plot(test_scores_mean, 'o-', color="y",
             label="Cross-validation score")
 
 
    plt.legend(loc="best")
 
    plt.show()