Python基础

2018-02-04  本文已影响0人  llsh2010
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,"========================")
上一篇下一篇

猜你喜欢

热点阅读