iT邦幫忙

0

python深度學習

  • 分享至 

  • xImage

import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression

list=[[0,np.nan,1,0,1,0,0],[0,1,0,0,1,1,np.nan],[np.nan,0,1,1,0,1,0],[0,0,1,np.nan,0,1,0]]
SA=pd.DataFrame(list)#SA=StudentAns
gotP= np.array([2,2,2,4])
average= np.nanmedian(SA)
newSA=np.where(SA.isnull(), average, SA)
lm = LinearRegression()
lm.fit(newSA,gotP)
to_be_predicted = np.array([7])
predicted = lm.predict(to_be_predicted)
print(predicted)

這是我的代碼,我想把統計學教授出過的題目以代碼呈現
題目是:當知道list中4位學生們的作答,且知道他們的分數
去回推正確答案(總分7分)

錯誤訊息:
ValueError: Expected 2D array, got 1D array instead:
array=[7].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
而我去查好像是sklearn的版本問題,一般reshape後就好,但是我的reshape後出現

錯誤訊息:
ValueError: shapes (1,1) and (7,) not aligned: 1 (dim 1) != 7 (dim 0)

請好心人解惑

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答