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

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

ValueError:無(wú)法將字符串轉(zhuǎn)換為浮點(diǎn)數(shù):'thal'

ValueError:無(wú)法將字符串轉(zhuǎn)換為浮點(diǎn)數(shù):'thal'

侃侃爾雅 2021-11-23 20:16:39
所以我瀏覽了一個(gè)用戶在這里提供的心臟病分類教程。在學(xué)習(xí)本教程時(shí),我遇到了一個(gè)問(wèn)題并且找不到解決方案。我收到一條錯(cuò)誤消息: "ValueError: could not convert string to float: 'thal'" 。這是數(shù)據(jù)集這是程序:import tensorflow as tfimport pandas as pdimport numpy as npimport matplotlib.pyplot as plthd = pd.read_csv("heart.csv", sep=",", header=None)hd.iloc[:,1].describe()IVs = hd.iloc[:,2:13]DV = hd.iloc[:,1]DV = pd.get_dummies(DV)  # One-Hot Encoding - required by classification algorithms# In order to feed the data into a Neural Network, I must turn the data into numpy objectsIVs = IVs.valuesDV = DV.valuesfrom sklearn.model_selection import train_test_splitX_train, X_test, y_train, y_test = train_test_split(IVs, DV, test_size=0.25, random_state=173)print(X_train.shape, y_train.shape)print(X_test.shape, y_test.shape)# Scale the variables using Z-scoresfrom sklearn.preprocessing import StandardScalerscaler = StandardScaler()  X_train = scaler.fit_transform(X_train) X_test = scaler.transform(X_test) 
查看完整描述

2 回答

?
肥皂起泡泡

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

hd = pd.read_csv("heart.csv", sep=",", header=None)

您指定header=None,它會(huì)忽略列的標(biāo)簽,從而創(chuàng)建一個(gè)混合文本和數(shù)字的數(shù)組。刪除此參數(shù)應(yīng)該可以解決您的問(wèn)題,即

hd = pd.read_csv("heart.csv", sep=",")

或者,您可以使用以下命令顯式指定 csv 文件中標(biāo)題的行索引 header=0


查看完整回答
反對(duì) 回復(fù) 2021-11-23
?
素胚勾勒不出你

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

正如底部的消息所說(shuō):ValueError: could not convert string to float: 'thal'這似乎是一個(gè)數(shù)據(jù)類型錯(cuò)誤。StandardScaler 需要數(shù)字(浮點(diǎn))數(shù)據(jù),但它在某處得到一個(gè)字符串并返回錯(cuò)誤。

您可以執(zhí)行多種操作。如果您有分類變量,請(qǐng)對(duì)它們進(jìn)行 One-Hot 編碼。也許您可以強(qiáng)制一列屬于某種數(shù)據(jù)類型。

PS:加載熊貓數(shù)據(jù)框后,您可以使用hd.dtypes. 檢查 IV 中是否有一些非數(shù)字列。


查看完整回答
反對(duì) 回復(fù) 2021-11-23
  • 2 回答
  • 0 關(guān)注
  • 515 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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