本文整理汇总了Python中sklearn.datasets.load_breast_cancer方法的典型用法代码示例。如果您正苦于以下问题:Python datasets.load_breast_cancer方法的具体用法?Python datasets.load_breast_cancer怎么用?Python datasets.load_breast_cancer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.datasets
的用法示例。
在下文中一共展示了datasets.load_breast_cancer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def setUp(self) -> None:
self.random_state = 0
d: dict = load_breast_cancer()
X: DataFrame = DataFrame(d['data'], columns=d['feature_names'])
self.col_ordinal = X.columns.to_list()
np.random.seed(self.random_state)
s = np.array(['a', 'b', 'c'])
X['cat alpha'] = s[np.random.randint(0, 3, len(X))]
X['cat num'] = np.random.randint(0, 3, len(X))
self.col_categorical = ['cat alpha', 'cat num']
s = np.array(['a', 'b'])
X['bin alpha'] = s[np.random.randint(0, 2, len(X))]
X['bin num'] = np.random.randint(0, 2, len(X))
self.col_binary = ['bin alpha', 'bin num']
self.X = X
self.y: ndarray = d['target']
self.X_train, self.X_test, self.y_train, self.y_test = \
train_test_split(self.X, self.y, test_size=0.4, random_state=self.random_state)
示例2: main
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def main():
dataset = datasets.load_breast_cancer()
features = dataset.data
labels = dataset.target
num_features = features.shape[1]
features = StandardScaler().fit_transform(features)
train_features, test_features, train_labels, test_labels = train_test_split(
features, labels, test_size=0.3, stratify=labels
)
model = NearestNeighbor(train_features, train_labels, num_features)
model.predict(test_features, test_labels, result_path="./results/nearest_neighbor/")
示例3: setUp
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def setUp(self):
self.roc_floor = 0.9
self.accuracy_floor = 0.9
random_state = 42
X, y = load_breast_cancer(return_X_y=True)
self.X_train, self.X_test, self.y_train, self.y_test = \
train_test_split(X, y, test_size=0.4, random_state=random_state)
classifiers = [DecisionTreeClassifier(random_state=random_state),
LogisticRegression(random_state=random_state),
KNeighborsClassifier(),
RandomForestClassifier(random_state=random_state),
GradientBoostingClassifier(random_state=random_state)]
self.clf = DES_LA(classifiers, local_region_size=30)
self.clf.fit(self.X_train, self.y_train)
示例4: setUp
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def setUp(self):
self.X, self.y = load_breast_cancer(return_X_y=True)
self.n_clusters = 5
self.n_estimators = 3
# Initialize a set of estimators
estimators = [KMeans(n_clusters=self.n_clusters),
MiniBatchKMeans(n_clusters=self.n_clusters),
AgglomerativeClustering(n_clusters=self.n_clusters)]
# Clusterer Ensemble without initializing a new Class
self.original_labels = np.zeros([self.X.shape[0], self.n_estimators])
for i, estimator in enumerate(estimators):
estimator.fit(self.X)
self.original_labels[:, i] = estimator.labels_
示例5: setUp
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def setUp(self):
self.roc_floor = 0.9
self.accuracy_floor = 0.9
random_state = 42
X, y = load_breast_cancer(return_X_y=True)
self.X_train, self.X_test, self.y_train, self.y_test = \
train_test_split(X, y, test_size=0.4, random_state=random_state)
classifiers = [DecisionTreeClassifier(random_state=random_state),
LogisticRegression(random_state=random_state),
KNeighborsClassifier(),
RandomForestClassifier(random_state=random_state),
GradientBoostingClassifier(random_state=random_state)]
self.clf = Stacking(classifiers, n_folds=4)
self.clf.fit(self.X_train, self.y_train)
示例6: setUp
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def setUp(self):
self.roc_floor = 0.9
self.accuracy_floor = 0.9
random_state = 42
X, y = load_breast_cancer(return_X_y=True)
self.X_train, self.X_test, self.y_train, self.y_test = \
train_test_split(X, y, test_size=0.4, random_state=random_state)
classifiers = [DecisionTreeClassifier(random_state=random_state),
LogisticRegression(random_state=random_state),
KNeighborsClassifier(),
RandomForestClassifier(random_state=random_state),
GradientBoostingClassifier(random_state=random_state)]
self.clf = SimpleClassifierAggregator(classifiers, method='average')
示例7: test_fit_2
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def test_fit_2(self):
"""Tests GridSearchCV fit() with different data."""
x_np, y_np = datasets.load_breast_cancer(return_X_y=True)
x = ds.array(x_np, block_size=(100, 10))
x = StandardScaler().fit_transform(x)
y = ds.array(y_np.reshape(-1, 1), block_size=(100, 1))
parameters = {'c': [0.1], 'gamma': [0.1]}
csvm = CascadeSVM()
searcher = GridSearchCV(csvm, parameters, cv=5)
searcher.fit(x, y)
self.assertTrue(hasattr(searcher, 'best_estimator_'))
self.assertTrue(hasattr(searcher, 'best_score_'))
self.assertTrue(hasattr(searcher, 'best_params_'))
self.assertTrue(hasattr(searcher, 'best_index_'))
self.assertTrue(hasattr(searcher, 'scorer_'))
self.assertEqual(searcher.n_splits_, 5)
示例8: test_save_load_classifier
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def test_save_load_classifier(self):
X, y = datasets.load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
k = 4
classifier_before = pyfms.Classifier(X.shape[1], k=k)
classifier_before.fit(X_train, y_train, nb_epoch=1000)
weights_before = classifier_before.get_weights()
accuracy_before = accuracy_score(y_test, classifier_before.predict(X_test))
classifier_file = os.path.join(self.workspace, 'classifier.fm')
classifier_before.save_weights(classifier_file)
classifier_after = pyfms.Classifier(X.shape[1])
classifier_after.load_weights(classifier_file)
weights_after = classifier_after.get_weights()
accuracy_after = accuracy_score(y_test, classifier_after.predict(X_test))
for wb, wa in zip(weights_before, weights_after):
np.testing.assert_array_equal(wb, wa)
self.assertEqual(accuracy_before, accuracy_after)
示例9: test_select_fdr_int
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def test_select_fdr_int(self):
model = SelectFdr()
X, y = load_breast_cancer(return_X_y=True)
model.fit(X, y)
model_onnx = convert_sklearn(
model, "select fdr",
[("input", Int64TensorType([None, X.shape[1]]))])
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X.astype(np.int64),
model,
model_onnx,
basename="SklearnSelectFdr",
allow_failure="StrictVersion(onnx.__version__)"
" < StrictVersion('1.2') or "
"StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')",
)
示例10: test_select_fwe_int
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def test_select_fwe_int(self):
model = SelectFwe()
X, y = load_breast_cancer(return_X_y=True)
model.fit(X, y)
model_onnx = convert_sklearn(
model, "select fwe",
[("input", Int64TensorType([None, X.shape[1]]))])
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X.astype(np.int64),
model,
model_onnx,
basename="SklearnSelectFwe",
allow_failure="StrictVersion(onnx.__version__)"
" < StrictVersion('1.2') or "
"StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')",
)
示例11: test_select_fdr_float
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def test_select_fdr_float(self):
model = SelectFdr()
X, y = load_breast_cancer(return_X_y=True)
model.fit(X, y)
model_onnx = convert_sklearn(
model, "select fdr",
[("input", FloatTensorType([None, X.shape[1]]))])
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X.astype(np.float32),
model,
model_onnx,
basename="SklearnSelectFdr",
allow_failure="StrictVersion(onnx.__version__)"
" < StrictVersion('1.2') or "
"StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')",
)
示例12: test_select_fwe_float
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def test_select_fwe_float(self):
model = SelectFwe()
X, y = load_breast_cancer(return_X_y=True)
model.fit(X, y)
model_onnx = convert_sklearn(
model, "select fwe",
[("input", FloatTensorType([None, X.shape[1]]))])
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X.astype(np.float32),
model,
model_onnx,
basename="SklearnSelectFwe",
allow_failure="StrictVersion(onnx.__version__)"
" < StrictVersion('1.2') or "
"StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')",
)
示例13: test_not_labels
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def test_not_labels():
data = load_breast_cancer()
X = data.data
y = data.target
# convert class values to [0,2]
# y = y * 2
# Splitting data into train and test
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=42)
# sklearn
clf_sklearn = linear_model.LogisticRegression()
clf_sklearn.fit(X_train, y_train)
y_pred_sklearn = clf_sklearn.predict(X_test)
# h2o
clf_h2o = h2o4gpu.LogisticRegression()
clf_h2o.fit(X_train, y_train)
y_pred_h2o = clf_h2o.predict(X_test)
assert np.allclose(accuracy_score(y_test, y_pred_sklearn), accuracy_score(y_test, y_pred_h2o.squeeze()))
示例14: load_dataset
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def load_dataset(encode_labels, rng):
# Generate a classification dataset
data = load_breast_cancer()
X = data.data
y = data.target
if encode_labels is not None:
y = np.take(encode_labels, y)
# split the data into training and test data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,
random_state=rng)
# Scale the variables to have 0 mean and unit variance
scalar = StandardScaler()
X_train = scalar.fit_transform(X_train)
X_test = scalar.transform(X_test)
# Split the data into training and DSEL for DS techniques
X_train, X_dsel, y_train, y_dsel = train_test_split(X_train, y_train,
test_size=0.5,
random_state=rng)
# Considering a pool composed of 10 base classifiers
# Calibrating Perceptrons to estimate probabilities
return X_dsel, X_test, X_train, y_dsel, y_test, y_train
示例15: test_meta_no_pool_of_classifiers
# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import load_breast_cancer [as 别名]
def test_meta_no_pool_of_classifiers(knn_methods):
rng = np.random.RandomState(123456)
data = load_breast_cancer()
X = data.data
y = data.target
# split the data into training and test data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,
random_state=rng)
# Scale the variables to have 0 mean and unit variance
scalar = StandardScaler()
X_train = scalar.fit_transform(X_train)
X_test = scalar.transform(X_test)
meta_des = METADES(knn_classifier=knn_methods, random_state=rng,
DSEL_perc=0.5)
meta_des.fit(X_train, y_train)
assert np.isclose(meta_des.score(X_test, y_test), 0.9095744680851063)