第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

plt.plot 繪制多條曲線而不是單條曲線

plt.plot 繪制多條曲線而不是單條曲線

慕田峪7331174 2023-09-02 16:17:09
這是我使用的數(shù)據(jù)集的鏈接:數(shù)據(jù)集import numpy as npimport matplotlib.pyplot as pltimport pandas as pd#Lets begin with polynomial regressiondf = pd.read_excel('enes.xlsx', index='hacim')X=pd.DataFrame(df['hacim'])Y=pd.DataFrame(df['delay'])from sklearn.linear_model import LinearRegressionfrom sklearn.preprocessing import PolynomialFeaturespoly_reg = PolynomialFeatures(degree = 4)X_poly = poly_reg.fit_transform(X)lin_reg_2 = LinearRegression()lin_reg_2.fit(X_poly, Y)plt.scatter(X, Y, color = 'red')plt.plot(X, lin_reg_2.predict(poly_reg.fit_transform(X)), color = 'blue')plt.title('X Vs Y')plt.xlabel('hacim')plt.ylabel('delay')plt.show()最后 plt.show 顯示了一個圖表,其中有很多行,而不是我想要的單行多項式回歸。出了什么問題,我該如何解決這個問題?數(shù)據(jù),hacim,delay0,815,1.441,750,1.112,321,2.373,1021,1.444,255,1.095,564,1.616,1455,15.277,525,2.78,1118,106.989,1036,3.4710,396,1.3411,1485,21.4912,1017,12.2213,1345,2.7214,312,1.7115,742,33.7916,1100,39.6217,1445,4.8818,847,1.5519,991,1.8220,1296,10.7721,854,1.8122,1198,61.923,1162,8.2224,1463,42.2525,1272,4.3126,745,2.3627,521,2.1428,1247,94.3329,732,12.5530,489,1.0531,1494,12.7832,591,3.1833,257,1.1834,602,4.2435,335,2.0636,523,3.6337,752,7.6138,349,1.7639,771,0.7940,855,39.0841,948,3.9542,1378,97.2843,598,2.6944,558,1.6745,634,34.6946,1146,12.2247,1087,1.7448,628,1.0349,711,3.3450,1116,7.2751,748,1.0952,1212,14.1653,434,1.4254,1046,8.2555,568,1.3356,894,2.6157,1041,4.7958,801,1.8459,1387,11.560,1171,161.2161,734,2.4362,1471,17.4263,461,1.4264,751,2.3665,898,2.466,593,1.7467,942,3.3968,825,1.0969,715,20.2370,725,5.4371,1128,7.5772,1348,4.4973,1393,9.7774,1379,97.7675,859,2.5976,612,15.9877,1495,8.2278,887,1.8579,867,38.6580,1353,1.681,851,60.2582,1079,24.0583,1100,25.5884,638,1.2385,1115,1.9486,1443,4.7987,1421,10.3388,1279,7.2989,1176,173.4490,315,1.5391,1019,34.0392,1337,48.6793,576,28.8394,919,2.8895,361,1.596,989,1.4797,1286,32.11
查看完整描述

1 回答

?
Qyouu

TA貢獻1786條經(jīng)驗 獲得超11個贊

讓我們使用 pandas 繪圖,它更容易:


X=pd.DataFrame(df['hacim'])

Y=pd.DataFrame(df['delay'])


from sklearn.linear_model import LinearRegression

from sklearn.preprocessing import PolynomialFeatures

poly_reg = PolynomialFeatures(degree = 4)

X_poly = poly_reg.fit_transform(X)

lin_reg_2 = LinearRegression()

lin_reg_2.fit(X_poly, Y)


df['y_pred'] = lin_reg_2.predict(poly_reg.fit_transform(X))

df = df.sort_values('hacim')

ax = df.plot.scatter('hacim','delay')

df.plot('hacim', 'y_pred', ax=ax, color='r')

plt.title('X Vs Y')

plt.xlabel('hacim')

plt.ylabel('delay')

plt.show()

輸出:

https://img1.sycdn.imooc.com//64f2efc30001577103860273.jpg

繪制折線圖時,散點線的根是未排序的數(shù)據(jù)。

你可以這樣做:

plt.plot(X, lin_reg_2.predict(poly_reg.fit_transform(X)), color = 'blue', marker='o', linestyle='none')

輸出:

https://img1.sycdn.imooc.com//64f2efd100010a7503840275.jpg

查看完整回答
反對 回復(fù) 2023-09-02
  • 1 回答
  • 0 關(guān)注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號