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

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

在python中輸入二進(jìn)制值

在python中輸入二進(jìn)制值

吃雞游戲 2022-07-12 10:28:03
我有一個(gè)缺少值的數(shù)據(jù)框,其中可能的選項(xiàng)是 True 或 False,因?yàn)樵?NaN 情況下,pandas 將該列作為浮點(diǎn)數(shù),并且在輸入該列并獲取值之后:0、0.5 和 1如何添加約束以僅獲得 0 和 1?目前我正在使用 missingpy 庫(kù)from missingpy import MissForest
查看完整描述

2 回答

?
三國(guó)紛爭(zhēng)

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

你介意用一些你使用的數(shù)據(jù)的例子和給你問(wèn)題的代碼來(lái)更新你的問(wèn)題 - 它會(huì)讓你得到更好的答案!


從您的說(shuō)法看來(lái),適合的模型正在考慮您的目標(biāo)變量是連續(xù)的而不是分類的(布爾值本質(zhì)上是分類的 0 或 1)。MissForest 上的 API 文檔說(shuō):


第一步涉及用初始猜測(cè)填充剩余的非候選列的任何缺失值,這是表示數(shù)值變量的列的列平均值和表示分類變量的列的列模式。請(qǐng)注意,分類變量需要在 imputer 的 fit() 方法調(diào)用期間明確標(biāo)識(shí)(有關(guān)更多信息,請(qǐng)參閱 API)。


這意味著您應(yīng)該cat_vars在擬合階段指定:


fit(self, X, y=None, cat_vars=None):在 X 上擬合 imputer。


Parameters

----------

X : {array-like}, shape (n_samples, n_features)

    Input data, where ``n_samples`` is the number of samples and

    ``n_features`` is the number of features.


cat_vars : int or array of ints, optional (default = None)

    An int or an array containing column indices of categorical

    variable(s)/feature(s) present in the dataset X.

    ``None`` if there are no categorical variables in the dataset.


Returns

-------

self : object

    Returns self.

參考這里。


這意味著將使用類別而不是連續(xù)值進(jìn)行估算。


查看完整回答
反對(duì) 回復(fù) 2022-07-12
?
慕妹3242003

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

您有幾種處理策略nan,讓我們考慮一下這個(gè)玩具df:


import pandas as pd

import numpy as np



df = pd.DataFrame(

    {

        'column': [np.nan, True, np.nan]

    }

)

print(df['column'])


>>> 

0     NaN

1    True

2     NaN

Name: column, dtype: object

bool如果您負(fù)擔(dān)得起使用損壞的數(shù)據(jù)(不建議),您可以簡(jiǎn)單地將列強(qiáng)制為一種類型:


print(df['column'].astype(bool))


>>> 

0    True

1    True

2    True

Name: column, dtype: bool

您可以刪除包含nan(最佳方法)的行:


print(df['column'].dropna())


>>>

1    True

Name: column, dtype: object

或者您可以將它們替換nan為默認(rèn)值:


print(df['column'].fillna(False))


>>>

0    False

1     True

2    False

Name: column, dtype: bool


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

添加回答

舉報(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)