numpy

Conda skeleton pypi: ModuleNotFoundError: No module named 'numpy'

自闭症网瘾萝莉.ら 提交于 2021-02-17 02:31:26
问题 I'm trying to create a conda package from a package I've uploaded to PyPI, by following this tutorial. I've downloaded and installed the latest Anaconda environment for Linux (Ubuntu 16.04). After installing conda-build I am able to run the conda skeleton pypi click command as per the example, but running it for my own package mf2 , I encounter the error: ModuleNotFoundError: No module named 'numpy' resulting in Error: command failed: <anaconda_path>/python setup.py install I've already tried

机器学习入门 【二】

微笑、不失礼 提交于 2021-02-16 23:34:47
常用库简介 Numpy 基础科学计算库 Scipy 强大的科学计算工具集 Pandas 数据分析的利器 Matplotlib 画出优美的图形 Scikit-learn 机器学习库 Numpy 【sklearn使用numpy数组形式的数据进行处理,所以需要把数据转换为numpy数组形式,其中的多维数组也是numpy的核心功能之一】 import numpy i = numpy.array([[520,13,14],[25,9,178]]) print("i: \n{}".format(i)) 给变量i复制为一个数组 i是一个典型的numpy数组 结果: sklearn需要使用 scipy 来对算法进行执行 sparse函数,用来 生成稀疏矩阵,而稀疏矩阵用来存储那些大部分数组为0的np数组 【常用】 sparse用法 : import numpy as np from scipy import sparse matrix = np.eye(6) #用eye函数生成一个6*6对角矩阵 #矩阵中对角线上的元素数值为1,其余都是0 sparse_matrix = sparse.csr_matrix(matrix) #这一行把np数组转化为CSR格式的scripy稀疏矩阵(sparse matrix) #sparse函数只会存储非0元素 print("对角矩阵:\n {}".format

机器学习入门

折月煮酒 提交于 2021-02-16 23:19:48
机器学习 针对经验 E 和一系列任务 T 和一定表现的衡量 P ,如果随着经验 E 的积累,针对定义好的任务 T 可以提高其表现 P ,则说明机器有学习能力 S klearn 库 基本使用 包含了所有机器学习算法 ——> 分类 回归 非监督分类 数据降维 数据预处理 1. 构建机器学习模型 A. 逻辑回归 B. 支持向量机 C. 决策树 D. 神经网络 在给定的数据上做解决分类的问题 导入样本数据 代码: from sklearn import datasets wine = datasets.load_wine() print(wine) 补充: y 是样本的标签!每个分类的个数是类似的,所以不会存在不平衡的问题! 通过 numpy 包的 shape() 方法输入 data 和 target 的大小: 代码: import numpy as np print(np.shape(x),np.shape(y)) 其中, (178,13)---- 代表 178*13 的矩阵【意思是 178 个样本,每个样本有 13 个特征(或 13 个特征矩阵)】 (178,) ----- 代表长度是 178 的一个一维向量 把数据分成训练数据和测试数据 ----- 搭建模型后用一种机制评估模型 代码: from sklearn.model_selection import train_test

Spark机器学习库(MLlib)指南

淺唱寂寞╮ 提交于 2021-02-16 23:12:55
机器学习库(MLlib)指南 MLlib是Spark的机器学习(ML)库。机器学习具有可扩展性和易用性。 提供高级API ,它提供了以下工具: ML算法:常见的学习算法,如分类、回归、聚类和协同过滤 特征化:特征提取、变换、降维和选择 管道:用于构建、评估和调优ML管道的工具 持久性:保存和加载算法、模型和管道 实用程序:线性代数,统计学,数据处理等。 声明:基于DataFrame的API是主要API 基于MLlib RDD的API现在处于维护模式。 从Spark 2.0开始,在 spark.mllib 程序包已进入维护模式。Spark的主要机器学习API现在是 DataFrame -based API spark.ml 。 有什么影响 ? MLlib将支持基于RDD的API spark.mllib 以及错误修复。 MLlib不会为基于RDD的API添加新功能 。 在Spark 2.x版本中,MLlib将为基于DataFrames的API添加功能,以实现与基于RDD的API的功能奇偶校验。 在达到功能奇偶校验(粗略估计Spark 2.3)之后,将弃用基于RDD的API。 The RDD-based API is expected to be removed in Spark 3.0. 预计将在Spark 3.0中删除基于RDD的API。

