import numpy as np import matplotlib.pyplot as plt from sklearn import mixture from sklearn.metrics import adjusted_rand_score from sklearn.datasets.samples_generator import make_blobs def create_data(centers,num=100,std=0.7): X, labels_true = make_b…
import numpy as np import matplotlib.pyplot as plt from sklearn import cluster from sklearn.metrics import adjusted_rand_score from sklearn.datasets.samples_generator import make_blobs def create_data(centers,num=100,std=0.7): X, labels_true = make_b…
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,decomposition def load_data(): ''' 加载用于降维的数据 ''' # 使用 scikit-learn 自带的 iris 数据集 iris=datasets.load_iris() return iris.data,iris.target #超大规模数据集降维I…
from sklearn.preprocessing import Normalizer #数据预处理正则化Normalizer模型 def test_Normalizer(): X=[[1,2,3,4,5], [5,4,3,2,1], [1,3,5,2,4,], [2,4,1,3,5]] print("before transform:",X) normalizer=Normalizer(norm='l2') print("after transform:",no…
from sklearn.preprocessing import MaxAbsScaler #数据预处理标准化MaxAbsScaler模型 def test_MaxAbsScaler(): X=[[1,5,1,2,10], [2,6,3,2,7], [3,7,5,6,4,], [4,8,7,8,1]] print("before transform:",X) scaler=MaxAbsScaler() scaler.fit(X) print("scale_ is :&quo…
from sklearn.preprocessing import StandardScaler #数据预处理标准化StandardScaler模型 def test_StandardScaler(): X=[[1,5,1,2,10], [2,6,3,2,7], [3,7,5,6,4,], [4,8,7,8,1]] print("before transform:",X) scaler=StandardScaler() scaler.fit(X) print("scale_…
from sklearn.preprocessing import MinMaxScaler #数据预处理标准化MinMaxScaler模型 def test_MinMaxScaler(): X=[[1,5,1,2,10], [2,6,3,2,7], [3,7,5,6,4,], [4,8,7,8,1]] print("before transform:",X) scaler=MinMaxScaler(feature_range=(0,2)) scaler.fit(X) print(&q…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model,svm from sklearn.model_selection import train_test_split def load_data_classfication(): ''' 加载用于分类问题的数据集 ''' # 使用 scikit-learn 自带的 iris 数据集 iris=datasets.lo…
from sklearn.decomposition import DictionaryLearning #数据预处理字典学习DictionaryLearning模型 def test_DictionaryLearning(): X=[[1,2,3,4,5], [6,7,8,9,10], [10,9,8,7,6,], [5,4,3,2,1]] print("before transform:",X) dct=DictionaryLearning(n_components=3) dct.…
from sklearn.svm import LinearSVC from sklearn.pipeline import Pipeline from sklearn import neighbors, datasets from sklearn.datasets import load_digits from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_tes…