menu

2021-07-03 记事

2021-07-03 记事


from sklearn import datasets, linear_model

from sklearn.model_selection import cross_val_score

diabetes = datasets.load_diabetes()

X = diabetes.data[:150]

y = diabetes.target[:150]

lasso = linear_model.Lasso()

print(cross_val_score(lasso, X, y, cv=3))

#[0.33150734 0.08022311 0.03531764]

https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_score.html

可以用於測試數據集

dir(datasets)


[‘all’, ‘builtins’, ‘cached’, ‘doc’, ‘file’, ‘loader’, ‘name’, ‘package’, ‘path’, ‘spec’, ‘_base’, ‘_california_housing’, ‘_covtype’, ‘_kddcup99’, ‘_lfw’, ‘_olivetti_faces’, ‘_openml’, ‘_rcv1’, ‘_samples_generator’, ‘_species_distributions’, ‘_svmlight_format_fast’, ‘_svmlight_format_io’, ‘_twenty_newsgroups’, ‘clear_data_home’, ‘dump_svmlight_file’, ‘fetch_20newsgroups’, ‘fetch_20newsgroups_vectorized’, ‘fetch_california_housing’, ‘fetch_covtype’, ‘fetch_kddcup99’, ‘fetch_lfw_pairs’, ‘fetch_lfw_people’, ‘fetch_olivetti_faces’, ‘fetch_openml’, ‘fetch_rcv1’, ‘fetch_species_distributions’, ‘get_data_home’, ‘load_boston’, ‘load_breast_cancer’, ‘load_diabetes’, ‘load_digits’, ‘load_files’, ‘load_iris’, ‘load_linnerud’, ‘load_sample_image’, ‘load_sample_images’, ‘load_svmlight_file’, ‘load_svmlight_files’, ‘load_wine’, ‘make_biclusters’, ‘make_blobs’, ‘make_checkerboard’, ‘make_circles’, ‘make_classification’, ‘make_friedman1’, ‘make_friedman2’, ‘make_friedman3’, ‘make_gaussian_quantiles’, ‘make_hastie_10_2’, ‘make_low_rank_matrix’, ‘make_moons’, ‘make_multilabel_classification’, ‘make_regression’, ‘make_s_curve’, ‘make_sparse_coded_signal’, ‘make_sparse_spd_matrix’, ‘make_sparse_uncorrelated’, ‘make_spd_matrix’, ‘make_swiss_roll’]

编辑