Beispiel #1
0
                 SelectFromModel(estimator=LinearSVC(penalty='l1'))),
                ("classification", RandomForestClassifier())])
clf.fit(x, y)

# np.random.RandomState(1) # 1 为种子
# RandomState.rand(d0, d1, ..., dn)  #The dimensions of the returned array, should all be positive. If no argument is given a single Python float is returned.

# 多层感知机分类
from sklearn.neural_network import MLPClassifier  # 利用了BP
x = [[0, 0], [1, 1]]  # 使用 SGD 或 Adam ,训练过程支持在线模式和小批量学习模式
y = [0, 1]  # 小数据集下,lbfgs运行更快,表现更好;大数据集,adam更好
clf = MLPClassifier(
    solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(5, 2),
    random_state=1)  # alpha:L2 penalty (regularization term) parameter
clf.fit(x, y)
clf.predict([[2, 2], [-1, -2]])

# 区域中浣熊脸的图片分割
from time import time
from sklearn.cluster import spectral_clustering
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
from sklearn.feature_extraction import image
from scipy.misc import face
face = face(
    gray=True)  # face.shape=(768, 1024), type(face)= <class 'numpy.ndarray'>
face = sp.misc.imresize(
    face, 0.1) / 255  #face.shape=(76,102),缩小当前尺寸的0.1,除以255,将数组归一化
graph = image.img_to_graph(
    face