本文整理汇总了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
示例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