日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

小象机器学习(邹博老师)学习笔记

發(fā)布時間:2023/12/10 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 小象机器学习(邹博老师)学习笔记 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、線性回歸

1. 基本線性回歸

from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1) # print x_train, y_train linreg = LinearRegression() model = linreg.fit(x_train, y_train) # model # linreg.coef_ # linreg.intercept_ y_hat = linreg.predict(np.array(x_test)) mse = np.average((y_hat - np.array(y_test)) ** 2) # Mean Squared Error rmse = np.sqrt(mse) # Root Mean Squared Error t = np.arange(len(x_test)) plt.plot(t, y_test, 'r-', linewidth=2, label='Test') plt.plot(t, y_hat, 'g-', linewidth=2, label='Predict')

?2. CV

from sklearn.model_selection import train_test_split from sklearn.linear_model import Lasso, Ridge from sklearn.model_selection import GridSearchCV x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1) # print x_train, y_train model = Lasso() # model = Ridge() alpha_can = np.logspace(-3, 2, 10) lasso_model = GridSearchCV(model, param_grid={'alpha': alpha_can}, cv=5) lasso_model.fit(x, y) # lasso_model.best_params_ # pd.DataFrame(lasso_model.cv_results_)

?3. pipline和meshgrid畫圖(鳶尾花數(shù)據(jù))

lr = Pipeline([('sc', StandardScaler()),('clf', LogisticRegression()) ]) lr.fit(x, y.ravel())N, M = 500, 500 # 橫縱各采樣多少個值 x1_min, x1_max = x[:, 0].min(), x[:, 0].max() # 第0列的范圍 x2_min, x2_max = x[:, 1].min(), x[:, 1].max() # 第1列的范圍 t1 = np.linspace(x1_min, x1_max, N) t2 = np.linspace(x2_min, x2_max, M) x1, x2 = np.meshgrid(t1, t2) # 生成網(wǎng)格采樣點 x_test = np.stack((x1.flat, x2.flat), axis=1) # 測試點 cm_light = mpl.colors.ListedColormap(['#77E0A0', '#FF8080', '#A0A0FF']) cm_dark = mpl.colors.ListedColormap(['g', 'r', 'b']) y_hat = lr.predict(x_test) # 預測值 y_hat = y_hat.reshape(x1.shape) # 使之與輸入的形狀相同 plt.pcolormesh(x1, x2, y_hat, cmap=cm_light) # 預測值的顯示 plt.scatter(x[:, 0], x[:, 1], c=y, edgecolors='k', s=50, cmap=cm_dark) # 樣本的顯示 plt.xlabel('petal length') plt.ylabel('petal width') plt.xlim(x1_min, x1_max) plt.ylim(x2_min, x2_max) plt.grid()

?

轉載于:https://www.cnblogs.com/figo-studypath/p/10384652.html

總結

以上是生活随笔為你收集整理的小象机器学习(邹博老师)学习笔记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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