本文整理汇总了Python中sklearn.preprocessing.MinMaxScaler.astype方法的典型用法代码示例。如果您正苦于以下问题:Python MinMaxScaler.astype方法的具体用法?Python MinMaxScaler.astype怎么用?Python MinMaxScaler.astype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.preprocessing.MinMaxScaler
的用法示例。
在下文中一共展示了MinMaxScaler.astype方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cuml_like
# 需要导入模块: from sklearn.preprocessing import MinMaxScaler [as 别名]
# 或者: from sklearn.preprocessing.MinMaxScaler import astype [as 别名]
def cuml_like(arr1, arr2):
arr1=MinMaxScaler().fit_transform(arr1.astype(float).reshape(-1,1))
arr2=MinMaxScaler().fit_transform(arr2.astype(float).reshape(-1,1))
if arr1.size!=arr2.size:
raise Exception('must be equal-sized arrays arr1 and arr2')
new = np.zeros_like(arr1)
for n in range(new.size):
new[n] = arr1[:n+1].sum()+arr2[n+1:].sum()
return new
示例2: make_data
# 需要导入模块: from sklearn.preprocessing import MinMaxScaler [as 别名]
# 或者: from sklearn.preprocessing.MinMaxScaler import astype [as 别名]
def make_data(n_samples=1000, n_features=1, n_targets=1, informative_prop=1.0,
noise=0.0, test_prop=0.1, valid_prop=0.3, method='linear'):
if method == 'linear':
params = dict(n_features=n_features,
n_informative=int(n_features*informative_prop),
noise=noise,
n_targets=n_targets,
n_samples=n_samples,
shuffle=False,
bias=0.0)
X, Y = make_regression(**params)
elif method == 'boston':
boston = load_boston()
X = boston.data
Y = boston.target
else:
params = dict(n_samples=n_samples,
n_features=n_features)
X, Y = make_friedman3(n_samples=n_samples, n_features=n_features,
noise=noise)
X = MinMaxScaler(feature_range=(0.0,1.0)).fit_transform(X)
X = X.astype(theano.config.floatX)
Y = MinMaxScaler(feature_range=(0.0,1.0)).fit_transform(Y)
Y = Y.astype(theano.config.floatX)
if len(X.shape) > 1:
n_features = X.shape[1]
else:
X = X.reshape(X.shape[0], -1)
n_features = 1
if len(Y.shape) > 1:
n_targets = Y.shape[1]
else:
Y = Y.reshape(Y.shape[0], -1)
n_targets = 1
X_train, Y_train, X_valid, Y_valid, X_test, Y_test = \
train_valid_test_split(X, Y,
test_prop=valid_prop, valid_prop=valid_prop)
return dict(
X_train=theano.shared(X_train),
Y_train=theano.shared(Y_train),
X_valid=theano.shared(X_valid),
Y_valid=theano.shared(Y_valid),
X_test=theano.shared(X_test),
Y_test=theano.shared(Y_test),
num_examples_train=X_train.shape[0],
num_examples_valid=X_valid.shape[0],
num_examples_test=X_test.shape[0],
input_dim=n_features,
output_dim=n_targets)
示例3: build_dataset
# 需要导入模块: from sklearn.preprocessing import MinMaxScaler [as 别名]
# 或者: from sklearn.preprocessing.MinMaxScaler import astype [as 别名]
def build_dataset(X, y, labels, test_prop=0.2, valid_prop=0.2,
register='both', test=False):
if register in ['IDS', 'ADS']:
sel_ixs = np.in1d(y, np.nonzero(labels[:, 1]==register))
X = X[sel_ixs]
y = y[sel_ixs]
elif register == 'both': # merge IDS and ADS labels per phone
ix2phone = dict(enumerate(labels[:, 0]))
phones = sorted(set(ix2phone.values()))
phone2newix = {p:ix for ix, p in enumerate(phones)}
y = np.array([phone2newix[ix2phone[i]] for i in y])
else:
raise ValueError('invalid option for register: {0}'.format(register))
oldix2newix = {old_ix:new_ix for new_ix, old_ix in enumerate(np.unique(y))}
y = np.array([oldix2newix[i] for i in y])
# X = StandardScaler().fit_transform(X)
X = MinMaxScaler(feature_range=(0,1)).fit_transform(X)
X = X.astype(theano.config.floatX)
y = y.astype('int32')
nclasses = np.unique(y).shape[0]
nfeatures = X.shape[1]
X_train, y_train, X_valid, y_valid, X_test, y_test = \
train_valid_test_split(X, y,
test_prop=test_prop, valid_prop=valid_prop)
if test:
X = X_train[100:200]
y = y_train[100:200]
X_train = X_train[:100]
y_train = y_train[:100]
X_valid = X_valid[:10]
y_valid = y_valid[:10]
X_test = X_test[:50]
y_test = y_test[:50]
return dict(
X_train=theano.shared(X_train),
y_train=theano.shared(y_train),
X_valid=theano.shared(X_valid),
y_valid=theano.shared(y_valid),
X_test=theano.shared(X_test),
y_test=theano.shared(y_test),
num_examples_train=X_train.shape[0],
num_examples_valid=X_valid.shape[0],
num_examples_test=X_test.shape[0],
input_dim=nfeatures,
output_dim=nclasses,
labels=labels
)
示例4: MinMaxScaler
# 需要导入模块: from sklearn.preprocessing import MinMaxScaler [as 别名]
# 或者: from sklearn.preprocessing.MinMaxScaler import astype [as 别名]
import numpy as np
from sklearn.preprocessing import MinMaxScaler, StandardScaler
from sklearn.cross_validation import train_test_split
import theanets
import climate
climate.enable_default_logging()
X_orig = np.load('/Users/bzamecnik/Documents/music-processing/music-processing-experiments/c-scale-piano_spectrogram_2048_hamming.npy')
sample_count, feature_count = X_orig.shape
X = MinMaxScaler().fit_transform(X_orig)
X = X.astype(np.float32)
X_train, X_test = train_test_split(X, test_size=0.4, random_state=42)
X_val, X_test = train_test_split(X_test, test_size=0.5, random_state=42)
# (np.maximum(0, 44100/512*np.arange(13)-2)).astype('int')
#blocks = [0, 84, 170, 256, 342, 428, 514, 600, 687, 773, 859, 945, 1031, 1205]
blocks = [0, 48, 98, 148, 198, 248, 298, 348, 398, 448, 498, 548, 598, 700]
def make_labels(blocks):
label_count = len(blocks) - 1
labels = np.zeros(blocks[-1])
for i in range(label_count):
labels[blocks[i]:blocks[i+1]] = i
return labels
y = make_labels(blocks)
def score(exp, Xs):
X_train, X_val, X_test = Xs