美文网首页
Python基础

Python基础

作者: llsh2010 | 来源:发表于2018-02-04 16:40 被阅读0次
    from sklearn import datasets
    from sklearn.model_selection import cross_val_predict
    from sklearn import linear_model
    import matplotlib.pyplot as plt
    
    i= 1
    
    print("\n", i,"========================")
     
    j = 1 
    print("    ",i,"_", j,"list-------------------")
    #https://www.cnblogs.com/zibu1234/p/4210571.html
    import numpy as num
    array = num.arange(-100,100,0.1)
    print(array)
    
    
    
    
    
    
    
    j= j +1 
    print("    ",i,"_", j,"-------------------")
    j= j +1 
    print("    ",i,"_", j,"-------------------")
    j= j +1 
    print("    ",i,"_", j,"-------------------")
    j= j +1 
    print("    ",i,"_", j,"-------------------")
    j= j +1 
    print("    ",i,"_", j,"-------------------")
    j= j +1 
    print("    ",i,"_", j,"-------------------")
    j= j +1 
    print("    ",i,"_", j,"-------------------")
    j= j +1 
    
    
    
    i= i +1
    print("\n", i,"循环========================")
    
    print("changdu:",len(array))
    for i in array:
        print(i)
    
    
    
    
    i= i +1 
    print("\n", i,"plot========================")
    
    
    
    
    
    lr = linear_model.LinearRegression()
    boston = datasets.load_boston()
    y = boston.target
    
    print(boston.data[0])
    
    print(len(boston.data[0]))
    print(len(boston.data))
    
    newdata = [
            [1,2,3],
            [1,2,3]
            ]
    
    
    print(newdata[0])
    print(len(newdata))
    
    
    
    # cross_val_predict returns an array of the same size as `y` where each entry
    # is a prediction obtained by cross validation:
    predicted = cross_val_predict(lr, boston.data, y, cv=10)
    #predicted = cross_val_predict(lr, newdata, y, cv=10)
    
    print(predicted)
    
    
    fig, ax = plt.subplots()
    ax.scatter(y, predicted, edgecolors=(0, 0, 0))
    
    ax.plot([y.min(), y.max()], [y.min(), y.max()], 'k--', lw=4)
    
    ax.set_xlabel('Measured')
    ax.set_ylabel('Predicted')
    plt.show()
    
    
    
    i= i +1 
    print("\n", i,"========================")
    
    
    
    
    
    i= i +1 
    print("\n", i,"========================")
    
    
    
    
    i= i +1 
    print("\n", i,"========================")
    

    相关文章

      网友评论

          本文标题:Python基础

          本文链接:https://www.haomeiwen.com/subject/phwmzxtx.html