当前位置: 首页>>代码示例>>Python>>正文


Python StandardScaler.as_matrix方法代码示例

本文整理汇总了Python中sklearn.preprocessing.StandardScaler.as_matrix方法的典型用法代码示例。如果您正苦于以下问题:Python StandardScaler.as_matrix方法的具体用法?Python StandardScaler.as_matrix怎么用?Python StandardScaler.as_matrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.preprocessing.StandardScaler的用法示例。


在下文中一共展示了StandardScaler.as_matrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: standardize

# 需要导入模块: from sklearn.preprocessing import StandardScaler [as 别名]
# 或者: from sklearn.preprocessing.StandardScaler import as_matrix [as 别名]
def standardize(df):
    X = df.drop(['id', 'group'], axis=1)
    X.ix[X.gender == 'f', 'gender'] = 1.0
    X.ix[X.gender == 'm', 'gender'] = -1.0
    X['gender'] = pd.to_numeric(X.gender)
    X = StandardScaler().fit_transform(X.as_matrix())
    return X
开发者ID:tomhettinger,项目名称:clustering,代码行数:9,代码来源:clustering.py

示例2: LabelEncoder

# 需要导入模块: from sklearn.preprocessing import StandardScaler [as 别名]
# 或者: from sklearn.preprocessing.StandardScaler import as_matrix [as 别名]
# Encode the nta column
le = LabelEncoder()
nta_encoded = le.fit_transform(data.nta)
data['nta_encoded'] = nta_encoded

# Drop the columns we won't use for our model
data.drop(['nta','date_hour','nta_dt','nbhd_name','Unnamed: 0'],axis=1,inplace=True)

# Scale our data (not every column needs to be scaled)
to_scale = data[(data.columns-['month','day','hour','nta_encoded'])]
X = StandardScaler().fit_transform(to_scale)
X = pd.DataFrame(X)
for col in ['month','day','hour','nta_encoded']:
    X[col] = data[col]
X = X.as_matrix()

# We want to determine the number of bins we are going to classify into by using
# k-means clustering different values of n clusters. We are going to choose the
# n with the best silhouette score
cluster_scores = []
for n in range(3,6):
    # Initialize and fit a KMeans object
    k_means = cluster.KMeans(n_clusters=n,n_jobs=-1,verbose=1)
    k_means.fit(X)
    # Get the cluster labels for each point
    labels = k_means.labels_
    # Initialize a list to store this n's silhouette scores
    scores = []
    # We need to limit the sample_size when calculating silhouette scores due to
    # computation time
开发者ID:JesseBickford,项目名称:Predicting_Uber_Demand,代码行数:32,代码来源:unsupervised_clustering.py


注:本文中的sklearn.preprocessing.StandardScaler.as_matrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。