Python: Why is np.where not working with two conditions?

时光怂恿深爱的人放手 提交于 2021-02-16 21:19:58
问题 I have the following data frame: >>> import pandas as pd >>> import numpy as np >>> df_test = pd.DataFrame({'id': [100, 101, 102, 103, 104], 'drive': ['4WD', None, '4WD', None, '2WD']}) >>> print(df_test) id drive 0 100 4WD 1 101 None 2 102 4WD 3 103 None 4 104 2WD And I would like to make a new column is_4x4 , that would be equal to 0, when drive is None , or drive is 2WD . In other cases, I would like the column to be equal to 1. I am using the following code, but the result is not as I

Python: Why is np.where not working with two conditions?

╄→尐↘猪︶ㄣ 提交于 2021-02-16 21:19:08
问题 I have the following data frame: >>> import pandas as pd >>> import numpy as np >>> df_test = pd.DataFrame({'id': [100, 101, 102, 103, 104], 'drive': ['4WD', None, '4WD', None, '2WD']}) >>> print(df_test) id drive 0 100 4WD 1 101 None 2 102 4WD 3 103 None 4 104 2WD And I would like to make a new column is_4x4 , that would be equal to 0, when drive is None , or drive is 2WD . In other cases, I would like the column to be equal to 1. I am using the following code, but the result is not as I

How would I find the mode (stats) of pixel values of an image?

…衆ロ難τιáo~ 提交于 2021-02-16 21:05:58
问题 I'm using opencv and I'm able to get a pixel of an image-- a 3-dimensional tuple, via the code below. However, I'm not quite sure how to calculate the mode of the pixels values in the image. import cv2 import numpy as np import matplotlib.pyplot as plt import numpy as np import cv2 img =cv2.imread('C:\\Users\Moondra\ABEO.png') #px = img[100,100] #gets pixel value #print (px) I tried, from scipy import stats stats.mode(img)[0] But this returns an array shape of stats.mode(img)[0].shape (1, 800

How would I find the mode (stats) of pixel values of an image?

北慕城南 提交于 2021-02-16 21:04:56
问题 I'm using opencv and I'm able to get a pixel of an image-- a 3-dimensional tuple, via the code below. However, I'm not quite sure how to calculate the mode of the pixels values in the image. import cv2 import numpy as np import matplotlib.pyplot as plt import numpy as np import cv2 img =cv2.imread('C:\\Users\Moondra\ABEO.png') #px = img[100,100] #gets pixel value #print (px) I tried, from scipy import stats stats.mode(img)[0] But this returns an array shape of stats.mode(img)[0].shape (1, 800

How to column_stack a numpy array with a scipy sparse matrix?

倖福魔咒の 提交于 2021-02-16 19:24:49
问题 I have the following matrices: A.toarray() array([[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]], dtype=int64) type(A) scipy.sparse.csr.csr_matrix A.shape (878049, 942) And matrix B: B array([2248, 2248, 2248, ..., 0, 0, 0]) type(B) numpy.ndarray B.shape (878049,) I would like to column stack A and B in C, I tried the folowing: C = sparse.column_stack([A,B]) Then: /usr/local/lib/python3

Numpy index of the maximum with reduction - numpy.argmax.reduceat

给你一囗甜甜゛ 提交于 2021-02-16 18:43:33
问题 I have a flat array b : a = numpy.array([0, 1, 1, 2, 3, 1, 2]) And an array c of indices marking the start of each "chunk": b = numpy.array([0, 4]) I know I can find the maximum in each "chunk" using a reduction: m = numpy.maximum.reduceat(a,b) >>> array([2, 3], dtype=int32) But... Is there a way to find the index of the maximum <edit> within a chunk </edit> (like numpy.argmax ), with vectorized operations (no lists, loops)? 回答1: Borrowing the idea from this post. Steps involved : Offset all