机器学习基础功能练习II

机器学习基础功能练习II

一、导入sklearn 数据集

  

from sklearn.datasets import load_diabetes
diabetes = load_diabetes()
"""返回字典,数据集的descr,data,feature_names等关键数据
diabetes.data 是一个矩阵
sklearn.datasets.load_boston
sklearn.datasets.load_breast_cancer
sklearn.datasets.load_diabetes
sklearn.datasets.load_digits
sklearn.datasets.load_files
sklearn.datasets.load_iris
"""
print(diabetes)
print(diabetes.feature_names)
print(diabetes.data)
X = diabetes.data
y = diabetes.target

  

二、分隔数据集

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
test_size=0.3 代表7:3,random_state=1 0~42

  

三、模型训练与预测

from sklearn.linear_model import LinearRegression
model = LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)

model.fit(X_train, y_train)
y_predict = model.predict(X_test)

  

上一篇:实现鸢尾花数据的读入


下一篇:[keras]MNIST 数据集下载不了,其他kears自带数据下载不了同理(例如imdb)