Windows安装python包numpy、SciPy、scikit-learn

本文介绍如何配置Tsinghua镜像加速Anaconda软件包的安装,并通过实例展示了使用pip及conda安装numpy、scipy和scikit-learn的具体步骤。此外,还提供了测试这些库是否成功安装的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于Tsinghua anaconda镜像的下载


更新:

使用pip方式安装更快:

pip install numpy
pip install scipy
pip install scikit-learn

1、镜像配置

在cmd窗口,运行

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

这里只是配置anaconda (一个python科学计算包)的仓库镜像来安装里边的包。

2、安装numpy/scipy/scikit-learn

conda install numpy
conda install scipy
conda install scikit-learn

如果安装出现失败,提示无法访问****,可以通过使用命令行(管理员)来打开,重新输入指令,即可。

C:\Windows\system32>pip3 install --ignore-installed --upgrade -U scikit-learn
Collecting scikit-learn
  Using cached scikit_learn-0.19.1-cp36-cp36m-win_amd64.whl

Installing collected packages: scikit-learn
Successfully installed scikit-learn-0.19.1

其他安装方式,使用pip安装:

pip3 install -U scikit-learn#针对python3以上版本

3、测试是否成功

C:\Users\RoFun>python
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.
1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

#测试numpy
>>> from numpy import *
>>> random.rand(4,4)
array([[ 0.50577718,  0.28084544,  0.60065843,  0.13602574],
       [ 0.21017214,  0.95728551,  0.86767926,  0.28480014],
       [ 0.09599413,  0.1180833 ,  0.32564685,  0.86346346],
       [ 0.44717601,  0.48939418,  0.66523856,  0.59264163]])
       
#测试SciPy
>>> mamat=mat(random.rand(4,4))
>>> mamat.I
matrix([[-0.21932642, -0.21289052,  3.39586459, -0.97625391],
        [-1.24711187,  2.321002  , -4.25158411,  3.64620557],
        [ 3.42909455, -5.57118063,  1.78018854,  0.39327149],
        [-0.63002829,  3.00212206, -2.29609706, -0.79183222]])

测试sk-learn

>>> import scikit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'scikit'

>>> from sklearn import datasets
>>> digits=datasets.load_digits()
>>> print(digits.data)
[[  0.   0.   5. ...,   0.   0.   0.]
 [  0.   0.   0. ...,  10.   0.   0.]
 [  0.   0.   0. ...,  16.   9.   0.]
 ...,
 [  0.   0.   1. ...,   6.   0.   0.]
 [  0.   0.   2. ...,  12.   0.   0.]
 [  0.   0.  10. ...,  12.   1.   0.]]

参考:

  1. sk-learn入门教程
### 使用NumPySciPyscikit-learn和PyWavelets进行科学计算 #### NumPy的基础操作 NumPy是一个用于处理数组的强大库,提供了大量的函数来支持多维数组对象的操作。 ```python import numpy as np # 创建一维数组 arr = np.array([1, 2, 3]) # 数组运算 result_addition = arr + 5 # 对每个元素加5 matrix_multiplication = np.dot(np.array([[1, 2], [3, 4]]), np.array([[2, 0], [1, 2]])) # 矩阵乘法 ``` 这些基础操作使得数据预处理变得非常方便[^1]。 #### SciPy的应用场景 SciPy建立在NumPy之上,扩展了许多高级功能,特别是针对数值积分、优化等问题提供了解决方案。 ```python from scipy import integrate def integrand(x): return x ** 2 integral_result, error_estimate = integrate.quad(integrand, 0, 1) # 计算定积分 print(f"The integral of x^2 from 0 to 1 is approximately {integral_result} with an estimated error of {error_estimate}") ``` 此例子展示了如何利用`integrate.quad()`来进行简单的数值积分计算。 #### scikit-learn的机器学习应用 对于想要快速实现监督学习算法的人来说,scikit-learn是非常理想的选择。下面给出一个线性回归模型的例子: ```python from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn.datasets import make_regression X, y = make_regression(n_samples=100, n_features=1, noise=0.1) # 划分训练集测试集 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) model = LinearRegression() model.fit(X_train, y_train) predictions = model.predict(X_test) ``` 这段代码说明了怎样通过划分数据集并拟合一个基本的线性回归模型来预测新样本的结果[^2]。 #### PyWavelets的小波变换分析 最后,在信号处理领域内,PyWavelets可以用来执行连续小波变换(CWT),离散小波变换(DWT)等任务。 ```python import pywt data = [i % 4 for i in range(8)] # 构造一些模拟的数据点 coeffs = pywt.wavedec(data, 'db1') # 应用Daubechies wavelet (D4) 进行分解 reconstructed_data = pywt.waverec(coeffs, 'db1') print("Original:", data) print("Reconstructed:", reconstructed_data[:len(data)]) ``` 上述程序片段显示了使用默认设置下的小波系数解码过程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rosefunR

你的赞赏是我创作的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值