import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D from sklearn.neural_network import MLPClassifier def creat_data(n): ''' 创建线性可分数据集 :param n: 正例样本的个数(同时也是负例样本的个数) :return: 返回一个线性可分数据集,数据集大小为 2*n ''' np.ra…
import numpy as np from matplotlib import pyplot as plt from sklearn import neighbors, datasets from matplotlib.colors import ListedColormap from sklearn.neural_network import MLPClassifier ## 加载数据集 np.random.seed(0) # 使用 scikit-learn 自带的 iris 数据集 ir…
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,manifold def load_data(): ''' 加载用于降维的数据 ''' # 使用 scikit-learn 自带的 iris 数据集 iris=datasets.load_iris() return iris.data,iris.target #等度量映射Isomap降维模型…
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,manifold def load_data(): ''' 加载用于降维的数据 ''' # 使用 scikit-learn 自带的 iris 数据集 iris=datasets.load_iris() return iris.data,iris.target #多维缩放降维MDS模型 def…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,ensemble from sklearn.model_selection import train_test_split def load_data_classification(): ''' 加载用于分类问题的数据集 ''' # 使用 scikit-learn 自带的 digits 数据集 digits=datasets.load_d…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,ensemble from sklearn.model_selection import train_test_split def load_data_classification(): ''' 加载用于分类问题的数据集 ''' # 使用 scikit-learn 自带的 digits 数据集 digits=datasets.load_d…
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…
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,manifold def load_data(): ''' 加载用于降维的数据 ''' # 使用 scikit-learn 自带的 iris 数据集 iris=datasets.load_iris() return iris.data,iris.target #局部线性嵌入LLE降维模型 d…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,naive_bayes from sklearn.model_selection import train_test_split # 加载 scikit-learn 自带的 digits 数据集 def load_data(): ''' 加载用于分类问题的数据集.这里使用 scikit-learn 自带的 digits 数据集 ''' d…
from sklearn.preprocessing import OneHotEncoder #数据预处理二元化OneHotEncoder模型 def test_OneHotEncoder(): X=[[1,2,3,4,5], [5,4,3,2,1], [3,3,3,3,3,], [1,1,1,1,1]] print("before transform:",X) encoder=OneHotEncoder(sparse=False) encoder.fit(X) print(&quo…
from sklearn.preprocessing import Binarizer #数据预处理二元化Binarizer模型 def test_Binarizer(): X=[[1,2,3,4,5], [5,4,3,2,1], [3,3,3,3,3,], [1,1,1,1,1]] print("before transform:",X) binarizer=Binarizer(threshold=2.5) print("after transform:",bin…
from sklearn.svm import LinearSVC from sklearn.datasets import load_iris from sklearn.feature_selection import RFE,RFECV from sklearn.model_selection import train_test_split #数据预处理包裹式特征选取RFE模型 def test_RFE(): iris=load_iris() X=iris.data y=iris.targe…
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_regression(): ''' 加载用于回归问题的数据集 ''' diabetes = datasets.load_diabetes() #使用 scikit-lea…
# -*- 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 #核化PCAKerne…
# -*- 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 #PCA降维 def…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,ensemble from sklearn.model_selection import train_test_split def load_data_regression(): ''' 加载用于回归问题的数据集 ''' #使用 scikit-learn 自带的一个糖尿病病人的数据集 diabetes = datasets.load_di…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,ensemble from sklearn.model_selection import train_test_split def load_data_classification(): ''' 加载用于分类问题的数据集 ''' # 使用 scikit-learn 自带的 digits 数据集 digits=datasets.load_d…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,ensemble from sklearn.model_selection import train_test_split def load_data_regression(): ''' 加载用于回归问题的数据集 ''' #使用 scikit-learn 自带的一个糖尿病病人的数据集 diabetes = datasets.load_di…
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_regression(): ''' 加载用于回归问题的数据集 ''' diabetes = datasets.load_diabetes() #使用 scikit-lea…
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…
import numpy as np from sklearn.model_selection import train_test_split,KFold,StratifiedKFold,LeaveOneOut,cross_val_score #模型选择数据集切分train_test_split模型 def test_train_test_split(): X=[[1,2,3,4], [11,12,13,14], [21,22,23,24], [31,32,33,34], [41,42,43,4…
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…
#K-NN分类 import os import sys import time import operator import cx_Oracle import numpy as np import pandas as pd import tensorflow as tf conn=cx_Oracle.connect('doctor/admin@localhost:1521/tszr') cursor = conn.cursor() #获取数据集 def getdata(surgery,surg…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier,DecisionTreeRegressor def load_data(): ''' 加载用于分类问题的数据集.数据集采用 scikit-…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier,DecisionTreeRegressor def creat_data(n): np.random.seed(0) X = 5 * np…
import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D from sklearn.model_selection import train_test_split from sklearn import datasets, linear_model,discriminant_analysis def load_data()…
import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D from sklearn import datasets, linear_model from sklearn.model_selection import train_test_split def load_data(): # 使用 scikit-learn 自带…
import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D from sklearn import datasets, linear_model from sklearn.model_selection import train_test_split def load_data(): diabetes = datasets.…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model from sklearn.model_selection import train_test_split def load_data(): diabetes = datasets.load_diabetes() return train_test_split(diabetes.data,diabetes.tar…
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model from sklearn.model_selection import train_test_split def load_data(): diabetes = datasets.load_diabetes() return train_test_split(diabetes.data,diabetes.tar…