本文整理匯總了Python中sklearn.preprocessing.StandardScaler.get_feature_names方法的典型用法代碼示例。如果您正苦於以下問題:Python StandardScaler.get_feature_names方法的具體用法?Python StandardScaler.get_feature_names怎麽用?Python StandardScaler.get_feature_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.preprocessing.StandardScaler
的用法示例。
在下文中一共展示了StandardScaler.get_feature_names方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: scale_dataframe
# 需要導入模塊: from sklearn.preprocessing import StandardScaler [as 別名]
# 或者: from sklearn.preprocessing.StandardScaler import get_feature_names [as 別名]
def scale_dataframe(train, test, cols, replace=True):
""" Takes train and test dataframes and a list of columns that need to be scaled.
Returns a 3-tuple comprising the scaled dataframes and the fitted scaler.
"""
scaler = StandardScaler()
scaledTrain = pd.DataFrame(data=scaler.fit_transform(train[cols]), columns=cols)
scaledTest = pd.DataFrame(data=scaler.transform(test[cols]), columns=cols)
scaledTrain.columns = scaler.get_feature_names()
scaledTest.columns = scaler.get_feature_names()
scaledTrain.index = train.index
scaledTest.index = test.index
if replace is True:
train = train.drop(cols, axis=1)
train = train.join(scaledTrain)
test = test.drop(cols, axis=1)
test = test.join(scaledTest)
return (train, test, scaler)