本文整理汇总了Python中sklearn.datasets.load_linnerud函数的典型用法代码示例。如果您正苦于以下问题:Python load_linnerud函数的具体用法?Python load_linnerud怎么用?Python load_linnerud使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_linnerud函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_load_linnerud
def test_load_linnerud():
res = load_linnerud()
assert_equal(res.data.shape, (20, 3))
assert_equal(res.target.shape, (20, 3))
assert_equal(len(res.target_names), 3)
assert_true(res.DESCR)
# test return_X_y option
X_y_tuple = load_linnerud(return_X_y=True)
bunch = load_linnerud()
assert_true(isinstance(X_y_tuple, tuple))
assert_array_equal(X_y_tuple[0], bunch.data)
assert_array_equal(X_y_tuple[1], bunch.target)
开发者ID:NazBen,项目名称:scikit-learn,代码行数:13,代码来源:test_base.py
示例2: test_convergence_fail
def test_convergence_fail():
d = load_linnerud()
X = d.data
Y = d.target
pls_bynipals = pls_.PLSCanonical(n_components=X.shape[1],
max_iter=2, tol=1e-10)
assert_warns(ConvergenceWarning, pls_bynipals.fit, X, Y)
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:7,代码来源:test_pls.py
示例3: test_pls_errors
def test_pls_errors():
d = load_linnerud()
X = d.data
Y = d.target
for clf in [pls_.PLSCanonical(), pls_.PLSRegression(), pls_.PLSSVD()]:
clf.n_components = 4
assert_raise_message(ValueError, "Invalid number of components", clf.fit, X, Y)
开发者ID:antoinewdg,项目名称:scikit-learn,代码行数:7,代码来源:test_pls.py
示例4: test_eigsym
def test_eigsym():
d = load_linnerud()
X = d.data
n = 3
X = dot(X.T, X)
eig = EIGSym(num_comp = n, tolerance = 5e-12)
eig.fit(X)
Xhat = dot(eig.V, dot(eig.D, eig.V.T))
assert_array_almost_equal(X, Xhat, decimal=4, err_msg="EIGSym does not" \
" give the correct reconstruction of the matrix")
[D,V] = np.linalg.eig(X)
# linalg.eig does not return the eigenvalues in order, so need to sort
idx = np.argsort(D, axis=None).tolist()[::-1]
D = D[idx]
V = V[:,idx]
Xhat = dot(V, dot(np.diag(D), V.T))
V, eig.V = direct(V, eig.V, compare = True)
assert_array_almost_equal(V, eig.V, decimal=5, err_msg="EIGSym does not" \
" give the correct eigenvectors")
开发者ID:tomlof,项目名称:sandlada,代码行数:26,代码来源:test_multiblock.py
示例5: test_scale
def test_scale():
d = load_linnerud()
X = d.data
Y = d.target
# causes X[:, -1].std() to be zero
X[:, -1] = 1.0
开发者ID:tomlof,项目名称:sandlada,代码行数:8,代码来源:test_multiblock.py
示例6: test_scale
def test_scale():
d = load_linnerud()
X = d.data
Y = d.target
# causes X[:, -1].std() to be zero
X[:, -1] = 1.0
for clf in [pls.PLSCanonical(), pls.PLSRegression(), pls.CCA(), pls.PLSSVD()]:
clf.set_params(scale=True)
clf.fit(X, Y)
开发者ID:calero2014,项目名称:scikit-learn,代码行数:11,代码来源:test_pls.py
示例7: test_PLSSVD
def test_PLSSVD():
# Let's check the PLSSVD doesn't return all possible component but just
# the specified number
d = load_linnerud()
X = d.data
Y = d.target
n_components = 2
for clf in [pls_.PLSSVD, pls_.PLSRegression, pls_.PLSCanonical]:
pls = clf(n_components=n_components)
pls.fit(X, Y)
assert_equal(n_components, pls.y_scores_.shape[1])
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:11,代码来源:test_pls.py
示例8: test_univariate_pls_regression
def test_univariate_pls_regression():
# Ensure 1d Y is correctly interpreted
d = load_linnerud()
X = d.data
Y = d.target
clf = pls_.PLSRegression()
# Compare 1d to column vector
model1 = clf.fit(X, Y[:, 0]).coef_
model2 = clf.fit(X, Y[:, :1]).coef_
assert_array_almost_equal(model1, model2)
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:11,代码来源:test_pls.py
示例9: test_load_linnerud
def test_load_linnerud():
res = load_linnerud()
assert_equal(res.data.shape, (20, 3))
assert_equal(res.target.shape, (20, 3))
assert_equal(len(res.target_names), 3)
assert_true(res.DESCR)
assert_true(os.path.exists(res.data_filename))
assert_true(os.path.exists(res.target_filename))
# test return_X_y option
check_return_X_y(res, partial(load_linnerud))
开发者ID:AlexisMignon,项目名称:scikit-learn,代码行数:11,代码来源:test_base.py
示例10: test_scale_and_stability
def test_scale_and_stability():
# We test scale=True parameter
# This allows to check numerical stability over platforms as well
d = load_linnerud()
X1 = d.data
Y1 = d.target
# causes X[:, -1].std() to be zero
X1[:, -1] = 1.0
# From bug #2821
# Test with X2, T2 s.t. clf.x_score[:, 1] == 0, clf.y_score[:, 1] == 0
# This test robustness of algorithm when dealing with value close to 0
X2 = np.array([[0., 0., 1.],
[1., 0., 0.],
[2., 2., 2.],
[3., 5., 4.]])
Y2 = np.array([[0.1, -0.2],
[0.9, 1.1],
[6.2, 5.9],
[11.9, 12.3]])
for (X, Y) in [(X1, Y1), (X2, Y2)]:
X_std = X.std(axis=0, ddof=1)
X_std[X_std == 0] = 1
Y_std = Y.std(axis=0, ddof=1)
Y_std[Y_std == 0] = 1
X_s = (X - X.mean(axis=0)) / X_std
Y_s = (Y - Y.mean(axis=0)) / Y_std
for clf in [CCA(), pls_.PLSCanonical(), pls_.PLSRegression(),
pls_.PLSSVD()]:
clf.set_params(scale=True)
X_score, Y_score = clf.fit_transform(X, Y)
clf.set_params(scale=False)
X_s_score, Y_s_score = clf.fit_transform(X_s, Y_s)
assert_array_almost_equal(X_s_score, X_score)
assert_array_almost_equal(Y_s_score, Y_score)
# Scaling should be idempotent
clf.set_params(scale=True)
X_score, Y_score = clf.fit_transform(X_s, Y_s)
assert_array_almost_equal(X_s_score, X_score)
assert_array_almost_equal(Y_s_score, Y_score)
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:44,代码来源:test_pls.py
示例11: load_linnerud
def load_linnerud():
from sklearn.datasets import load_linnerud
linnerud = load_linnerud()
# print(linnerud.DESCR)
print(linnerud.keys())
# print(linnerud.feature_names)
# Chins : 懸垂の回数
# Situps : 腹筋の回数
# Jumps : 跳躍
# print(linnerud.target_names)
# ['Weight', 'Waist', 'Pulse']
X = linnerud.data
y = linnerud.target
return SklearnDataGenerator.shuffle(X, y)
开发者ID:Munetaka,项目名称:labo,代码行数:19,代码来源:sklearn_data_generator.py
示例12: test_predict_transform_copy
def test_predict_transform_copy():
# check that the "copy" keyword works
d = load_linnerud()
X = d.data
Y = d.target
clf = pls_.PLSCanonical()
X_copy = X.copy()
Y_copy = Y.copy()
clf.fit(X, Y)
# check that results are identical with copy
assert_array_almost_equal(clf.predict(X), clf.predict(X.copy(), copy=False))
assert_array_almost_equal(clf.transform(X), clf.transform(X.copy(), copy=False))
# check also if passing Y
assert_array_almost_equal(clf.transform(X, Y), clf.transform(X.copy(), Y.copy(), copy=False))
# check that copy doesn't destroy
# we do want to check exact equality here
assert_array_equal(X_copy, X)
assert_array_equal(Y_copy, Y)
# also check that mean wasn't zero before (to make sure we didn't touch it)
assert_true(np.all(X.mean(axis=0) != 0))
开发者ID:antoinewdg,项目名称:scikit-learn,代码行数:21,代码来源:test_pls.py
示例13: scikitAlgorithms_UCIDataset
def scikitAlgorithms_UCIDataset(input_dict):
from sklearn import datasets
allDSets = {"iris":datasets.load_iris(), "boston":datasets.load_boston(), "diabetes":datasets.load_diabetes(), " linnerud":datasets.load_linnerud()}
dataset = allDSets[input_dict['dsIn']]
output_dict = {}
output_dict['dtsOut'] = dataset#(dataset.data, dataset.target)
return output_dict
开发者ID:Alshak,项目名称:clowdflows,代码行数:7,代码来源:library.py
示例14: test_pls
def test_pls():
d = load_linnerud()
X = d.data
Y = d.target
# 1) Canonical (symmetric) PLS (PLS 2 blocks canonical mode A)
# ===========================================================
# Compare 2 algo.: nipals vs. svd
# ------------------------------
pls_bynipals = pls_.PLSCanonical(n_components=X.shape[1])
pls_bynipals.fit(X, Y)
pls_bysvd = pls_.PLSCanonical(algorithm="svd", n_components=X.shape[1])
pls_bysvd.fit(X, Y)
# check equalities of loading (up to the sign of the second column)
assert_array_almost_equal(
pls_bynipals.x_loadings_,
pls_bysvd.x_loadings_, decimal=5,
err_msg="nipals and svd implementations lead to different x loadings")
assert_array_almost_equal(
pls_bynipals.y_loadings_,
pls_bysvd.y_loadings_, decimal=5,
err_msg="nipals and svd implementations lead to different y loadings")
# Check PLS properties (with n_components=X.shape[1])
# ---------------------------------------------------
plsca = pls_.PLSCanonical(n_components=X.shape[1])
plsca.fit(X, Y)
T = plsca.x_scores_
P = plsca.x_loadings_
Wx = plsca.x_weights_
U = plsca.y_scores_
Q = plsca.y_loadings_
Wy = plsca.y_weights_
def check_ortho(M, err_msg):
K = np.dot(M.T, M)
assert_array_almost_equal(K, np.diag(np.diag(K)), err_msg=err_msg)
# Orthogonality of weights
# ~~~~~~~~~~~~~~~~~~~~~~~~
check_ortho(Wx, "x weights are not orthogonal")
check_ortho(Wy, "y weights are not orthogonal")
# Orthogonality of latent scores
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check_ortho(T, "x scores are not orthogonal")
check_ortho(U, "y scores are not orthogonal")
# Check X = TP' and Y = UQ' (with (p == q) components)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# center scale X, Y
Xc, Yc, x_mean, y_mean, x_std, y_std =\
pls_._center_scale_xy(X.copy(), Y.copy(), scale=True)
assert_array_almost_equal(Xc, np.dot(T, P.T), err_msg="X != TP'")
assert_array_almost_equal(Yc, np.dot(U, Q.T), err_msg="Y != UQ'")
# Check that rotations on training data lead to scores
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Xr = plsca.transform(X)
assert_array_almost_equal(Xr, plsca.x_scores_,
err_msg="rotation on X failed")
Xr, Yr = plsca.transform(X, Y)
assert_array_almost_equal(Xr, plsca.x_scores_,
err_msg="rotation on X failed")
assert_array_almost_equal(Yr, plsca.y_scores_,
err_msg="rotation on Y failed")
# "Non regression test" on canonical PLS
# --------------------------------------
# The results were checked against the R-package plspm
pls_ca = pls_.PLSCanonical(n_components=X.shape[1])
pls_ca.fit(X, Y)
x_weights = np.array(
[[-0.61330704, 0.25616119, -0.74715187],
[-0.74697144, 0.11930791, 0.65406368],
[-0.25668686, -0.95924297, -0.11817271]])
# x_weights_sign_flip holds columns of 1 or -1, depending on sign flip
# between R and python
x_weights_sign_flip = pls_ca.x_weights_ / x_weights
x_rotations = np.array(
[[-0.61330704, 0.41591889, -0.62297525],
[-0.74697144, 0.31388326, 0.77368233],
[-0.25668686, -0.89237972, -0.24121788]])
x_rotations_sign_flip = pls_ca.x_rotations_ / x_rotations
y_weights = np.array(
[[+0.58989127, 0.7890047, 0.1717553],
[+0.77134053, -0.61351791, 0.16920272],
[-0.23887670, -0.03267062, 0.97050016]])
y_weights_sign_flip = pls_ca.y_weights_ / y_weights
y_rotations = np.array(
[[+0.58989127, 0.7168115, 0.30665872],
[+0.77134053, -0.70791757, 0.19786539],
[-0.23887670, -0.00343595, 0.94162826]])
y_rotations_sign_flip = pls_ca.y_rotations_ / y_rotations
# x_weights = X.dot(x_rotation)
#.........这里部分代码省略.........
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:101,代码来源:test_pls.py
示例15: zip
# coding=utf-8
from sklearn import datasets
import numpy as np
import matplotlib.pyplot as plt
d1 = datasets.load_iris() #
d2 = datasets.load_breast_cancer() #乳腺癌数据
d3 = datasets.load_digits() #手写数字
d4 = datasets.load_boston() #波士顿房价
d5 = datasets.load_linnerud() #体能数据集
print(d3.keys())
samples,features = d3.data.shape
print(samples,features)
print(d3.images.shape)
#print(d1.data)
#print(d1.target)
print(d3.target_names)
print(np.bincount(d1.target))
x_index = 3
colors = ['blue','red','green']
'''
for label,color in zip(range(len(d1.target_names)),colors):
plt.hist(d1.data[d1.target==label,x_index],label=d1.target_names[label],color=color) #直方图
开发者ID:xxwei,项目名称:TraderCode,代码行数:30,代码来源:sklearnData.py
示例16: load_linnerud
# Import necessary library
import numpy as np
import pandas as pd
# Load the dataset
from sklearn.datasets import load_linnerud
linnerud_data = load_linnerud()
X = linnerud_data.data
y = linnerud_data.target
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_squared_error as mse
from sklearn.linear_model import LinearRegression
# TODO: split the data into training and testing sets,
# using the standard settings for train_test_split.
# Then, train and test the classifiers with your newly split data instead of X and y.
#Solution
# Prepare the data as features and labels.
features = X
labels = y
# split the data into training and testing sets
from sklearn import cross_validation
features_train, features_test, labels_train, labels_test = cross_validation.train_test_split(features, labels, test_size=0.4, random_state=0)
# Create decision tree regressor/algorithm object
开发者ID:okeonwuka,项目名称:PycharmProjects,代码行数:31,代码来源:Mean_Squared_Error.py
示例17: test_predictions
def test_predictions():
d = load_linnerud()
X = d.data
Y = d.target
tol = 5e-12
miter = 1000
num_comp = 2
Xorig = X.copy()
Yorig = Y.copy()
# SSY = np.sum(Yorig**2)
# center = True
scale = False
pls1 = PLSRegression(n_components = num_comp, scale = scale,
tol = tol, max_iter = miter, copy = True)
pls1.fit(Xorig, Yorig)
Yhat1 = pls1.predict(Xorig)
SSYdiff1 = np.sum((Yorig-Yhat1)**2)
# print "PLSRegression: R2Yhat = %.4f" % (1 - (SSYdiff1 / SSY))
# Compare PLSR and sklearn.PLSRegression
pls3 = PLSR(num_comp = num_comp, center = True, scale = scale,
tolerance = tol, max_iter = miter)
pls3.fit(X, Y)
Yhat3 = pls3.predict(X)
assert_array_almost_equal(Yhat1, Yhat3, decimal = 5,
err_msg = "PLSR gives wrong prediction")
SSYdiff3 = np.sum((Yorig-Yhat3)**2)
# print "PLSR : R2Yhat = %.4f" % (1 - (SSYdiff3 / SSY))
assert abs(SSYdiff1 - SSYdiff3) < 0.00005
pls2 = PLSCanonical(n_components = num_comp, scale = scale,
tol = tol, max_iter = miter, copy = True)
pls2.fit(Xorig, Yorig)
Yhat2 = pls2.predict(Xorig)
SSYdiff2 = np.sum((Yorig-Yhat2)**2)
# print "PLSCanonical : R2Yhat = %.4f" % (1 - (SSYdiff2 / SSY))
# Compare PLSC and sklearn.PLSCanonical
pls4 = PLSC(num_comp = num_comp, center = True, scale = scale,
tolerance = tol, max_iter = miter)
pls4.fit(X, Y)
Yhat4 = pls4.predict(X)
SSYdiff4 = np.sum((Yorig-Yhat4)**2)
# print "PLSC : R2Yhat = %.4f" % (1 - (SSYdiff4 / SSY))
# Compare O2PLS and sklearn.PLSCanonical
pls5 = O2PLS(num_comp = [num_comp, 1, 0], center = True, scale = scale,
tolerance = tol, max_iter = miter)
pls5.fit(X, Y)
Yhat5 = pls5.predict(X)
SSYdiff5 = np.sum((Yorig-Yhat5)**2)
# print "O2PLS : R2Yhat = %.4f" % (1 - (SSYdiff5 / SSY))
assert abs(SSYdiff2 - SSYdiff4) < 0.00005
assert SSYdiff2 > SSYdiff5
开发者ID:tomlof,项目名称:sandlada,代码行数:66,代码来源:test_multiblock.py
示例18: load_linnerud
import numpy as np
from numpy.testing import assert_array_almost_equal
from sklearn.datasets import load_linnerud
from sklearn import pls
d = load_linnerud()
X = d.data
Y = d.target
def test_pls():
n_components = 2
# 1) Canonical (symetric) PLS (PLS 2 blocks canonical mode A)
# ===========================================================
# Compare 2 algo.: nipals vs. svd
# ------------------------------
pls_bynipals = pls.PLSCanonical(n_components=n_components)
pls_bynipals.fit(X, Y)
pls_bysvd = pls.PLSCanonical(algorithm="svd", n_components=n_components)
pls_bysvd.fit(X, Y)
# check that the loading vectors are highly correlated
assert_array_almost_equal(
[
np.abs(np.corrcoef(pls_bynipals.x_loadings_[:, k], pls_bysvd.x_loadings_[:, k])[1, 0])
for k in xrange(n_components)
],
np.ones(n_components),
err_msg="nipals and svd implementation lead to different x loadings",
)
assert_array_almost_equal(
开发者ID:njwilson,项目名称:scikit-learn,代码行数:31,代码来源:test_pls.py
示例19: load_UCI_dataset
def load_UCI_dataset(dsIn):
'''Loads a UCI dataset
:param dsIn: the dataset name
:return: A SciKit dataset
'''
from sklearn import datasets
allDSets = {"iris":datasets.load_iris(), "boston":datasets.load_boston(), "diabetes":datasets.load_diabetes(), " linnerud":datasets.load_linnerud()}
dataset = allDSets[dsIn]
return dataset
开发者ID:xflows,项目名称:cf_data_mining,代码行数:11,代码来源:utilities.py
示例20: experimentVariables
def experimentVariables(projectName):
'''
This function returns all the variables necessary to start a experiment including:
name of the experiment
datasets locations
variables to report from the experiment
what to report from the experiment
'''
computerName=os.environ.get('COMPUTERNAME')
if projectName== 'unlabeledModelS':
if computerName=='JULIAN':
from sklearn.datasets import load_boston, load_iris, load_diabetes, load_digits, load_linnerud
datasets={'boston':load_boston(),'iris':load_iris(),'diabetes':load_diabetes(),'digits':load_digits(),'linnerud':load_linnerud()}
print('working at [email protected]')
dataset='digits'
numTests=50
experimentName='One'
agmntlvl=0
description='here the description of this experiment'
data=datasets[dataset]['data']
labels=datasets[dataset]['target']
verbose=0
plots=False
signal2plot='f1_score_mv_predval_agmnt'
# signal2plot='f1_score_val_predval_agmnt'
#The next are variables that store the outcomes from the
#experiment
variables=\
'spear=[]\n'
return {'dataset':dataset,'numTests':numTests,'experimentName':experimentName,\
'description':description,'agmntlvl':agmntlvl,'variables':variables,'data':data,\
'labels':labels,'verbose':verbose,'plots':plots,'signal2plot':signal2plot}
else:
print('Variables not defined for [email protected]')
开发者ID:julian-ramos,项目名称:GeneralFunctions,代码行数:37,代码来源:General.py
注:本文中的sklearn.datasets.load_linnerud函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论