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

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

在sklearn中使用DataFrameMapper()進(jìn)行PolynomialFeature

在sklearn中使用DataFrameMapper()進(jìn)行PolynomialFeature

慕尼黑5688855 2023-08-22 17:16:34
對于住房數(shù)據(jù)集,我嘗試使用 sklearn_pandas 中的 DataFrameMapper() 在選定的列上應(yīng)用多項(xiàng)式特征。我的代碼:from sklearn.preprocessing import PolynomialFeatures from sklearn_pandas import DataFrameMapper mapper = DataFrameMapper([('houseAge_income', PolynomialFeatures(2)),('median_income', PolynomialFeatures(2)),(['latitude', 'housing_median_age', 'total_rooms', 'population', 'median_house_value', 'ocean_proximity']], None) ]) poly_feature = mapper.fit_transform(housing) 當(dāng)我嘗試使用houseAge_income.reshape(-1, 1)在 DataFrameMapper() 中,我遇到了另一個(gè)問題:---------------------------------------------------------------------------KeyError                                  Traceback (most recent call last)/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)   2645             try:-> 2646                 return self._engine.get_loc(key)   2647             except KeyError:pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()KeyError: 'houseAge_income.reshape(-1, 1)'During handling of the above exception, another exception occurred:KeyError                                  Traceback (most recent call last)5 frames/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)   2646                 return self._engine.get_loc(key)   2647             except KeyError:-> 2648                 return self._engine.get_loc(self._maybe_cast_indexer(key))   2649         indexer = self.get_indexer([key], method=method, tolerance=tolerance)   2650         if indexer.ndim > 1 or indexer.size > 1:pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()誰能告訴我,我錯(cuò)過了什么?
查看完整描述

1 回答

?
白板的微信

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

  • 從文檔中

    • 'column'將列選擇器指定為(作為簡單字符串)和['column'](作為包含一個(gè)元素的列表)之間的區(qū)別在于傳遞給轉(zhuǎn)換器的數(shù)組的形狀。在第一種情況下,將傳遞一個(gè)一維數(shù)組,而在第二種情況下,將傳遞一個(gè)具有一列的二維數(shù)組,即列向量。

  • 所有列必須使用相同類型的列選擇器傳遞。

    • 在本例中,為 a?list,因?yàn)樾枰?code>list保留一些未轉(zhuǎn)換的列。

import pandas as pd

from sklearn.preprocessing import PolynomialFeatures

from sklearn_pandas import DataFrameMapper


# load data

df = pd.read_csv('https://raw.githubusercontent.com/ageron/handson-ml2/master/datasets/housing/housing.csv')


# create houseAge_income

df['houseAge_income'] = df.housing_median_age.mul(df.median_income)


# configure mapper with all columns passed as lists

mapper = DataFrameMapper([(['houseAge_income'], PolynomialFeatures(2)),

? ? ? ? ? ? ? ? ? ? ? ? ? (['median_income'], PolynomialFeatures(2)),

? ? ? ? ? ? ? ? ? ? ? ? ? (['latitude', 'housing_median_age', 'total_rooms', 'population', 'median_house_value', 'ocean_proximity'], None)])


# fit

poly_feature = mapper.fit_transform(df)


# display(pd.DataFrame(poly_feature).head())

? 0? ? ? ?1? ? ? ? ? ?2? 3? ? ? ?4? ? ? ?5? ? ? 6? ?7? ? ?8? ? ?9? ? ? ? ? 10? ? ? ? 11

0? 1? 341.33? 1.1651e+05? 1? 8.3252? 69.309? 37.88? 41? ?880? ?322? 4.526e+05? NEAR BAY

1? 1? 174.33? ? ? ?30391? 1? 8.3014? 68.913? 37.86? 21? 7099? 2401? 3.585e+05? NEAR BAY

2? 1? 377.38? 1.4242e+05? 1? 7.2574? ?52.67? 37.85? 52? 1467? ?496? 3.521e+05? NEAR BAY

3? 1? 293.44? ? ? ?86108? 1? 5.6431? 31.845? 37.85? 52? 1274? ?558? 3.413e+05? NEAR BAY

4? 1? ? ?200? ? ? ?40001? 1? 3.8462? 14.793? 37.85? 52? 1627? ?565? 3.422e+05? NEAR BAY




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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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