机器学习sklearn
Scikit-learn(sklearn)是机器学习中常用的第三方模块,对常用的机器学习方法进行了封装,包括回归(Regression)、降维(Dimensionality Reduction)、分类(Classfication)、聚类(Clustering)等方法。
lcp0633
这个作者很懒,什么都没留下…
展开
-
线性回归
import numpy as npimport matplotlib.pyplot as pltfrom sklearn import datasets,linear_model,model_selection#1、加载数据集x,y=diabetes=datasets.load_diabetes(return_X_y=True)print(x.shape)print(y.shape)x_train,x_test,y_train,y_test=model_selection.train...原创 2020-05-10 15:50:28 · 158 阅读 · 0 评论 -
交叉验证——决策树和随机森林
from sklearn.datasets import load_winefrom sklearn.ensemble import RandomForestClassifierfrom sklearn.tree import DecisionTreeClassifierfrom sklearn.model_selection import cross_val_scoreimport matplotlib.pyplot as pltwine = load_wine()rfc = Ra...原创 2020-05-10 11:45:18 · 1660 阅读 · 0 评论 -
随机森林
from sklearn.tree import DecisionTreeClassifierfrom sklearn.ensemble import RandomForestClassifierfrom sklearn.datasets import load_winefrom sklearn.model_selection import train_test_split# 1、加载数据集x, y = load_wine(return_X_y=True)print(x.shape)...原创 2020-05-10 10:05:45 · 284 阅读 · 0 评论 -
决策树
from sklearn import datasetsfrom sklearn import treefrom sklearn.model_selection import train_test_splitimport graphviz# 1、加载数据x,y = datasets.load_iris(return_X_y=True)x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)feature_na...原创 2020-05-10 08:18:34 · 130 阅读 · 0 评论 -
线性回归交叉验证
from sklearn import datasetsfrom sklearn.model_selection import cross_val_score # 交叉验证from sklearn.linear_model import LinearRegression, Lasso, Ridge, ElasticNet# 1、加载数据x, y = datasets.fetch_california_housing(return_X_y=True)print(x.shape)p...原创 2020-05-09 10:52:24 · 2155 阅读 · 0 评论 -
KNN
from sklearn import datasetsfrom sklearn.model_selection import train_test_splitfrom sklearn.neighbors import KNeighborsClassifier# 1、加载数据iris = datasets.load_iris()x = iris.datay = iris.targettarget_names = ['setosa', 'versicolor', 'virginica'...原创 2020-05-09 09:09:38 · 113 阅读 · 0 评论