安装 sklearn_sklearn 安装说明

安装 sklearn_sklearn 安装说明_第1张图片

klearn 安装说明

第一步:进入root用户:

cen@localhost ~]$ su root

密码:000000

第二步:安装sklearn

输入命令:pip install sklearn

(base) [root@localhost cen]# pip install sklearn

Collecting sklearn

Downloading https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz

Collecting scikit-learn (from sklearn)

Downloading https://files.pythonhosted.org/packages/9f/c5/e5267eb84994e9a92a2c6a6ee768514f255d036f3c8378acfa694e9f2c99/scikit_learn-0.21.3-cp37-cp37m-manylinux1_x86_64.whl (6.7MB)

......

Requirement already satisfied: numpy>=1.11.0 in /root/anaconda3/lib/python3.7/site-packages (from scikit-learn->sklearn) (1.16.4)

Building wheels for collected packages: sklearn

Building wheel for sklearn (setup.py) ... done

Created wheel for sklearn: filename=sklearn-0.0-py2.py3-none-any.whl size=1316 sha256=238d7a6d1e537779783982ab8c1f35518971109133af9d4139bcbacd88a66d05

Stored in directory: /root/.cache/pip/wheels/76/03/bb/589d421d27431bcd2c6da284d5f2286c8e3b2ea3cf1594c074

Successfully built sklearn

Installing collected packages: scipy, joblib, scikit-learn, sklearn

Successfully installed joblib-0.13.2 scikit-learn-0.21.3 scipy-1.3.1 sklearn-0.0

安装完提示:Successfully built sklearn 表示安装成功

第三步:检测一输入python,导入sklearn包

(base) [root@localhost cen]# python

Python 3.7.3 (default, Mar 27 2019, 22:11:17)

[GCC 7.3.0] :: Anaconda, Inc. on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import sklearn

>>>

没有报错,完成!

如果不成正常安装请尝试以下命令:

pip install scipy-0.18.0-cp37-cp37m-win_amd64.whl

在spyder中输入以下代码测试一个简单的回归问题:

这里使用sklearn自带的数据集,数据集为某市房价,根据某地区若干指标对房价进行预测。

from sklearn.linear_model import LinearRegression

from sklearn.datasets import load_boston

from sklearn.model_selection import train_test_split

#导入结果评价包

from sklearn.metrics import mean_absolute_error

#利用线性回归模型预测波斯顿房价

#下载sklearn自带的数据集

data = load_boston()

#建立线性回归模型

clf = LinearRegression()

#划分训练集和测试集

X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, test_size=0.3, random_state=0)

clf.fit(X_train, y_train)

predict_data = clf.predict(X_test)

print(predict_data)

#平均绝对值误差对结果进行评价

appraise = mean_absolute_error(y_test, predict_data)

print(appraise)

结果如图:

安装 sklearn_sklearn 安装说明_第2张图片

你可能感兴趣的:(安装,sklearn)