1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
def maxmin(list): max_,min_=np.max(list),np.min(list) newlist=[] for x in list: newlist.append((x - min_) / (max_ - min_)) print(newlist)
def z_score(list): mu=sum(list)/len(list) count=0 for i in list: count = count + (i - mu) ** 2 sigma = np.sqrt(count / len(list)) newlist=[] for i in list: newlist.append((i - mu) / sigma) print(newlist)
import numpy as np list=[1,2,3,4,5] maxmin(list) z_score(list)
import numpy as np from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split
def muti_linear_regre(X,Y): X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=2,random_state=1) reg=LinearRegression() reg.fit(X_train, Y_train) print(reg.predict(X_test))
X=np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10,11,12], [13,14,15,16], [17,18,19,20], [21,22,23,24]]) y=np.array([sum(x) for x in X]) if __name__=="__main__": muti_linear_regre(X,y)
|
评论区
欢迎你留下宝贵的意见,昵称输入QQ号会显示QQ头像哦~