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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

修復(fù)了 one-hot 編碼中的冗余,但在嘗試反轉(zhuǎn)時(shí)仍然出現(xiàn)錯(cuò)誤

修復(fù)了 one-hot 編碼中的冗余,但在嘗試反轉(zhuǎn)時(shí)仍然出現(xiàn)錯(cuò)誤

慕勒3428872 2023-09-19 14:54:35
我正在進(jìn)行 one-hot 編碼并使用 ??? =((??????)^?1) * ?????? 來(lái)估計(jì) theta。由于冗余,我收到了錯(cuò)誤,因此我決定刪除有冗余的列。這是在刪除列之前:這是我的代碼,因?yàn)槲覈L試刪除具有冗余的列: def one_hot_encode_revised(data):                all_columns = data.columns            records = data[all_columns].to_dict(orient='records')        encoder = DictVectorizer(sparse=False)        encoded_X = encoder.fit_transform(records)        df = pd.DataFrame(data=encoded_X, columns=encoder.feature_names_)                return df.drop(['day=Fri', 'sex=Male', 'smoker=No', 'time=Dinner'], axis =1)one_hot_X_revised = one_hot_encode_revised(X)輸出如下:然后,我使用這個(gè)函數(shù)根據(jù)上面的方程估計(jì) theta:def get_analytical_sol(X, y):"""Computes the analytical solution to our least squares problemParameters-----------X: a 2D dataframe of numeric features (one-hot encoded)y: a 1D vector of tip amountsReturns-----------The estimate for theta"""return np.linalg.inv(X.T * X) * (X.T * y)運(yùn)行這個(gè):revised_analytical_thetas = get_analytical_sol(one_hot_X_revised, tips)我的錯(cuò)誤是: ValueError: 無(wú)法強(qiáng)制轉(zhuǎn)換為 DataFrame,形狀必須是 (8, 244): 給定 (252, 252)作為參考,提示是這樣的:我是否正確地消除了冗余,如果是,為什么仍然有錯(cuò)誤?
查看完整描述

1 回答

?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊

您在這一行中有一個(gè)錯(cuò)誤return np.linalg.inv(X.T * X) * (X.T * y)。你想要做的是矩陣乘法。在 pandas 數(shù)據(jù)框中,符號(hào)*不用于矩陣乘法。您需要使用@dot()數(shù)據(jù)框的方法。



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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號(hào)

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